graphql 14.0.0 → 14.1.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.
Files changed (285) hide show
  1. package/README.md +4 -4
  2. package/error/GraphQLError.js +1 -1
  3. package/error/GraphQLError.js.flow +3 -3
  4. package/error/GraphQLError.mjs +1 -1
  5. package/error/formatError.js +1 -1
  6. package/error/formatError.mjs +1 -1
  7. package/error/index.mjs +1 -1
  8. package/error/locatedError.js +1 -1
  9. package/error/locatedError.mjs +1 -1
  10. package/error/printError.js +1 -1
  11. package/error/printError.mjs +1 -1
  12. package/error/syntaxError.js +1 -1
  13. package/error/syntaxError.mjs +1 -1
  14. package/execution/execute.js +4 -4
  15. package/execution/execute.js.flow +4 -6
  16. package/execution/execute.mjs +5 -5
  17. package/execution/index.mjs +1 -1
  18. package/execution/values.js +4 -4
  19. package/execution/values.js.flow +3 -3
  20. package/execution/values.mjs +3 -3
  21. package/graphql.js +1 -1
  22. package/graphql.mjs +1 -1
  23. package/index.js +12 -0
  24. package/index.js.flow +4 -0
  25. package/index.mjs +4 -4
  26. package/jsutils/dedent.js +2 -2
  27. package/jsutils/dedent.js.flow +1 -1
  28. package/jsutils/dedent.mjs +2 -2
  29. package/jsutils/defineToJSON.js +17 -6
  30. package/jsutils/defineToJSON.js.flow +14 -5
  31. package/jsutils/defineToJSON.mjs +14 -6
  32. package/jsutils/defineToStringTag.js +5 -5
  33. package/jsutils/defineToStringTag.js.flow +3 -3
  34. package/jsutils/defineToStringTag.mjs +4 -4
  35. package/jsutils/inspect.js +46 -12
  36. package/jsutils/inspect.js.flow +42 -15
  37. package/jsutils/inspect.mjs +45 -5
  38. package/jsutils/instanceOf.js +1 -1
  39. package/jsutils/instanceOf.mjs +1 -1
  40. package/jsutils/invariant.js +1 -1
  41. package/jsutils/invariant.mjs +1 -1
  42. package/jsutils/isInvalid.js +1 -1
  43. package/jsutils/isInvalid.mjs +1 -1
  44. package/jsutils/isNullish.js +1 -1
  45. package/jsutils/isNullish.mjs +1 -1
  46. package/jsutils/isPromise.js +1 -1
  47. package/jsutils/isPromise.mjs +1 -1
  48. package/jsutils/keyMap.js +1 -1
  49. package/jsutils/keyMap.mjs +1 -1
  50. package/jsutils/keyValMap.js +1 -1
  51. package/jsutils/keyValMap.mjs +1 -1
  52. package/jsutils/mapValue.js +54 -0
  53. package/jsutils/mapValue.js.flow +27 -0
  54. package/jsutils/mapValue.mjs +44 -0
  55. package/jsutils/memoize3.js +1 -1
  56. package/jsutils/memoize3.mjs +1 -1
  57. package/jsutils/nodejsCustomInspectSymbol.js +18 -0
  58. package/jsutils/nodejsCustomInspectSymbol.js.flow +15 -0
  59. package/jsutils/nodejsCustomInspectSymbol.mjs +10 -0
  60. package/jsutils/orList.js +17 -4
  61. package/jsutils/orList.js.flow +13 -7
  62. package/jsutils/orList.mjs +14 -4
  63. package/jsutils/promiseForObject.js +1 -1
  64. package/jsutils/promiseForObject.mjs +1 -1
  65. package/jsutils/promiseReduce.js +1 -1
  66. package/jsutils/promiseReduce.mjs +1 -1
  67. package/jsutils/quotedOrList.js +1 -1
  68. package/jsutils/quotedOrList.mjs +1 -1
  69. package/jsutils/suggestionList.js +1 -1
  70. package/jsutils/suggestionList.mjs +1 -1
  71. package/language/blockStringValue.js +2 -2
  72. package/language/blockStringValue.js.flow +1 -1
  73. package/language/blockStringValue.mjs +2 -2
  74. package/language/directiveLocation.js +1 -1
  75. package/language/directiveLocation.mjs +1 -1
  76. package/language/index.mjs +1 -1
  77. package/language/kinds.js +1 -1
  78. package/language/kinds.mjs +1 -1
  79. package/language/lexer.js +29 -13
  80. package/language/lexer.js.flow +34 -20
  81. package/language/lexer.mjs +28 -13
  82. package/language/location.js +1 -1
  83. package/language/location.mjs +1 -1
  84. package/language/parser.js +31 -38
  85. package/language/parser.js.flow +32 -48
  86. package/language/parser.mjs +30 -38
  87. package/language/predicates.js +1 -1
  88. package/language/predicates.mjs +1 -1
  89. package/language/printer.js +13 -7
  90. package/language/printer.js.flow +19 -9
  91. package/language/printer.mjs +13 -7
  92. package/language/source.js +8 -7
  93. package/language/source.mjs +1 -9
  94. package/language/visitor.js +11 -20
  95. package/language/visitor.js.flow +4 -5
  96. package/language/visitor.mjs +8 -20
  97. package/package.json +10 -3
  98. package/polyfills/find.js +31 -0
  99. package/polyfills/find.js.flow +29 -0
  100. package/polyfills/find.mjs +23 -0
  101. package/{jsutils → polyfills}/isFinite.js +1 -1
  102. package/{jsutils → polyfills}/isFinite.js.flow +0 -0
  103. package/{jsutils → polyfills}/isFinite.mjs +1 -1
  104. package/{jsutils → polyfills}/isInteger.js +1 -1
  105. package/{jsutils → polyfills}/isInteger.js.flow +0 -0
  106. package/{jsutils → polyfills}/isInteger.mjs +1 -1
  107. package/polyfills/objectEntries.js +26 -0
  108. package/polyfills/objectEntries.js.flow +19 -0
  109. package/polyfills/objectEntries.mjs +18 -0
  110. package/{jsutils → polyfills}/objectValues.js +1 -1
  111. package/{jsutils → polyfills}/objectValues.js.flow +1 -1
  112. package/{jsutils → polyfills}/objectValues.mjs +1 -1
  113. package/subscription/asyncIteratorReject.mjs +1 -1
  114. package/subscription/index.mjs +1 -1
  115. package/subscription/mapAsyncIterator.mjs +1 -1
  116. package/subscription/subscribe.js +1 -1
  117. package/subscription/subscribe.js.flow +1 -1
  118. package/subscription/subscribe.mjs +2 -2
  119. package/type/definition.js +31 -130
  120. package/type/definition.js.flow +35 -47
  121. package/type/definition.mjs +30 -131
  122. package/type/directives.js +25 -29
  123. package/type/directives.js.flow +24 -20
  124. package/type/directives.mjs +22 -30
  125. package/type/index.js +12 -0
  126. package/type/index.js.flow +4 -0
  127. package/type/index.mjs +5 -3
  128. package/type/introspection.js +3 -3
  129. package/type/introspection.js.flow +1 -1
  130. package/type/introspection.mjs +2 -2
  131. package/type/scalars.js +45 -34
  132. package/type/scalars.js.flow +40 -26
  133. package/type/scalars.mjs +44 -26
  134. package/type/schema.js +82 -87
  135. package/type/schema.js.flow +17 -9
  136. package/type/schema.mjs +79 -86
  137. package/type/validate.js +168 -175
  138. package/type/validate.js.flow +8 -49
  139. package/type/validate.mjs +159 -175
  140. package/utilities/TypeInfo.js +10 -23
  141. package/utilities/TypeInfo.js.flow +1 -1
  142. package/utilities/TypeInfo.mjs +2 -24
  143. package/utilities/assertValidName.js +1 -1
  144. package/utilities/assertValidName.mjs +1 -1
  145. package/utilities/astFromValue.js +2 -2
  146. package/utilities/astFromValue.js.flow +1 -1
  147. package/utilities/astFromValue.mjs +2 -2
  148. package/utilities/buildASTSchema.js +169 -152
  149. package/utilities/buildASTSchema.js.flow +117 -113
  150. package/utilities/buildASTSchema.mjs +160 -152
  151. package/utilities/buildClientSchema.js +24 -14
  152. package/utilities/buildClientSchema.js.flow +24 -14
  153. package/utilities/buildClientSchema.mjs +23 -14
  154. package/utilities/coerceValue.js +38 -19
  155. package/utilities/coerceValue.js.flow +41 -47
  156. package/utilities/coerceValue.mjs +38 -20
  157. package/utilities/concatAST.js +1 -1
  158. package/utilities/concatAST.mjs +1 -1
  159. package/utilities/extendSchema.js +228 -312
  160. package/utilities/extendSchema.js.flow +27 -152
  161. package/utilities/extendSchema.mjs +229 -312
  162. package/utilities/findBreakingChanges.js +7 -5
  163. package/utilities/findBreakingChanges.js.flow +3 -2
  164. package/utilities/findBreakingChanges.mjs +6 -5
  165. package/utilities/findDeprecatedUsages.js +1 -1
  166. package/utilities/findDeprecatedUsages.mjs +1 -1
  167. package/utilities/getOperationAST.js +1 -1
  168. package/utilities/getOperationAST.mjs +1 -1
  169. package/utilities/getOperationRootType.js +1 -1
  170. package/utilities/getOperationRootType.mjs +1 -1
  171. package/utilities/index.mjs +1 -1
  172. package/utilities/introspectionFromSchema.js +1 -1
  173. package/utilities/introspectionFromSchema.mjs +1 -1
  174. package/utilities/introspectionQuery.js +1 -1
  175. package/utilities/introspectionQuery.mjs +1 -1
  176. package/utilities/isValidJSValue.js +1 -1
  177. package/utilities/isValidJSValue.mjs +1 -1
  178. package/utilities/isValidLiteralValue.js +1 -1
  179. package/utilities/isValidLiteralValue.mjs +1 -1
  180. package/utilities/lexicographicSortSchema.js +2 -2
  181. package/utilities/lexicographicSortSchema.js.flow +1 -1
  182. package/utilities/lexicographicSortSchema.mjs +2 -2
  183. package/utilities/schemaPrinter.js +3 -3
  184. package/utilities/schemaPrinter.js.flow +1 -1
  185. package/utilities/schemaPrinter.mjs +2 -2
  186. package/utilities/separateOperations.js +1 -1
  187. package/utilities/separateOperations.mjs +1 -1
  188. package/utilities/typeComparators.js +1 -1
  189. package/utilities/typeComparators.mjs +1 -1
  190. package/utilities/typeFromAST.js +1 -1
  191. package/utilities/typeFromAST.mjs +1 -1
  192. package/utilities/valueFromAST.js +3 -3
  193. package/utilities/valueFromAST.js.flow +1 -1
  194. package/utilities/valueFromAST.mjs +2 -2
  195. package/utilities/valueFromASTUntyped.js +1 -1
  196. package/utilities/valueFromASTUntyped.mjs +1 -1
  197. package/validation/ValidationContext.js +57 -82
  198. package/validation/ValidationContext.js.flow +52 -49
  199. package/validation/ValidationContext.mjs +52 -77
  200. package/validation/index.js.flow +1 -0
  201. package/validation/index.mjs +1 -1
  202. package/validation/rules/ExecutableDefinitions.js +1 -1
  203. package/validation/rules/ExecutableDefinitions.js.flow +1 -1
  204. package/validation/rules/ExecutableDefinitions.mjs +1 -1
  205. package/validation/rules/FieldsOnCorrectType.js +1 -1
  206. package/validation/rules/FieldsOnCorrectType.mjs +1 -1
  207. package/validation/rules/FragmentsOnCompositeTypes.js +1 -1
  208. package/validation/rules/FragmentsOnCompositeTypes.mjs +1 -1
  209. package/validation/rules/KnownArgumentNames.mjs +1 -1
  210. package/validation/rules/KnownDirectives.js +1 -1
  211. package/validation/rules/KnownDirectives.mjs +1 -1
  212. package/validation/rules/KnownFragmentNames.js +1 -1
  213. package/validation/rules/KnownFragmentNames.mjs +1 -1
  214. package/validation/rules/KnownTypeNames.js +59 -21
  215. package/validation/rules/KnownTypeNames.js.flow +54 -20
  216. package/validation/rules/KnownTypeNames.mjs +56 -21
  217. package/validation/rules/LoneAnonymousOperation.js +1 -1
  218. package/validation/rules/LoneAnonymousOperation.mjs +1 -1
  219. package/validation/rules/LoneSchemaDefinition.js +1 -1
  220. package/validation/rules/LoneSchemaDefinition.mjs +1 -1
  221. package/validation/rules/NoFragmentCycles.js +1 -1
  222. package/validation/rules/NoFragmentCycles.js.flow +2 -2
  223. package/validation/rules/NoFragmentCycles.mjs +1 -1
  224. package/validation/rules/NoUndefinedVariables.js +1 -1
  225. package/validation/rules/NoUndefinedVariables.mjs +1 -1
  226. package/validation/rules/NoUnusedFragments.js +1 -1
  227. package/validation/rules/NoUnusedFragments.js.flow +2 -2
  228. package/validation/rules/NoUnusedFragments.mjs +1 -1
  229. package/validation/rules/NoUnusedVariables.js +1 -1
  230. package/validation/rules/NoUnusedVariables.mjs +1 -1
  231. package/validation/rules/OverlappingFieldsCanBeMerged.js +57 -33
  232. package/validation/rules/OverlappingFieldsCanBeMerged.js.flow +5 -6
  233. package/validation/rules/OverlappingFieldsCanBeMerged.mjs +48 -33
  234. package/validation/rules/PossibleFragmentSpreads.js +1 -1
  235. package/validation/rules/PossibleFragmentSpreads.mjs +1 -1
  236. package/validation/rules/PossibleTypeExtensions.js +158 -0
  237. package/validation/rules/PossibleTypeExtensions.js.flow +160 -0
  238. package/validation/rules/PossibleTypeExtensions.mjs +146 -0
  239. package/validation/rules/ProvidedRequiredArguments.mjs +1 -1
  240. package/validation/rules/ScalarLeafs.js +1 -1
  241. package/validation/rules/ScalarLeafs.mjs +1 -1
  242. package/validation/rules/SingleFieldSubscriptions.js +1 -1
  243. package/validation/rules/SingleFieldSubscriptions.mjs +1 -1
  244. package/validation/rules/UniqueArgumentNames.js +1 -1
  245. package/validation/rules/UniqueArgumentNames.mjs +1 -1
  246. package/validation/rules/UniqueDirectiveNames.js +55 -0
  247. package/validation/rules/UniqueDirectiveNames.js.flow +64 -0
  248. package/validation/rules/UniqueDirectiveNames.mjs +43 -0
  249. package/validation/rules/UniqueDirectivesPerLocation.js +1 -1
  250. package/validation/rules/UniqueDirectivesPerLocation.mjs +1 -1
  251. package/validation/rules/UniqueEnumValueNames.js +94 -0
  252. package/validation/rules/UniqueEnumValueNames.js.flow +87 -0
  253. package/validation/rules/UniqueEnumValueNames.mjs +81 -0
  254. package/validation/rules/UniqueFieldDefinitionNames.js +105 -0
  255. package/validation/rules/UniqueFieldDefinitionNames.js.flow +101 -0
  256. package/validation/rules/UniqueFieldDefinitionNames.mjs +92 -0
  257. package/validation/rules/UniqueFragmentNames.js +1 -1
  258. package/validation/rules/UniqueFragmentNames.mjs +1 -1
  259. package/validation/rules/UniqueInputFieldNames.js +1 -1
  260. package/validation/rules/UniqueInputFieldNames.mjs +1 -1
  261. package/validation/rules/UniqueOperationNames.js +1 -1
  262. package/validation/rules/UniqueOperationNames.mjs +1 -1
  263. package/validation/rules/UniqueOperationTypes.js +85 -0
  264. package/validation/rules/UniqueOperationTypes.js.flow +76 -0
  265. package/validation/rules/UniqueOperationTypes.mjs +73 -0
  266. package/validation/rules/UniqueTypeNames.js +62 -0
  267. package/validation/rules/UniqueTypeNames.js.flow +67 -0
  268. package/validation/rules/UniqueTypeNames.mjs +50 -0
  269. package/validation/rules/UniqueVariableNames.js +1 -1
  270. package/validation/rules/UniqueVariableNames.mjs +1 -1
  271. package/validation/rules/ValuesOfCorrectType.js +29 -13
  272. package/validation/rules/ValuesOfCorrectType.js.flow +4 -5
  273. package/validation/rules/ValuesOfCorrectType.mjs +28 -13
  274. package/validation/rules/VariablesAreInputTypes.js +1 -1
  275. package/validation/rules/VariablesAreInputTypes.mjs +1 -1
  276. package/validation/rules/VariablesInAllowedPosition.js +4 -4
  277. package/validation/rules/VariablesInAllowedPosition.mjs +4 -4
  278. package/validation/specifiedRules.js +14 -2
  279. package/validation/specifiedRules.js.flow +13 -0
  280. package/validation/specifiedRules.mjs +8 -2
  281. package/validation/validate.js +1 -1
  282. package/validation/validate.mjs +1 -1
  283. package/jsutils/find.js +0 -22
  284. package/jsutils/find.js.flow +0 -19
  285. package/jsutils/find.mjs +0 -15
