graphql 16.11.0 → 16.13.0

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.
Files changed (48) hide show
  1. package/README.md +49 -6
  2. package/execution/execute.d.ts +14 -1
  3. package/execution/execute.js +72 -13
  4. package/execution/execute.mjs +72 -13
  5. package/execution/subscribe.js +1 -0
  6. package/execution/subscribe.mjs +2 -0
  7. package/index.d.ts +11 -0
  8. package/index.js +24 -0
  9. package/index.mjs +6 -2
  10. package/language/ast.d.ts +45 -1
  11. package/language/ast.js +14 -1
  12. package/language/ast.mjs +14 -1
  13. package/language/index.d.ts +14 -1
  14. package/language/index.js +12 -0
  15. package/language/index.mjs +8 -1
  16. package/language/kinds.d.ts +6 -0
  17. package/language/kinds.js +5 -0
  18. package/language/kinds.mjs +5 -0
  19. package/language/lexer.d.ts +52 -1
  20. package/language/lexer.js +10 -0
  21. package/language/lexer.mjs +17 -4
  22. package/language/parser.d.ts +30 -3
  23. package/language/parser.js +129 -13
  24. package/language/parser.mjs +123 -11
  25. package/language/predicates.d.ts +4 -0
  26. package/language/predicates.js +11 -0
  27. package/language/predicates.mjs +9 -0
  28. package/language/printer.js +42 -13
  29. package/language/printer.mjs +42 -13
  30. package/language/schemaCoordinateLexer.d.ts +43 -0
  31. package/language/schemaCoordinateLexer.js +171 -0
  32. package/language/schemaCoordinateLexer.mjs +122 -0
  33. package/language/tokenKind.d.ts +1 -0
  34. package/language/tokenKind.js +1 -0
  35. package/language/tokenKind.mjs +1 -0
  36. package/package.json +1 -1
  37. package/utilities/index.d.ts +5 -0
  38. package/utilities/index.js +14 -0
  39. package/utilities/index.mjs +5 -0
  40. package/utilities/resolveSchemaCoordinate.d.ts +80 -0
  41. package/utilities/resolveSchemaCoordinate.js +260 -0
  42. package/utilities/resolveSchemaCoordinate.mjs +243 -0
  43. package/validation/rules/ValuesOfCorrectTypeRule.js +7 -36
  44. package/validation/rules/ValuesOfCorrectTypeRule.mjs +7 -35
  45. package/validation/validate.js +12 -0
  46. package/validation/validate.mjs +13 -2
  47. package/version.js +2 -2
  48. package/version.mjs +2 -2
