gql.tada 1.0.0 β†’ 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -44,36 +44,7 @@ server for TypeScript, the documentation for each API should pop up in your edit
44
44
 
45
45
  ## πŸ”Ž Let’s take a look!
46
46
 
47
- ```ts
48
- import { graphql } from 'gql.tada';
49
- import { myIntrospectionQuery } from './fixtures/introspection';
50
-
51
- // We can declare our introspected schema once globally
52
- declare module 'gql.tada' {
53
- interface setupSchema {
54
- introspection: typeof myIntrospectionQuery;
55
- }
56
- }
57
-
58
- // Creates fragment documents
59
- const fragment = graphql(`
60
- fragment HelloWorld extends Query {
61
- hello
62
- world
63
- }
64
- `);
65
-
66
- // Creates queries, optionally accepting a list of fragments for fragment spreads
67
- const query = graphql(
68
- `
69
- {
70
- hello
71
- ...HelloWorld
72
- }
73
- `,
74
- [fragment]
75
- );
76
- ```
47
+ <img width="100%" alt="Code Editor showing GraphQL queries being edited with gql.tada and GraphLSP" src="https://github.com/0no-co/gql.tada/blob/277ce424a747522ef2ca0d398b113f4f285eb595/website/public/demo-code.png?raw=true" />
77
48
 
78
49
  ## πŸ“¦ [Releases](https://github.com/0no-co/gql.tada/releases)
79
50
 
@@ -2,10 +2,10 @@ import {
2
2
  Kind,
3
3
  OperationTypeNode,
4
4
  DocumentNode,
5
- FieldNode,
6
- NameNode,
7
5
  FragmentSpreadNode,
8
6
  InlineFragmentNode,
7
+ FieldNode,
8
+ NameNode,
9
9
  TypeNode,
10
10
  } from '@0no-co/graphql.web';
11
11
 
@@ -1017,10 +1017,10 @@ type isOptionalRec<Directives extends readonly unknown[] | undefined> =
1017
1017
  name: any;
1018
1018
  }
1019
1019
  ? Directive['name']['value'] extends 'include' | 'skip' | 'defer'
1020
- ? false
1020
+ ? true
1021
1021
  : isOptionalRec<Rest>
1022
1022
  : isOptionalRec<Rest>
1023
- : true;
1023
+ : false;
1024
1024
  type getFieldAlias<Node extends FieldNode> = Node['alias'] extends undefined
1025
1025
  ? Node['name']['value']
1026
1026
  : Node['alias'] extends NameNode
@@ -1085,7 +1085,7 @@ type getSpreadSubtype<
1085
1085
  type getTypenameOfType<Type extends ObjectLikeType> = Type extends {
1086
1086
  possibleTypes: any;
1087
1087
  }
1088
- ? Type['possibleTypes']
1088
+ ? Type['name'] | Type['possibleTypes']
1089
1089
  : Type['name'];
1090
1090
  type getSelection<
1091
1091
  Selections extends readonly any[],
@@ -1094,44 +1094,8 @@ type getSelection<
1094
1094
  Fragments extends {
1095
1095
  [name: string]: any;
1096
1096
  },
1097
- > = obj<
1098
- getFieldsSelectionRec<Selections, Type, Introspection, Fragments> &
1099
- getFragmentsSelection<Selections, Type, Introspection, Fragments>
1100
- >;
1101
- type getFieldsSelectionRec<
1102
- Selections extends readonly unknown[],
1103
- Type extends ObjectLikeType,
1104
- Introspection extends IntrospectionLikeType,
1105
- Fragments extends {
1106
- [name: string]: any;
1107
- },
1108
- > = Selections extends readonly [infer Selection, ...infer Rest]
1109
- ? (Selection extends FieldNode
1110
- ? isOptionalRec<Selection['directives']> extends true
1111
- ? {
1112
- [Prop in getFieldAlias<Selection>]: Selection['name']['value'] extends '__typename'
1113
- ? getTypenameOfType<Type>
1114
- : unwrapType$1<
1115
- Type['fields'][Selection['name']['value']]['type'],
1116
- Selection['selectionSet'],
1117
- Introspection,
1118
- Fragments
1119
- >;
1120
- }
1121
- : {
1122
- [Prop in getFieldAlias<Selection>]?: Selection['name']['value'] extends '__typename'
1123
- ? getTypenameOfType<Type>
1124
- : unwrapType$1<
1125
- Type['fields'][Selection['name']['value']]['type'],
1126
- Selection['selectionSet'],
1127
- Introspection,
1128
- Fragments
1129
- >;
1130
- }
1131
- : {}) &
1132
- getFieldsSelectionRec<Rest, Type, Introspection, Fragments>
1133
- : {};
1134
- type _getFragmentsSelectionRec<
1097
+ > = obj<getPossibleTypesSelection<Selections, Type, Introspection, Fragments>>;
1098
+ type _getPossibleTypeSelectionRec<
1135
1099
  Selections extends readonly unknown[],