@@ -1,13 +1,12 @@
1
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
-
3
1
  /**
4
2
  * Copyright (c) 2015-present, Facebook, Inc.
5
3
  *
6
4
  * This source code is licensed under the MIT license found in the
7
5
  * LICENSE file in the root directory of this source tree.
8
6
  *
9
- * strict
7
+ *
10
8
  */
9
+ import objectValues from '../polyfills/objectValues';
11
10
  import invariant from '../jsutils/invariant';
12
11
  import keyMap from '../jsutils/keyMap';
13
12
  import keyValMap from '../jsutils/keyValMap';
@@ -49,26 +48,36 @@ export function buildASTSchema(documentAST, options) {
49
48
  }
50
49
 
51
50
  var schemaDef;
52
- var typeDefs = [];
53
51
  var nodeMap = Object.create(null);
54
52
  var directiveDefs = [];
55
-
56
- for (var i = 0; i < documentAST.definitions.length; i++) {
57
- var def = documentAST.definitions[i];
58
-
59
- if (def.kind === Kind.SCHEMA_DEFINITION) {
60
- schemaDef = def;
61
- } else if (isTypeDefinitionNode(def)) {
62
- var typeName = def.name.value;
63
-
64
- if (nodeMap[typeName]) {
65
- throw new Error("Type \"".concat(typeName, "\" was defined more than once."));
53
+ var _iteratorNormalCompletion = true;
54
+ var _didIteratorError = false;
55
+ var _iteratorError = undefined;
56
+
57
+ try {
58
+ for (var _iterator = documentAST.definitions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
59
+ var def = _step.value;
60
+
61
+ if (def.kind === Kind.SCHEMA_DEFINITION) {
62
+ schemaDef = def;
63
+ } else if (isTypeDefinitionNode(def)) {
64
+ nodeMap[def.name.value] = def;
65
+ } else if (def.kind === Kind.DIRECTIVE_DEFINITION) {
66
+ directiveDefs.push(def);
67
+ }
68
+ }
69
+ } catch (err) {
70
+ _didIteratorError = true;
71
+ _iteratorError = err;
72
+ } finally {
73
+ try {
74
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
75
+ _iterator.return();
76
+ }
77
+ } finally {
78
+ if (_didIteratorError) {
79
+ throw _iteratorError;
66
80
  }
67
-
68
- typeDefs.push(def);
69
- nodeMap[typeName] = def;
70
- } else if (def.kind === Kind.DIRECTIVE_DEFINITION) {
71
- directiveDefs.push(def);
72
81
  }
73
82
  }
74
83
 
@@ -77,8 +86,8 @@ export function buildASTSchema(documentAST, options) {
77
86
  mutation: nodeMap.Mutation,
78
87
  subscription: nodeMap.Subscription
79
88
  };
80
- var definitionBuilder = new ASTDefinitionBuilder(nodeMap, options, function (typeRef) {
81
- throw new Error("Type \"".concat(typeRef.name.value, "\" not found in document."));
89
+ var definitionBuilder = new ASTDefinitionBuilder(nodeMap, options, function (typeName) {
90
+ throw new Error("Type \"".concat(typeName, "\" not found in document."));
82
91
  });
83
92
  var directives = directiveDefs.map(function (def) {
84
93
  return definitionBuilder.buildDirective(def);
@@ -109,7 +118,7 @@ export function buildASTSchema(documentAST, options) {
109
118
  query: operationTypes.query ? definitionBuilder.buildType(operationTypes.query) : null,
110
119
  mutation: operationTypes.mutation ? definitionBuilder.buildType(operationTypes.mutation) : null,
111
120
  subscription: operationTypes.subscription ? definitionBuilder.buildType(operationTypes.subscription) : null,
112
- types: typeDefs.map(function (node) {
121
+ types: objectValues(nodeMap).map(function (node) {
113
122
  return definitionBuilder.buildType(node);
114
123
  }),
115
124
  directives: directives,
@@ -120,37 +129,26 @@ export function buildASTSchema(documentAST, options) {
120
129
 
121
130
  function getOperationTypes(schema) {
122
131
  var opTypes = {};
123
- var _iteratorNormalCompletion = true;
124
- var _didIteratorError = false;
125
- var _iteratorError = undefined;
132
+ var _iteratorNormalCompletion2 = true;
133
+ var _didIteratorError2 = false;
134
+ var _iteratorError2 = undefined;
126
135
 
127
136
  try {
128
- for (var _iterator = schema.operationTypes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
129
- var operationType = _step.value;
130
- var _typeName = operationType.type.name.value;
131
- var operation = operationType.operation;
132
-
133
- if (opTypes[operation]) {
134
- throw new Error("Must provide only one ".concat(operation, " type in schema."));
135
- }
136
-
137
- if (!nodeMap[_typeName]) {
138
- throw new Error("Specified ".concat(operation, " type \"").concat(_typeName, "\" not found in document."));
139
- }
140
-
141
- opTypes[operation] = operationType.type;
137
+ for (var _iterator2 = schema.operationTypes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
138
+ var operationType = _step2.value;
139
+ opTypes[operationType.operation] = operationType.type;
142
140
  }
143
141
  } catch (err) {
144
- _didIteratorError = true;
145
- _iteratorError = err;
142
+ _didIteratorError2 = true;
143
+ _iteratorError2 = err;
146
144
  } finally {
147
145
  try {
148
- if (!_iteratorNormalCompletion && _iterator.return != null) {
149
- _iterator.return();
146
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
147
+ _iterator2.return();
150
148
  }
151
149
  } finally {
152
- if (_didIteratorError) {
153
- throw _iteratorError;
150
+ if (_didIteratorError2) {
151
+ throw _iteratorError2;
154
152
  }
155
153
  }
156
154
  }
@@ -162,14 +160,6 @@ export var ASTDefinitionBuilder =
162
160
  /*#__PURE__*/
163
161
  function () {
164
162
  function ASTDefinitionBuilder(typeDefinitionsMap, options, resolveType) {
165
- _defineProperty(this, "_typeDefinitionsMap", void 0);
166
-
167
- _defineProperty(this, "_options", void 0);
168
-
169
- _defineProperty(this, "_resolveType", void 0);
170
-
171
- _defineProperty(this, "_cache", void 0);
172
-
173
163
  this._typeDefinitionsMap = typeDefinitionsMap;
174
164
  this._options = options;
175
165
  this._resolveType = resolveType; // Initialize to the GraphQL built in scalars and introspection types.
@@ -187,7 +177,7 @@ function () {
187
177
  if (!this._cache[typeName]) {
188
178
  if (node.kind === Kind.NAMED_TYPE) {
189
179
  var defNode = this._typeDefinitionsMap[typeName];
190
- this._cache[typeName] = defNode ? this._makeSchemaDef(defNode) : this._resolveType(node);
180
+ this._cache[typeName] = defNode ? this._makeSchemaDef(defNode) : this._resolveType(node.name.value);
191
181
  } else {
192
182
  this._cache[typeName] = this._makeSchemaDef(node);
193
183
  }
@@ -209,38 +199,60 @@ function () {
209
199
  return this.buildType(typeNode);
210
200
  };
211
201
 
212
- _proto.buildDirective = function buildDirective(directiveNode) {
202
+ _proto.buildDirective = function buildDirective(directive) {
203
+ var _this = this;
204
+
205
+ var locations = directive.locations.map(function (_ref) {
206
+ var value = _ref.value;
207
+ return value;
208
+ });
213
209
  return new GraphQLDirective({
214
- name: directiveNode.name.value,
215
- description: getDescription(directiveNode, this._options),
216
- locations: directiveNode.locations.map(function (node) {
217
- return node.value;
210
+ name: directive.name.value,
211
+ description: getDescription(directive, this._options),
212
+ locations: locations,
213
+ args: keyByNameNode(directive.arguments || [], function (arg) {
214
+ return _this.buildArg(arg);
218
215
  }),
219
- args: directiveNode.arguments && this._makeInputValues(directiveNode.arguments),
220
- astNode: directiveNode
216
+ astNode: directive
221
217
  });
222
218
  };
223
219
 
224
220
  _proto.buildField = function buildField(field) {
221
+ var _this2 = this;
222
+
225
223
  return {
226
224
  // Note: While this could make assertions to get the correctly typed
227
225
  // value, that would throw immediately while type system validation
228
226
  // with validateSchema() will produce more actionable results.
229
227
  type: this._buildWrappedType(field.type),
230
228
  description: getDescription(field, this._options),
231
- args: field.arguments && this._makeInputValues(field.arguments),
229
+ args: keyByNameNode(field.arguments || [], function (arg) {
230
+ return _this2.buildArg(arg);
231
+ }),
232
232
  deprecationReason: getDeprecationReason(field),
233
233
  astNode: field
234
234
  };
235
235
  };
236
236
 
237
+ _proto.buildArg = function buildArg(value) {
238
+ // Note: While this could make assertions to get the correctly typed
239
+ // value, that would throw immediately while type system validation
240
+ var type = this._buildWrappedType(value.type);
241
+
242
+ return {
243
+ type: type,
244
+ description: getDescription(value, this._options),
245
+ defaultValue: valueFromAST(value.defaultValue, type),
246
+ astNode: value
247
+ };
248
+ };
249
+
237
250
  _proto.buildInputField = function buildInputField(value) {
238
251
  // Note: While this could make assertions to get the correctly typed
239
252
  // value, that would throw immediately while type system validation
240
253
  var type = this._buildWrappedType(value.type);
241
254
 
242
255
  return {
243
- name: value.name.value,
244
256
  type: type,
245
257
  description: getDescription(value, this._options),
246
258
  defaultValue: valueFromAST(value.defaultValue, type),
@@ -256,129 +268,114 @@ function () {
256
268
  };
257
269
  };
258
270
 
259
- _proto._makeSchemaDef = function _makeSchemaDef(def) {
260
- switch (def.kind) {
271
+ _proto._makeSchemaDef = function _makeSchemaDef(astNode) {
272
+ switch (astNode.kind) {
261
273
  case Kind.OBJECT_TYPE_DEFINITION:
262
- return this._makeTypeDef(def);
274
+ return this._makeTypeDef(astNode);
263
275
 
264
276
  case Kind.INTERFACE_TYPE_DEFINITION:
265
- return this._makeInterfaceDef(def);
277
+ return this._makeInterfaceDef(astNode);
266
278
 
267
279
  case Kind.ENUM_TYPE_DEFINITION:
268
- return this._makeEnumDef(def);
280
+ return this._makeEnumDef(astNode);
269
281
 
270
282
  case Kind.UNION_TYPE_DEFINITION:
271
- return this._makeUnionDef(def);
283
+ return this._makeUnionDef(astNode);
272
284
 
273
285
  case Kind.SCALAR_TYPE_DEFINITION:
274
- return this._makeScalarDef(def);
286
+ return this._makeScalarDef(astNode);
275
287
 
276
288
  case Kind.INPUT_OBJECT_TYPE_DEFINITION:
277
- return this._makeInputObjectDef(def);
289
+ return this._makeInputObjectDef(astNode);
278
290
 
279
291
  default:
280
- throw new Error("Type kind \"".concat(def.kind, "\" not supported."));
292
+ throw new Error("Type kind \"".concat(astNode.kind, "\" not supported."));
281
293
  }
282
294
  };
283
295
 
284
- _proto._makeTypeDef = function _makeTypeDef(def) {
285
- var _this = this;
286
-
287
- var interfaces = def.interfaces;
288
- return new GraphQLObjectType({
289
- name: def.name.value,
290
- description: getDescription(def, this._options),
291
- fields: function fields() {
292
- return _this._makeFieldDefMap(def);
293
- },
294
- // Note: While this could make early assertions to get the correctly
295
- // typed values, that would throw immediately while type system
296
- // validation with validateSchema() will produce more actionable results.
297
- interfaces: interfaces ? function () {
298
- return interfaces.map(function (ref) {
299
- return _this.buildType(ref);
300
- });
301
- } : [],
302
- astNode: def
303
- });
304
- };
305
-
306
- _proto._makeFieldDefMap = function _makeFieldDefMap(def) {
307
- var _this2 = this;
308
-
309
- return def.fields ? keyValMap(def.fields, function (field) {
310
- return field.name.value;
311
- }, function (field) {
312
- return _this2.buildField(field);
313
- }) : {};
314
- };
315
-
316
- _proto._makeInputValues = function _makeInputValues(values) {
296
+ _proto._makeTypeDef = function _makeTypeDef(astNode) {
317
297
  var _this3 = this;
318
298
 
319
- return keyValMap(values, function (value) {
320
- return value.name.value;
321
- }, function (value) {
322
- return _this3.buildInputField(value);
299
+ var interfaceNodes = astNode.interfaces;
300
+ var fieldNodes = astNode.fields; // Note: While this could make assertions to get the correctly typed
301
+ // values below, that would throw immediately while type system
302
+ // validation with validateSchema() will produce more actionable results.
303
+
304
+ var interfaces = interfaceNodes && interfaceNodes.length > 0 ? function () {
305
+ return interfaceNodes.map(function (ref) {
306
+ return _this3.buildType(ref);
307
+ });
308
+ } : [];
309
+ var fields = fieldNodes && fieldNodes.length > 0 ? function () {
310
+ return keyByNameNode(fieldNodes, function (field) {
311
+ return _this3.buildField(field);
312
+ });
313
+ } : Object.create(null);
314
+ return new GraphQLObjectType({
315
+ name: astNode.name.value,
316
+ description: getDescription(astNode, this._options),
317
+ interfaces: interfaces,
318
+ fields: fields,
319
+ astNode: astNode
323
320
  });
324
321
  };
325
322
 
326
- _proto._makeInterfaceDef = function _makeInterfaceDef(def) {
323
+ _proto._makeInterfaceDef = function _makeInterfaceDef(astNode) {
327
324
  var _this4 = this;
328
325
 
326
+ var fieldNodes = astNode.fields;
327
+ var fields = fieldNodes && fieldNodes.length > 0 ? function () {
328
+ return keyByNameNode(fieldNodes, function (field) {
329
+ return _this4.buildField(field);
330
+ });
331
+ } : Object.create(null);
329
332
  return new GraphQLInterfaceType({
330
- name: def.name.value,
331
- description: getDescription(def, this._options),
332
- fields: function fields() {
333
- return _this4._makeFieldDefMap(def);
334
- },
335
- astNode: def
336
- });
337
- };
338
-
339
- _proto._makeEnumDef = function _makeEnumDef(def) {
340
- return new GraphQLEnumType({
341
- name: def.name.value,
342
- description: getDescription(def, this._options),
343
- values: this._makeValueDefMap(def),
344
- astNode: def
333
+ name: astNode.name.value,
334
+ description: getDescription(astNode, this._options),
335
+ fields: fields,
336
+ astNode: astNode
345
337
  });
346
338
  };
347
339
 
348
- _proto._makeValueDefMap = function _makeValueDefMap(def) {
340
+ _proto._makeEnumDef = function _makeEnumDef(astNode) {
349
341
  var _this5 = this;
350
342
 
351
- return def.values ? keyValMap(def.values, function (enumValue) {
352
- return enumValue.name.value;
353
- }, function (enumValue) {
354
- return _this5.buildEnumValue(enumValue);
355
- }) : {};
343
+ var valueNodes = astNode.values || [];
344
+ return new GraphQLEnumType({
345
+ name: astNode.name.value,
346
+ description: getDescription(astNode, this._options),
347
+ values: keyByNameNode(valueNodes, function (value) {
348
+ return _this5.buildEnumValue(value);
349
+ }),
350
+ astNode: astNode
351
+ });
356
352
  };
357
353
 
358
- _proto._makeUnionDef = function _makeUnionDef(def) {
354
+ _proto._makeUnionDef = function _makeUnionDef(astNode) {
359
355
  var _this6 = this;
360
356
 
361
- var types = def.types;
357
+ var typeNodes = astNode.types; // Note: While this could make assertions to get the correctly typed
358
+ // values below, that would throw immediately while type system
359
+ // validation with validateSchema() will produce more actionable results.
360
+
361
+ var types = typeNodes && typeNodes.length > 0 ? function () {
362
+ return typeNodes.map(function (ref) {
363
+ return _this6.buildType(ref);
364
+ });
365
+ } : [];
362
366
  return new GraphQLUnionType({
363
- name: def.name.value,
364
- description: getDescription(def, this._options),
365
- // Note: While this could make assertions to get the correctly typed
366
- // values below, that would throw immediately while type system
367
- // validation with validateSchema() will produce more actionable results.
368
- types: types ? function () {
369
- return types.map(function (ref) {
370
- return _this6.buildType(ref);
371
- });
372
- } : [],
373
- astNode: def
367
+ name: astNode.name.value,
368
+ description: getDescription(astNode, this._options),
369
+ types: types,
370
+ astNode: astNode
374
371
  });
375
372
  };
376
373
 
377
- _proto._makeScalarDef = function _makeScalarDef(def) {
374
+ _proto._makeScalarDef = function _makeScalarDef(astNode) {
378
375
  return new GraphQLScalarType({
379
- name: def.name.value,
380
- description: getDescription(def, this._options),
381
- astNode: def,
376
+ name: astNode.name.value,
377
+ description: getDescription(astNode, this._options),
378
+ astNode: astNode,
382
379
  serialize: function serialize(value) {
383
380
  return value;
384
381
  }
@@ -388,23 +385,34 @@ function () {
388
385
  _proto._makeInputObjectDef = function _makeInputObjectDef(def) {
389
386
  var _this7 = this;
390
387
 
388
+ var fields = def.fields;
391
389
  return new GraphQLInputObjectType({
392
390
  name: def.name.value,
393
391
  description: getDescription(def, this._options),
394
- fields: function fields() {
395
- return def.fields ? _this7._makeInputValues(def.fields) : {};
396
- },
392
+ fields: fields ? function () {
393
+ return keyByNameNode(fields, function (field) {
394
+ return _this7.buildInputField(field);
395
+ });
396
+ } : Object.create(null),
397
397
  astNode: def
398
398
  });
399
399
  };
400
400
 
401
401
  return ASTDefinitionBuilder;
402
402
  }();
403
+
404
+ function keyByNameNode(list, valFn) {
405
+ return keyValMap(list, function (_ref2) {
406
+ var name = _ref2.name;
407
+ return name.value;
408
+ }, valFn);
409
+ }
403
410
  /**
404
411
  * Given a field or enum value node, returns the string value for the
405
412
  * deprecation reason.
406
413
  */
407
414
 
415
+
408
416
  function getDeprecationReason(node) {
409
417
  var deprecated = getDirectiveValues(GraphQLDeprecatedDirective, node);
410
418
  return deprecated && deprecated.reason;
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.buildClientSchema = buildClientSchema;
7
7
 
8
+ var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
9
+
8
10
  var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
9
11
 
10
12
  var _keyMap = _interopRequireDefault(require("../jsutils/keyMap"));
@@ -33,7 +35,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
33
35
  * This source code is licensed under the MIT license found in the
34
36
  * LICENSE file in the root directory of this source tree.
35
37
  *
36
- * strict
38
+ *
37
39
  */
38
40
 
39
41
  /**
@@ -86,7 +88,7 @@ function buildClientSchema(introspection, options) {
86
88
  }
87
89
 
88
90
  if (!typeRef.name) {
89
- throw new Error('Unknown type reference: ' + JSON.stringify(typeRef));
91
+ throw new Error('Unknown type reference: ' + (0, _inspect.default)(typeRef));
90
92
  }
91
93
 
92
94
  return getNamedType(typeRef.name);
@@ -110,13 +112,13 @@ function buildClientSchema(introspection, options) {
110
112
 
111
113
  function getInputType(typeRef) {
112
114
  var type = getType(typeRef);
113
- !(0, _definition.isInputType)(type) ? (0, _invariant.default)(0, 'Introspection must provide input type for arguments.') : void 0;
115
+ !(0, _definition.isInputType)(type) ? (0, _invariant.default)(0, 'Introspection must provide input type for arguments, but received: ' + (0, _inspect.default)(type) + '.') : void 0;
114
116
  return type;
115
117
  }
116
118
 
117
119
  function getOutputType(typeRef) {
118
120
  var type = getType(typeRef);
119
- !(0, _definition.isOutputType)(type) ? (0, _invariant.default)(0, 'Introspection must provide output type for fields.') : void 0;
121
+ !(0, _definition.isOutputType)(type) ? (0, _invariant.default)(0, 'Introspection must provide output type for fields, but received: ' + (0, _inspect.default)(type) + '.') : void 0;
120
122
  return type;
121
123
  }
122
124
 
@@ -155,7 +157,7 @@ function buildClientSchema(introspection, options) {
155
157
  }
156
158
  }
157
159
 
158
- throw new Error('Invalid or incomplete introspection result. Ensure that a full ' + 'introspection query is used in order to build a client schema:' + JSON.stringify(type));
160
+ throw new Error('Invalid or incomplete introspection result. Ensure that a full ' + 'introspection query is used in order to build a client schema:' + (0, _inspect.default)(type));
159
161
  }
160
162
 
161
163
  function buildScalarDef(scalarIntrospection) {
@@ -170,13 +172,15 @@ function buildClientSchema(introspection, options) {
170
172
 
171
173
  function buildObjectDef(objectIntrospection) {
172
174
  if (!objectIntrospection.interfaces) {
173
- throw new Error('Introspection result missing interfaces: ' + JSON.stringify(objectIntrospection));
175
+ throw new Error('Introspection result missing interfaces: ' + (0, _inspect.default)(objectIntrospection));
174
176
  }
175
177
 
176
178
  return new _definition.GraphQLObjectType({
177
179
  name: objectIntrospection.name,
178
180
  description: objectIntrospection.description,
179
- interfaces: objectIntrospection.interfaces.map(getInterfaceType),
181
+ interfaces: function interfaces() {
182
+ return objectIntrospection.interfaces.map(getInterfaceType);
183
+ },
180
184
  fields: function fields() {
181
185
  return buildFieldDefMap(objectIntrospection);
182
186
  }
@@ -195,19 +199,21 @@ function buildClientSchema(introspection, options) {
195
199
 
196
200
  function buildUnionDef(unionIntrospection) {
197
201
  if (!unionIntrospection.possibleTypes) {
198
- throw new Error('Introspection result missing possibleTypes: ' + JSON.stringify(unionIntrospection));
202
+ throw new Error('Introspection result missing possibleTypes: ' + (0, _inspect.default)(unionIntrospection));
199
203
  }
200
204
 
201
205
  return new _definition.GraphQLUnionType({
202
206
  name: unionIntrospection.name,
203
207
  description: unionIntrospection.description,
204
- types: unionIntrospection.possibleTypes.map(getObjectType)
208
+ types: function types() {
209
+ return unionIntrospection.possibleTypes.map(getObjectType);
210
+ }
205
211
  });
206
212
  }
207
213
 
208
214
  function buildEnumDef(enumIntrospection) {
209
215
  if (!enumIntrospection.enumValues) {
210
- throw new Error('Introspection result missing enumValues: ' + JSON.stringify(enumIntrospection));
216
+ throw new Error('Introspection result missing enumValues: ' + (0, _inspect.default)(enumIntrospection));
211
217
  }
212
218
 
213
219
  return new _definition.GraphQLEnumType({
@@ -226,7 +232,7 @@ function buildClientSchema(introspection, options) {
226
232
 
227
233
  function buildInputObjectDef(inputObjectIntrospection) {
228
234
  if (!inputObjectIntrospection.inputFields) {
229
- throw new Error('Introspection result missing inputFields: ' + JSON.stringify(inputObjectIntrospection));
235
+ throw new Error('Introspection result missing inputFields: ' + (0, _inspect.default)(inputObjectIntrospection));
230
236
  }
231
237
 
232
238
  return new _definition.GraphQLInputObjectType({
@@ -240,14 +246,14 @@ function buildClientSchema(introspection, options) {
240
246
 
241
247
  function buildFieldDefMap(typeIntrospection) {
242
248
  if (!typeIntrospection.fields) {
243
- throw new Error('Introspection result missing fields: ' + JSON.stringify(typeIntrospection));
249
+ throw new Error('Introspection result missing fields: ' + (0, _inspect.default)(typeIntrospection));
244
250
  }
245
251
 
246
252
  return (0, _keyValMap.default)(typeIntrospection.fields, function (fieldIntrospection) {
247
253
  return fieldIntrospection.name;
248
254
  }, function (fieldIntrospection) {
249
255
  if (!fieldIntrospection.args) {
250
- throw new Error('Introspection result missing field args: ' + JSON.stringify(fieldIntrospection));
256
+ throw new Error('Introspection result missing field args: ' + (0, _inspect.default)(fieldIntrospection));
251
257
  }
252
258
 
253
259
  return {
@@ -277,7 +283,11 @@ function buildClientSchema(introspection, options) {
277
283
 
278
284
  function buildDirective(directiveIntrospection) {
279
285
  if (!directiveIntrospection.args) {
280
- throw new Error('Introspection result missing directive args: ' + JSON.stringify(directiveIntrospection));
286
+ throw new Error('Introspection result missing directive args: ' + (0, _inspect.default)(directiveIntrospection));
287
+ }
288
+
289
+ if (!directiveIntrospection.locations) {
290
+ throw new Error('Introspection result missing directive locations: ' + (0, _inspect.default)(directiveIntrospection));
281
291
  }
282
292
 
283
293
  return new _directives.GraphQLDirective({