package/language/ast.js CHANGED
@@ -131,12 +131,19 @@ const QueryDocumentKeys = {
131
131
  Name: [],
132
132
  Document: ['definitions'],
133
133
  OperationDefinition: [
134
+ 'description',
134
135
  'name',
135
136
  'variableDefinitions',
136
137
  'directives',
137
138
  'selectionSet',
138
139
  ],
139
- VariableDefinition: ['variable', 'type', 'defaultValue', 'directives'],
140
+ VariableDefinition: [
141
+ 'description',
142
+ 'variable',
143
+ 'type',
144
+ 'defaultValue',
145
+ 'directives',
146
+ ],
140
147
  Variable: ['name'],
141
148
  SelectionSet: ['selections'],
142
149
  Field: ['alias', 'name', 'arguments', 'directives', 'selectionSet'],
@@ -144,6 +151,7 @@ const QueryDocumentKeys = {
144
151
  FragmentSpread: ['name', 'directives'],
145
152
  InlineFragment: ['typeCondition', 'directives', 'selectionSet'],
146
153
  FragmentDefinition: [
154
+ 'description',
147
155
  'name', // Note: fragment variable definitions are deprecated and will removed in v17.0.0
148
156
  'variableDefinitions',
149
157
  'typeCondition',
@@ -200,6 +208,11 @@ const QueryDocumentKeys = {
200
208
  UnionTypeExtension: ['name', 'directives', 'types'],
201
209
  EnumTypeExtension: ['name', 'directives', 'values'],
202
210
  InputObjectTypeExtension: ['name', 'directives', 'fields'],
211
+ TypeCoordinate: ['name'],
212
+ MemberCoordinate: ['name', 'memberName'],
213
+ ArgumentCoordinate: ['name', 'fieldName', 'argumentName'],
214
+ DirectiveCoordinate: ['name'],
215
+ DirectiveArgumentCoordinate: ['name', 'argumentName'],
203
216
  };
204
217
  exports.QueryDocumentKeys = QueryDocumentKeys;
205
218
  const kindValues = new Set(Object.keys(QueryDocumentKeys));
package/language/ast.mjs CHANGED
@@ -115,12 +115,19 @@ export const QueryDocumentKeys = {
115
115
  Name: [],
116
116
  Document: ['definitions'],
117
117
  OperationDefinition: [
118
+ 'description',
118
119
  'name',
119
120
  'variableDefinitions',
120
121
  'directives',
121
122
  'selectionSet',
122
123
  ],
123
- VariableDefinition: ['variable', 'type', 'defaultValue', 'directives'],
124
+ VariableDefinition: [
125
+ 'description',
126
+ 'variable',
127
+ 'type',
128
+ 'defaultValue',
129
+ 'directives',
130
+ ],
124
131
  Variable: ['name'],
125
132
  SelectionSet: ['selections'],
126
133
  Field: ['alias', 'name', 'arguments', 'directives', 'selectionSet'],
@@ -128,6 +135,7 @@ export const QueryDocumentKeys = {
128
135
  FragmentSpread: ['name', 'directives'],
129
136
  InlineFragment: ['typeCondition', 'directives', 'selectionSet'],
130
137
  FragmentDefinition: [
138
+ 'description',
131
139
  'name', // Note: fragment variable definitions are deprecated and will removed in v17.0.0
132
140
  'variableDefinitions',
133
141
  'typeCondition',
@@ -184,6 +192,11 @@ export const QueryDocumentKeys = {
184
192
  UnionTypeExtension: ['name', 'directives', 'types'],
185
193
  EnumTypeExtension: ['name', 'directives', 'values'],
186
194
  InputObjectTypeExtension: ['name', 'directives', 'fields'],
195
+ TypeCoordinate: ['name'],
196
+ MemberCoordinate: ['name', 'memberName'],
197
+ ArgumentCoordinate: ['name', 'fieldName', 'argumentName'],
198
+ DirectiveCoordinate: ['name'],
199
+ DirectiveArgumentCoordinate: ['name', 'argumentName'],
187
200
  };
188
201
  const kindValues = new Set(Object.keys(QueryDocumentKeys));
189
202
  /**
@@ -7,7 +7,13 @@ export type { KindEnum } from './kinds';
7
7
  export { TokenKind } from './tokenKind';
8
8
  export type { TokenKindEnum } from './tokenKind';
9
9
  export { Lexer } from './lexer';
10
- export { parse, parseValue, parseConstValue, parseType } from './parser';
10
+ export {
11
+ parse,
12
+ parseValue,
13
+ parseConstValue,
14
+ parseType,
15
+ parseSchemaCoordinate,
16
+ } from './parser';
11
17
  export type { ParseOptions } from './parser';
12
18
  export { print } from './printer';
13
19
  export {
@@ -80,6 +86,12 @@ export type {
80
86
  UnionTypeExtensionNode,
81
87
  EnumTypeExtensionNode,
82
88
  InputObjectTypeExtensionNode,
89
+ SchemaCoordinateNode,
90
+ TypeCoordinateNode,
91
+ MemberCoordinateNode,
92
+ ArgumentCoordinateNode,
93
+ DirectiveCoordinateNode,
94
+ DirectiveArgumentCoordinateNode,
83
95
  } from './ast';
84
96
  export {
85
97
  isDefinitionNode,
@@ -92,6 +104,7 @@ export {
92
104
  isTypeDefinitionNode,
93
105
  isTypeSystemExtensionNode,
94
106
  isTypeExtensionNode,
107
+ isSchemaCoordinateNode,
95
108
  } from './predicates';
96
109
  export { DirectiveLocation } from './directiveLocation';
97
110
  export type { DirectiveLocationEnum } from './directiveLocation';
package/language/index.js CHANGED
@@ -93,6 +93,12 @@ Object.defineProperty(exports, 'isExecutableDefinitionNode', {
93
93
  return _predicates.isExecutableDefinitionNode;
94
94
  },
95
95
  });
96
+ Object.defineProperty(exports, 'isSchemaCoordinateNode', {
97
+ enumerable: true,
98
+ get: function () {
99
+ return _predicates.isSchemaCoordinateNode;
100
+ },
101
+ });
96
102
  Object.defineProperty(exports, 'isSelectionNode', {
97
103
  enumerable: true,
98
104
  get: function () {
@@ -147,6 +153,12 @@ Object.defineProperty(exports, 'parseConstValue', {
147
153
  return _parser.parseConstValue;
148
154
  },
149
155
  });
156
+ Object.defineProperty(exports, 'parseSchemaCoordinate', {
157
+ enumerable: true,
158
+ get: function () {
159
+ return _parser.parseSchemaCoordinate;
160
+ },
161
+ });
150
162
  Object.defineProperty(exports, 'parseType', {
151
163
  enumerable: true,
152
164
  get: function () {
@@ -4,7 +4,13 @@ export { printLocation, printSourceLocation } from './printLocation.mjs';
4
4
  export { Kind } from './kinds.mjs';
5
5
  export { TokenKind } from './tokenKind.mjs';
6
6
  export { Lexer } from './lexer.mjs';
7
- export { parse, parseValue, parseConstValue, parseType } from './parser.mjs';
7
+ export {
8
+ parse,
9
+ parseValue,
10
+ parseConstValue,
11
+ parseType,
12
+ parseSchemaCoordinate,
13
+ } from './parser.mjs';
8
14
  export { print } from './printer.mjs';
9
15
  export {
10
16
  visit,
@@ -25,5 +31,6 @@ export {
25
31
  isTypeDefinitionNode,
26
32
  isTypeSystemExtensionNode,
27
33
  isTypeExtensionNode,
34
+ isSchemaCoordinateNode,
28
35
  } from './predicates.mjs';
29
36
  export { DirectiveLocation } from './directiveLocation.mjs';
@@ -56,6 +56,12 @@ declare enum Kind {
56
56
  UNION_TYPE_EXTENSION = 'UnionTypeExtension',
57
57
  ENUM_TYPE_EXTENSION = 'EnumTypeExtension',
58
58
  INPUT_OBJECT_TYPE_EXTENSION = 'InputObjectTypeExtension',
59
+ /** Schema Coordinates */
60
+ TYPE_COORDINATE = 'TypeCoordinate',
61
+ MEMBER_COORDINATE = 'MemberCoordinate',
62
+ ARGUMENT_COORDINATE = 'ArgumentCoordinate',
63
+ DIRECTIVE_COORDINATE = 'DirectiveCoordinate',
64
+ DIRECTIVE_ARGUMENT_COORDINATE = 'DirectiveArgumentCoordinate',
59
65
  }
60
66
  export { Kind };
61
67
  /**
package/language/kinds.js CHANGED
@@ -55,6 +55,11 @@ exports.Kind = Kind;
55
55
  Kind['UNION_TYPE_EXTENSION'] = 'UnionTypeExtension';
56
56
  Kind['ENUM_TYPE_EXTENSION'] = 'EnumTypeExtension';
57
57
  Kind['INPUT_OBJECT_TYPE_EXTENSION'] = 'InputObjectTypeExtension';
58
+ Kind['TYPE_COORDINATE'] = 'TypeCoordinate';
59
+ Kind['MEMBER_COORDINATE'] = 'MemberCoordinate';
60
+ Kind['ARGUMENT_COORDINATE'] = 'ArgumentCoordinate';
61
+ Kind['DIRECTIVE_COORDINATE'] = 'DirectiveCoordinate';
62
+ Kind['DIRECTIVE_ARGUMENT_COORDINATE'] = 'DirectiveArgumentCoordinate';
58
63
  })(Kind || (exports.Kind = Kind = {}));
59
64
  /**
60
65
  * The enum type representing the possible kind values of AST nodes.
@@ -47,6 +47,11 @@ var Kind;
47
47
  Kind['UNION_TYPE_EXTENSION'] = 'UnionTypeExtension';
48
48
  Kind['ENUM_TYPE_EXTENSION'] = 'EnumTypeExtension';
49
49
  Kind['INPUT_OBJECT_TYPE_EXTENSION'] = 'InputObjectTypeExtension';
50
+ Kind['TYPE_COORDINATE'] = 'TypeCoordinate';
51
+ Kind['MEMBER_COORDINATE'] = 'MemberCoordinate';
52
+ Kind['ARGUMENT_COORDINATE'] = 'ArgumentCoordinate';
53
+ Kind['DIRECTIVE_COORDINATE'] = 'DirectiveCoordinate';
54
+ Kind['DIRECTIVE_ARGUMENT_COORDINATE'] = 'DirectiveArgumentCoordinate';
50
55
  })(Kind || (Kind = {}));
51
56
 
52
57
  export { Kind };
@@ -1,6 +1,21 @@
1
1
  import { Token } from './ast';
2
2
  import type { Source } from './source';
3
3
  import { TokenKind } from './tokenKind';
4
+ /**
5
+ * A Lexer interface which provides common properties and methods required for
6
+ * lexing GraphQL source.
7
+ *
8
+ * @internal
9
+ */
10
+ export interface LexerInterface {
11
+ source: Source;
12
+ lastToken: Token;
13
+ token: Token;
14
+ line: number;
15
+ lineStart: number;
16
+ advance: () => Token;
17
+ lookahead: () => Token;
18
+ }
4
19
  /**
5
20
  * Given a Source object, creates a Lexer for that source.
6
21
  * A Lexer is a stateful stream generator in that every time
@@ -9,7 +24,7 @@ import { TokenKind } from './tokenKind';
9
24
  * EOF, after which the lexer will repeatedly return the same EOF token
10
25
  * whenever called.
11
26
  */
12
- export declare class Lexer {
27
+ export declare class Lexer implements LexerInterface {
13
28
  source: Source;
14
29
  /**
15
30
  * The previously focused non-ignored token.
@@ -43,3 +58,39 @@ export declare class Lexer {
43
58
  * @internal
44
59
  */
45
60
  export declare function isPunctuatorTokenKind(kind: TokenKind): boolean;
61
+ /**
62
+ * Prints the code point (or end of file reference) at a given location in a
63
+ * source for use in error messages.
64
+ *
65
+ * Printable ASCII is printed quoted, while other points are printed in Unicode
66
+ * code point form (ie. U+1234).
67
+ *
68
+ * @internal
69
+ */
70
+ export declare function printCodePointAt(
71
+ lexer: LexerInterface,
72
+ location: number,
73
+ ): string;
74
+ /**
75
+ * Create a token with line and column location information.
76
+ *
77
+ * @internal
78
+ */
79
+ export declare function createToken(
80
+ lexer: LexerInterface,
81
+ kind: TokenKind,
82
+ start: number,
83
+ end: number,
84
+ value?: string,
85
+ ): Token;
86
+ /**
87
+ * Reads an alphanumeric + underscore name from the source.
88
+ *
89
+ * ```
90
+ * Name ::
91
+ * - NameStart NameContinue* [lookahead != NameContinue]
92
+ * ```
93
+ *
94
+ * @internal
95
+ */
96
+ export declare function readName(lexer: LexerInterface, start: number): Token;
package/language/lexer.js CHANGED
@@ -4,7 +4,10 @@ Object.defineProperty(exports, '__esModule', {
4
4
  value: true,
5
5
  });
6
6
  exports.Lexer = void 0;
7
+ exports.createToken = createToken;
7
8
  exports.isPunctuatorTokenKind = isPunctuatorTokenKind;
9
+ exports.printCodePointAt = printCodePointAt;
10
+ exports.readName = readName;
8
11
 
9
12
  var _syntaxError = require('../error/syntaxError.js');
10
13
 
@@ -107,6 +110,7 @@ function isPunctuatorTokenKind(kind) {
107
110
  kind === _tokenKind.TokenKind.AMP ||
108
111
  kind === _tokenKind.TokenKind.PAREN_L ||
109
112
  kind === _tokenKind.TokenKind.PAREN_R ||
113
+ kind === _tokenKind.TokenKind.DOT ||
110
114
  kind === _tokenKind.TokenKind.SPREAD ||
111
115
  kind === _tokenKind.TokenKind.COLON ||
112
116
  kind === _tokenKind.TokenKind.EQUALS ||
@@ -161,6 +165,8 @@ function isTrailingSurrogate(code) {
161
165
  *
162
166
  * Printable ASCII is printed quoted, while other points are printed in Unicode
163
167
  * code point form (ie. U+1234).
168
+ *
169
+ * @internal
164
170
  */
165
171
 
166
172
  function printCodePointAt(lexer, location) {
@@ -178,6 +184,8 @@ function printCodePointAt(lexer, location) {
178
184
  }
179
185
  /**
180
186
  * Create a token with line and column location information.
187
+ *
188
+ * @internal
181
189
  */
182
190
 
183
191
  function createToken(lexer, kind, start, end, value) {
@@ -979,6 +987,8 @@ function readBlockString(lexer, start) {
979
987
  * Name ::
980
988
  * - NameStart NameContinue* [lookahead != NameContinue]
981
989
  * ```
990
+ *
991
+ * @internal
982
992
  */
983
993
 
984
994
  function readName(lexer, start) {
@@ -3,6 +3,13 @@ import { Token } from './ast.mjs';
3
3
  import { dedentBlockStringLines } from './blockString.mjs';
4
4
  import { isDigit, isNameContinue, isNameStart } from './characterClasses.mjs';
5
5
  import { TokenKind } from './tokenKind.mjs';
6
+ /**
7
+ * A Lexer interface which provides common properties and methods required for
8
+ * lexing GraphQL source.
9
+ *
10
+ * @internal
11
+ */
12
+
6
13
  /**
7
14
  * Given a Source object, creates a Lexer for that source.
8
15
  * A Lexer is a stateful stream generator in that every time
@@ -11,7 +18,6 @@ import { TokenKind } from './tokenKind.mjs';
11
18
  * EOF, after which the lexer will repeatedly return the same EOF token
12
19
  * whenever called.
13
20
  */
14
-
15
21
  export class Lexer {
16
22
  /**
17
23
  * The previously focused non-ignored token.
@@ -87,6 +93,7 @@ export function isPunctuatorTokenKind(kind) {
87
93
  kind === TokenKind.AMP ||
88
94
  kind === TokenKind.PAREN_L ||
89
95
  kind === TokenKind.PAREN_R ||
96
+ kind === TokenKind.DOT ||
90
97
  kind === TokenKind.SPREAD ||
91
98
  kind === TokenKind.COLON ||
92
99
  kind === TokenKind.EQUALS ||
@@ -141,9 +148,11 @@ function isTrailingSurrogate(code) {
141
148
  *
142
149
  * Printable ASCII is printed quoted, while other points are printed in Unicode
143
150
  * code point form (ie. U+1234).
151
+ *
152
+ * @internal
144
153
  */
145
154
 
146
- function printCodePointAt(lexer, location) {
155
+ export function printCodePointAt(lexer, location) {
147
156
  const code = lexer.source.body.codePointAt(location);
148
157
 
149
158
  if (code === undefined) {
@@ -158,9 +167,11 @@ function printCodePointAt(lexer, location) {
158
167
  }
159
168
  /**
160
169
  * Create a token with line and column location information.
170
+ *
171
+ * @internal
161
172
  */
162
173
 
163
- function createToken(lexer, kind, start, end, value) {
174
+ export function createToken(lexer, kind, start, end, value) {
164
175
  const line = lexer.line;
165
176
  const col = 1 + start - lexer.lineStart;
166
177
  return new Token(kind, start, end, line, col, value);
@@ -875,9 +886,11 @@ function readBlockString(lexer, start) {
875
886
  * Name ::
876
887
  * - NameStart NameContinue* [lookahead != NameContinue]
877
888
  * ```
889
+ *
890
+ * @internal
878
891
  */
879
892
 
880
- function readName(lexer, start) {
893
+ export function readName(lexer, start) {
881
894
  const body = lexer.source.body;
882
895
  const bodyLength = body.length;
883
896
  let position = start + 1;
@@ -36,6 +36,7 @@ import type {
36
36
  OperationTypeDefinitionNode,
37
37
  ScalarTypeDefinitionNode,
38
38
  ScalarTypeExtensionNode,
39
+ SchemaCoordinateNode,
39
40
  SchemaDefinitionNode,
40
41
  SchemaExtensionNode,
41
42
  SelectionNode,
@@ -51,7 +52,7 @@ import type {
51
52
  VariableNode,
52
53
  } from './ast';
53
54
  import { Location, OperationTypeNode } from './ast';
54
- import { Lexer } from './lexer';
55
+ import type { LexerInterface } from './lexer';
55
56
  import { Source } from './source';
56
57
  import { TokenKind } from './tokenKind';
57
58
  /**
@@ -88,6 +89,11 @@ export interface ParseOptions {
88
89
  * ```
89
90
  */
90
91
  allowLegacyFragmentVariables?: boolean;
92
+ /**
93
+ * You may override the Lexer class used to lex the source; this is used by
94
+ * schema coordinates to introduce a lexer with a restricted syntax.
95
+ */
96
+ lexer?: LexerInterface | undefined;
91
97
  }
92
98
  /**
93
99
  * Given a GraphQL source, parses it into a Document.
@@ -133,6 +139,18 @@ export declare function parseType(
133
139
  source: string | Source,
134
140
  options?: ParseOptions | undefined,
135
141
  ): TypeNode;
142
+ /**
143
+ * Given a string containing a GraphQL Schema Coordinate (ex. `Type.field`),
144
+ * parse the AST for that schema coordinate.
145
+ * Throws GraphQLError if a syntax error is encountered.
146
+ *
147
+ * Consider providing the results to the utility function:
148
+ * resolveASTSchemaCoordinate(). Or calling resolveSchemaCoordinate() directly
149
+ * with an unparsed source.
150
+ */
151
+ export declare function parseSchemaCoordinate(
152
+ source: string | Source,
153
+ ): SchemaCoordinateNode;
136
154
  /**
137
155
  * This class is exported only to assist people in implementing their own parsers
138
156
  * without duplicating too much code and should be used only as last resort for cases
@@ -145,8 +163,8 @@ export declare function parseType(
145
163
  * @internal
146
164
  */
147
165
  export declare class Parser {
148
- protected _options: ParseOptions;
149
- protected _lexer: Lexer;
166
+ protected _options: Omit<ParseOptions, 'lexer'>;
167
+ protected _lexer: LexerInterface;
150
168
  protected _tokenCounter: number;
151
169
  constructor(source: string | Source, options?: ParseOptions);
152
170
  get tokenCount(): number;
@@ -490,6 +508,15 @@ export declare class Parser {
490
508
  */
491
509
  parseDirectiveLocations(): Array<NameNode>;
492
510
  parseDirectiveLocation(): NameNode;
511
+ /**
512
+ * SchemaCoordinate :
513
+ * - Name
514
+ * - Name . Name
515
+ * - Name . Name ( Name : )
516
+ * - \@ Name
517
+ * - \@ Name ( Name : )
518
+ */
519
+ parseSchemaCoordinate(): SchemaCoordinateNode;
493
520
  /**
494
521
  * Returns a node that, if configured to do so, sets a "loc" field as a
495
522
  * location object, used to identify the place in the source that created a