1136
1100
  PossibleType extends string,
1137
1101
  Type extends ObjectLikeType,
@@ -1143,18 +1107,40 @@ type _getFragmentsSelectionRec<
1143
1107
  ? (Node extends FragmentSpreadNode | InlineFragmentNode
1144
1108
  ? getSpreadSubtype<Node, Type, Introspection, Fragments> extends infer Subtype extends
1145
1109
  ObjectLikeType
1146
- ? PossibleType extends Subtype['name'] | getTypenameOfType<Subtype>
1110
+ ? PossibleType extends getTypenameOfType<Subtype>
1147
1111
  ?
1148
- | (isOptionalRec<Node['directives']> extends true ? never : {})
1112
+ | (isOptionalRec<Node['directives']> extends true ? {} : never)
1149
1113
  | getFragmentSelection<Node, Subtype, Introspection, Fragments>
1150
1114
  : {}
1151
1115
  : Node extends FragmentSpreadNode
1152
1116
  ? makeUndefinedFragmentRef<Node['name']['value']>
1153
1117
  : {}
1154
- : {}) &
1155
- _getFragmentsSelectionRec<Rest, PossibleType, Type, Introspection, Fragments>
1118
+ : Node extends FieldNode
1119
+ ? isOptionalRec<Node['directives']> extends true
1120
+ ? {
1121
+ [Prop in getFieldAlias<Node>]?: Node['name']['value'] extends '__typename'
1122
+ ? PossibleType
1123
+ : unwrapType$1<
1124
+ Type['fields'][Node['name']['value']]['type'],
1125
+ Node['selectionSet'],
1126
+ Introspection,
1127
+ Fragments
1128
+ >;
1129
+ }
1130
+ : {
1131
+ [Prop in getFieldAlias<Node>]: Node['name']['value'] extends '__typename'
1132
+ ? PossibleType
1133
+ : unwrapType$1<
1134
+ Type['fields'][Node['name']['value']]['type'],
1135
+ Node['selectionSet'],
1136
+ Introspection,
1137
+ Fragments
1138
+ >;
1139
+ }
1140
+ : {}) &
1141
+ _getPossibleTypeSelectionRec<Rest, PossibleType, Type, Introspection, Fragments>
1156
1142
  : {};
1157
- type getFragmentsSelection<
1143
+ type getPossibleTypesSelection<
1158
1144
  Selections extends readonly unknown[],
1159
1145
  Type extends ObjectLikeType,
1160
1146
  Introspection extends IntrospectionLikeType,
@@ -1166,7 +1152,7 @@ type getFragmentsSelection<
1166
1152
  possibleTypes: any;
1167
1153
  }
1168
1154
  ? objValues<{
1169
- [PossibleType in Type['possibleTypes']]: _getFragmentsSelectionRec<
1155
+ [PossibleType in Type['possibleTypes']]: _getPossibleTypeSelectionRec<
1170
1156
  Selections,
1171
1157
  PossibleType,
1172
1158
  Type,
@@ -1178,7 +1164,7 @@ type getFragmentsSelection<
1178
1164
  kind: 'OBJECT';
1179
1165
  name: any;
1180
1166
  }
1181
- ? _getFragmentsSelectionRec<Selections, Type['name'], Type, Introspection, Fragments>
1167
+ ? _getPossibleTypeSelectionRec<Selections, Type['name'], Type, Introspection, Fragments>
1182
1168
  : {};
1183
1169
  type getOperationSelectionType<
1184
1170
  Definition,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gql.tada",
3
3
  "description": "The spec-compliant & magical GraphQL query language engine in the TypeScript type system",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "author": "0no.co <hi@0no.co>",
6
6
  "source": "./src/index.ts",
7
7
  "main": "./dist/gql-tada",