graphql 17.0.0-beta.2 → 17.0.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 (262) hide show
  1. package/README.md +3 -5
  2. package/__dev__/diagnostics.d.mts +1 -0
  3. package/__dev__/diagnostics.d.ts +1 -0
  4. package/__dev__/diagnostics.js +3 -0
  5. package/__dev__/diagnostics.mjs +3 -0
  6. package/diagnostics.d.mts +307 -0
  7. package/diagnostics.d.ts +307 -0
  8. package/diagnostics.js +75 -0
  9. package/diagnostics.js.map +1 -0
  10. package/diagnostics.mjs +70 -0
  11. package/diagnostics.mjs.map +1 -0
  12. package/error/GraphQLError.d.mts +3 -1
  13. package/error/GraphQLError.d.ts +3 -1
  14. package/error/GraphQLError.js +3 -3
  15. package/error/GraphQLError.js.map +1 -1
  16. package/error/GraphQLError.mjs +3 -3
  17. package/error/GraphQLError.mjs.map +1 -1
  18. package/error/locatedError.d.mts +1 -3
  19. package/error/locatedError.d.ts +1 -3
  20. package/error/locatedError.js.map +1 -1
  21. package/error/locatedError.mjs.map +1 -1
  22. package/execution/ExecutionArgs.d.mts +6 -0
  23. package/execution/ExecutionArgs.d.ts +6 -0
  24. package/execution/ExecutionArgs.js.map +1 -1
  25. package/execution/ExecutionArgs.mjs.map +1 -1
  26. package/execution/Executor.d.mts +19 -1
  27. package/execution/Executor.d.ts +19 -1
  28. package/execution/Executor.js +49 -4
  29. package/execution/Executor.js.map +1 -1
  30. package/execution/Executor.mjs +49 -4
  31. package/execution/Executor.mjs.map +1 -1
  32. package/execution/execute.d.mts +65 -44
  33. package/execution/execute.d.ts +65 -44
  34. package/execution/execute.js +73 -4
  35. package/execution/execute.js.map +1 -1
  36. package/execution/execute.mjs +73 -4
  37. package/execution/execute.mjs.map +1 -1
  38. package/execution/values.d.mts +17 -17
  39. package/execution/values.d.ts +17 -17
  40. package/execution/values.js.map +1 -1
  41. package/execution/values.mjs.map +1 -1
  42. package/index.d.mts +1 -0
  43. package/index.d.ts +1 -0
  44. package/index.js.map +1 -1
  45. package/index.mjs.map +1 -1
  46. package/language/parser.d.mts +20 -30
  47. package/language/parser.d.ts +20 -30
  48. package/language/parser.js +9 -9
  49. package/language/parser.js.map +1 -1
  50. package/language/parser.mjs +9 -9
  51. package/language/parser.mjs.map +1 -1
  52. package/language/predicates.d.mts +5 -1
  53. package/language/predicates.d.ts +5 -1
  54. package/language/predicates.js.map +1 -1
  55. package/language/predicates.mjs.map +1 -1
  56. package/language/source.d.mts +4 -5
  57. package/language/source.d.ts +4 -5
  58. package/language/source.js.map +1 -1
  59. package/language/source.mjs.map +1 -1
  60. package/language/visitor.d.mts +10 -2
  61. package/language/visitor.d.ts +10 -2
  62. package/language/visitor.js.map +1 -1
  63. package/language/visitor.mjs.map +1 -1
  64. package/package.json +2 -2
  65. package/type/definition.d.mts +96 -64
  66. package/type/definition.d.ts +96 -64
  67. package/type/definition.js.map +1 -1
  68. package/type/definition.mjs.map +1 -1
  69. package/type/directives.d.mts +3 -3
  70. package/type/directives.d.ts +3 -3
  71. package/type/directives.js.map +1 -1
  72. package/type/directives.mjs.map +1 -1
  73. package/type/schema.d.mts +4 -8
  74. package/type/schema.d.ts +4 -8
  75. package/type/schema.js.map +1 -1
  76. package/type/schema.mjs.map +1 -1
  77. package/type/validate.js +101 -30
  78. package/type/validate.js.map +1 -1
  79. package/type/validate.mjs +101 -30
  80. package/type/validate.mjs.map +1 -1
  81. package/utilities/TypeInfo.d.mts +1 -1
  82. package/utilities/TypeInfo.d.ts +1 -1
  83. package/utilities/TypeInfo.js.map +1 -1
  84. package/utilities/TypeInfo.mjs.map +1 -1
  85. package/utilities/buildASTSchema.d.mts +0 -1
  86. package/utilities/buildASTSchema.d.ts +0 -1
  87. package/utilities/buildASTSchema.js +0 -1
  88. package/utilities/buildASTSchema.js.map +1 -1
  89. package/utilities/buildASTSchema.mjs +0 -1
  90. package/utilities/buildASTSchema.mjs.map +1 -1
  91. package/utilities/buildClientSchema.d.mts +5 -1
  92. package/utilities/buildClientSchema.d.ts +5 -1
  93. package/utilities/buildClientSchema.js.map +1 -1
  94. package/utilities/buildClientSchema.mjs.map +1 -1
  95. package/utilities/coerceInputValue.d.mts +7 -6
  96. package/utilities/coerceInputValue.d.ts +7 -6
  97. package/utilities/coerceInputValue.js.map +1 -1
  98. package/utilities/coerceInputValue.mjs.map +1 -1
  99. package/utilities/concatAST.d.mts +4 -1
  100. package/utilities/concatAST.d.ts +4 -1
  101. package/utilities/concatAST.js.map +1 -1
  102. package/utilities/concatAST.mjs.map +1 -1
  103. package/utilities/extendSchema.d.mts +3 -3
  104. package/utilities/extendSchema.d.ts +3 -3
  105. package/utilities/extendSchema.js +5 -1
  106. package/utilities/extendSchema.js.map +1 -1
  107. package/utilities/extendSchema.mjs +5 -1
  108. package/utilities/extendSchema.mjs.map +1 -1
  109. package/utilities/introspectionFromSchema.d.mts +6 -2
  110. package/utilities/introspectionFromSchema.d.ts +6 -2
  111. package/utilities/introspectionFromSchema.js.map +1 -1
  112. package/utilities/introspectionFromSchema.mjs.map +1 -1
  113. package/utilities/lexicographicSortSchema.d.mts +5 -1
  114. package/utilities/lexicographicSortSchema.d.ts +5 -1
  115. package/utilities/lexicographicSortSchema.js.map +1 -1
  116. package/utilities/lexicographicSortSchema.mjs.map +1 -1
  117. package/utilities/printSchema.d.mts +5 -1
  118. package/utilities/printSchema.d.ts +5 -1
  119. package/utilities/printSchema.js.map +1 -1
  120. package/utilities/printSchema.mjs.map +1 -1
  121. package/utilities/replaceVariables.d.mts +4 -8
  122. package/utilities/replaceVariables.d.ts +4 -8
  123. package/utilities/replaceVariables.js.map +1 -1
  124. package/utilities/replaceVariables.mjs.map +1 -1
  125. package/utilities/stripIgnoredCharacters.d.mts +2 -2
  126. package/utilities/stripIgnoredCharacters.d.ts +2 -2
  127. package/utilities/stripIgnoredCharacters.js.map +1 -1
  128. package/utilities/stripIgnoredCharacters.mjs.map +1 -1
  129. package/utilities/typeComparators.d.mts +1 -5
  130. package/utilities/typeComparators.d.ts +1 -5
  131. package/utilities/typeComparators.js.map +1 -1
  132. package/utilities/typeComparators.mjs.map +1 -1
  133. package/utilities/validateInputValue.d.mts +10 -8
  134. package/utilities/validateInputValue.d.ts +10 -8
  135. package/utilities/validateInputValue.js.map +1 -1
  136. package/utilities/validateInputValue.mjs.map +1 -1
  137. package/validation/rules/DeferStreamDirectiveOnRootFieldRule.d.mts +4 -1
  138. package/validation/rules/DeferStreamDirectiveOnRootFieldRule.d.ts +4 -1
  139. package/validation/rules/DeferStreamDirectiveOnRootFieldRule.js +70 -17
  140. package/validation/rules/DeferStreamDirectiveOnRootFieldRule.js.map +1 -1
  141. package/validation/rules/DeferStreamDirectiveOnRootFieldRule.mjs +70 -17
  142. package/validation/rules/DeferStreamDirectiveOnRootFieldRule.mjs.map +1 -1
  143. package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.d.mts +1 -1
  144. package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.d.ts +1 -1
  145. package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.js +90 -21
  146. package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.js.map +1 -1
  147. package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.mjs +91 -22
  148. package/validation/rules/DeferStreamDirectiveOnValidOperationsRule.mjs.map +1 -1
  149. package/validation/rules/ExecutableDefinitionsRule.d.mts +6 -2
  150. package/validation/rules/ExecutableDefinitionsRule.d.ts +6 -2
  151. package/validation/rules/ExecutableDefinitionsRule.js.map +1 -1
  152. package/validation/rules/ExecutableDefinitionsRule.mjs.map +1 -1
  153. package/validation/rules/FieldsOnCorrectTypeRule.d.mts +3 -1
  154. package/validation/rules/FieldsOnCorrectTypeRule.d.ts +3 -1
  155. package/validation/rules/FieldsOnCorrectTypeRule.js.map +1 -1
  156. package/validation/rules/FieldsOnCorrectTypeRule.mjs.map +1 -1
  157. package/validation/rules/FragmentsOnCompositeTypesRule.d.mts +6 -2
  158. package/validation/rules/FragmentsOnCompositeTypesRule.d.ts +6 -2
  159. package/validation/rules/FragmentsOnCompositeTypesRule.js.map +1 -1
  160. package/validation/rules/FragmentsOnCompositeTypesRule.mjs.map +1 -1
  161. package/validation/rules/KnownArgumentNamesRule.d.mts +3 -1
  162. package/validation/rules/KnownArgumentNamesRule.d.ts +3 -1
  163. package/validation/rules/KnownArgumentNamesRule.js.map +1 -1
  164. package/validation/rules/KnownArgumentNamesRule.mjs.map +1 -1
  165. package/validation/rules/KnownDirectivesRule.js +2 -1
  166. package/validation/rules/KnownDirectivesRule.js.map +1 -1
  167. package/validation/rules/KnownDirectivesRule.mjs +2 -1
  168. package/validation/rules/KnownDirectivesRule.mjs.map +1 -1
  169. package/validation/rules/KnownFragmentNamesRule.d.mts +3 -1
  170. package/validation/rules/KnownFragmentNamesRule.d.ts +3 -1
  171. package/validation/rules/KnownFragmentNamesRule.js.map +1 -1
  172. package/validation/rules/KnownFragmentNamesRule.mjs.map +1 -1
  173. package/validation/rules/LoneAnonymousOperationRule.d.mts +6 -2
  174. package/validation/rules/LoneAnonymousOperationRule.d.ts +6 -2
  175. package/validation/rules/LoneAnonymousOperationRule.js.map +1 -1
  176. package/validation/rules/LoneAnonymousOperationRule.mjs.map +1 -1
  177. package/validation/rules/MaxIntrospectionDepthRule.d.mts +6 -2
  178. package/validation/rules/MaxIntrospectionDepthRule.d.ts +6 -2
  179. package/validation/rules/MaxIntrospectionDepthRule.js.map +1 -1
  180. package/validation/rules/MaxIntrospectionDepthRule.mjs.map +1 -1
  181. package/validation/rules/NoUndefinedVariablesRule.d.mts +3 -1
  182. package/validation/rules/NoUndefinedVariablesRule.d.ts +3 -1
  183. package/validation/rules/NoUndefinedVariablesRule.js.map +1 -1
  184. package/validation/rules/NoUndefinedVariablesRule.mjs.map +1 -1
  185. package/validation/rules/NoUnusedFragmentsRule.d.mts +3 -1
  186. package/validation/rules/NoUnusedFragmentsRule.d.ts +3 -1
  187. package/validation/rules/NoUnusedFragmentsRule.js.map +1 -1
  188. package/validation/rules/NoUnusedFragmentsRule.mjs.map +1 -1
  189. package/validation/rules/NoUnusedVariablesRule.d.mts +3 -1
  190. package/validation/rules/NoUnusedVariablesRule.d.ts +3 -1
  191. package/validation/rules/NoUnusedVariablesRule.js.map +1 -1
  192. package/validation/rules/NoUnusedVariablesRule.mjs.map +1 -1
  193. package/validation/rules/OverlappingFieldsCanBeMergedRule.d.mts +6 -2
  194. package/validation/rules/OverlappingFieldsCanBeMergedRule.d.ts +6 -2
  195. package/validation/rules/OverlappingFieldsCanBeMergedRule.js.map +1 -1
  196. package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs.map +1 -1
  197. package/validation/rules/PossibleFragmentSpreadsRule.d.mts +6 -2
  198. package/validation/rules/PossibleFragmentSpreadsRule.d.ts +6 -2
  199. package/validation/rules/PossibleFragmentSpreadsRule.js.map +1 -1
  200. package/validation/rules/PossibleFragmentSpreadsRule.mjs.map +1 -1
  201. package/validation/rules/ProvidedRequiredArgumentsRule.d.mts +6 -2
  202. package/validation/rules/ProvidedRequiredArgumentsRule.d.ts +6 -2
  203. package/validation/rules/ProvidedRequiredArgumentsRule.js.map +1 -1
  204. package/validation/rules/ProvidedRequiredArgumentsRule.mjs.map +1 -1
  205. package/validation/rules/SingleFieldSubscriptionsRule.d.mts +6 -2
  206. package/validation/rules/SingleFieldSubscriptionsRule.d.ts +6 -2
  207. package/validation/rules/SingleFieldSubscriptionsRule.js.map +1 -1
  208. package/validation/rules/SingleFieldSubscriptionsRule.mjs.map +1 -1
  209. package/validation/rules/UniqueArgumentNamesRule.d.mts +3 -1
  210. package/validation/rules/UniqueArgumentNamesRule.d.ts +3 -1
  211. package/validation/rules/UniqueArgumentNamesRule.js.map +1 -1
  212. package/validation/rules/UniqueArgumentNamesRule.mjs.map +1 -1
  213. package/validation/rules/UniqueDirectivesPerLocationRule.d.mts +6 -2
  214. package/validation/rules/UniqueDirectivesPerLocationRule.d.ts +6 -2
  215. package/validation/rules/UniqueDirectivesPerLocationRule.js.map +1 -1
  216. package/validation/rules/UniqueDirectivesPerLocationRule.mjs.map +1 -1
  217. package/validation/rules/UniqueFragmentNamesRule.d.mts +3 -1
  218. package/validation/rules/UniqueFragmentNamesRule.d.ts +3 -1
  219. package/validation/rules/UniqueFragmentNamesRule.js.map +1 -1
  220. package/validation/rules/UniqueFragmentNamesRule.mjs.map +1 -1
  221. package/validation/rules/UniqueInputFieldNamesRule.d.mts +6 -2
  222. package/validation/rules/UniqueInputFieldNamesRule.d.ts +6 -2
  223. package/validation/rules/UniqueInputFieldNamesRule.js.map +1 -1
  224. package/validation/rules/UniqueInputFieldNamesRule.mjs.map +1 -1
  225. package/validation/rules/UniqueOperationNamesRule.d.mts +3 -1
  226. package/validation/rules/UniqueOperationNamesRule.d.ts +3 -1
  227. package/validation/rules/UniqueOperationNamesRule.js.map +1 -1
  228. package/validation/rules/UniqueOperationNamesRule.mjs.map +1 -1
  229. package/validation/rules/UniqueVariableNamesRule.d.mts +3 -1
  230. package/validation/rules/UniqueVariableNamesRule.d.ts +3 -1
  231. package/validation/rules/UniqueVariableNamesRule.js.map +1 -1
  232. package/validation/rules/UniqueVariableNamesRule.mjs.map +1 -1
  233. package/validation/rules/ValuesOfCorrectTypeRule.d.mts +3 -1
  234. package/validation/rules/ValuesOfCorrectTypeRule.d.ts +3 -1
  235. package/validation/rules/ValuesOfCorrectTypeRule.js.map +1 -1
  236. package/validation/rules/ValuesOfCorrectTypeRule.mjs.map +1 -1
  237. package/validation/rules/VariablesAreInputTypesRule.d.mts +6 -2
  238. package/validation/rules/VariablesAreInputTypesRule.d.ts +6 -2
  239. package/validation/rules/VariablesAreInputTypesRule.js.map +1 -1
  240. package/validation/rules/VariablesAreInputTypesRule.mjs.map +1 -1
  241. package/validation/rules/VariablesInAllowedPositionRule.d.mts +6 -2
  242. package/validation/rules/VariablesInAllowedPositionRule.d.ts +6 -2
  243. package/validation/rules/VariablesInAllowedPositionRule.js.map +1 -1
  244. package/validation/rules/VariablesInAllowedPositionRule.mjs.map +1 -1
  245. package/validation/rules/custom/NoDeprecatedCustomRule.d.mts +3 -1
  246. package/validation/rules/custom/NoDeprecatedCustomRule.d.ts +3 -1
  247. package/validation/rules/custom/NoDeprecatedCustomRule.js.map +1 -1
  248. package/validation/rules/custom/NoDeprecatedCustomRule.mjs.map +1 -1
  249. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.mts +6 -2
  250. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.d.ts +6 -2
  251. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.js.map +1 -1
  252. package/validation/rules/custom/NoSchemaIntrospectionCustomRule.mjs.map +1 -1
  253. package/validation/validate.d.mts +3 -6
  254. package/validation/validate.d.ts +3 -6
  255. package/validation/validate.js +6 -0
  256. package/validation/validate.js.map +1 -1
  257. package/validation/validate.mjs +6 -0
  258. package/validation/validate.mjs.map +1 -1
  259. package/version.js +2 -2
  260. package/version.js.map +1 -1
  261. package/version.mjs +2 -2
  262. package/version.mjs.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"validateInputValue.js","sourceRoot":"","sources":["../../src/utilities/validateInputValue.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,kCAAiC;AACtD,OAAO,EAAE,OAAO,EAAE,+BAA8B;AAChD,OAAO,EAAE,gBAAgB,EAAE,wCAAuC;AAClE,OAAO,EAAE,YAAY,EAAE,oCAAmC;AAC1D,OAAO,EAAE,MAAM,EAAE,8BAA6B;AAG9C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,4BAA2B;AAC1D,OAAO,EAAE,cAAc,EAAE,sCAAqC;AAE9D,OAAO,EAAE,kBAAkB,EAAE,wCAAuC;AACpE,OAAO,EAAE,YAAY,EAAE,kCAAiC;AAGxD,OAAO,EAAE,IAAI,EAAE,8BAA6B;AAC5C,OAAO,EAAE,KAAK,EAAE,gCAA+B;AAG/C,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,oBAAoB,GACr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,CAAC,YAAY,CAAC;QAClD,CAAC,CAAC,sBAAsB;QACxB,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,SAAS,oBAAoB,CAC3B,OAA4E,EAC5E,OAAe,EACf,SAAkB,EAClB,IAAsB,EACtB,aAA4B;IAE5B,OAAO,CACL,IAAI,YAAY,CAAC,OAAO,EAAE;QACxB,KAAK,EAAE,SAAS;QAChB,aAAa;KACd,CAAC,EACF,WAAW,CAAC,IAAI,CAAC,CAClB,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAAC,WAAoB;IACjD,IAAI,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC;QACpC,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;YAClD,OAAO,OAAO,CAAC;QACjB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,+BAA+B,CAAC,IAAsB;IAC7D,OAAO,mCAAmC,IAAI,wFAAwF,CAAC;AACzI,CAAC","sourcesContent":["/** @category Values */\n\nimport { didYouMean } from '../jsutils/didYouMean.ts';\nimport { inspect } from '../jsutils/inspect.ts';\nimport { isIterableObject } from '../jsutils/isIterableObject.ts';\nimport { isObjectLike } from '../jsutils/isObjectLike.ts';\nimport { keyMap } from '../jsutils/keyMap.ts';\nimport type { Maybe } from '../jsutils/Maybe.ts';\nimport type { Path } from '../jsutils/Path.ts';\nimport { addPath, pathToArray } from '../jsutils/Path.ts';\nimport { suggestionList } from '../jsutils/suggestionList.ts';\n\nimport { ensureGraphQLError } from '../error/ensureGraphQLError.ts';\nimport { GraphQLError } from '../error/GraphQLError.ts';\n\nimport type { ASTNode, ValueNode, VariableNode } from '../language/ast.ts';\nimport { Kind } from '../language/kinds.ts';\nimport { print } from '../language/printer.ts';\n\nimport type { GraphQLInputType } from '../type/definition.ts';\nimport {\n assertLeafType,\n isInputObjectType,\n isListType,\n isNonNullType,\n isRequiredInputField,\n} from '../type/definition.ts';\n\nimport type { FragmentVariableValues } from '../execution/collectFields.ts';\nimport type { VariableValues } from '../execution/values.ts';\n\nimport { replaceVariables } from './replaceVariables.ts';\n\n/**\n * Validate that the provided input value is allowed for this type, collecting\n * all errors via a callback function.\n * @param inputValue - JavaScript value to validate.\n * @param type - GraphQL input type to validate the value against.\n * @param onError - Callback invoked for each validation error and path.\n * @param hideSuggestions - Whether suggestion text should be omitted from errors.\n * @returns Nothing.\n * @example\n * ```ts\n * // Collect validation errors with their input paths.\n * import {\n * GraphQLInputObjectType,\n * GraphQLInt,\n * GraphQLNonNull,\n * } from 'graphql/type';\n * import { validateInputValue } from 'graphql/utilities';\n *\n * const ReviewInput = new GraphQLInputObjectType({\n * name: 'ReviewInput',\n * fields: {\n * stars: { type: new GraphQLNonNull(GraphQLInt) },\n * },\n * });\n * const errors = [];\n *\n * validateInputValue({ stars: 'bad' }, ReviewInput, (error, path) => {\n * errors.push({ message: error.message, path });\n * });\n *\n * errors; // => [ { message: 'Expected value of type \"Int\", found: \"bad\".', path: ['stars'] } ]\n * ```\n * @example\n * ```ts\n * // This variant hides suggestion text for unknown input fields.\n * import { GraphQLInputObjectType, GraphQLString } from 'graphql/type';\n * import { validateInputValue } from 'graphql/utilities';\n *\n * const ReviewInput = new GraphQLInputObjectType({\n * name: 'ReviewInput',\n * fields: {\n * comment: { type: GraphQLString },\n * },\n * });\n * const errors = [];\n *\n * validateInputValue(\n * { rating: 'extra field' },\n * ReviewInput,\n * (error) => {\n * errors.push(error.message);\n * },\n * true,\n * );\n *\n * errors; // => ['Expected value of type \"ReviewInput\" not to include unknown field \"rating\", found: { rating: \"extra field\" }.']\n * ```\n */\nexport function validateInputValue(\n inputValue: unknown,\n type: GraphQLInputType,\n onError: (error: GraphQLError, path: ReadonlyArray<string | number>) => void,\n hideSuggestions?: Maybe<boolean>,\n): void {\n return validateInputValueImpl(\n inputValue,\n type,\n onError,\n hideSuggestions,\n undefined,\n );\n}\n\nfunction validateInputValueImpl(\n inputValue: unknown,\n type: GraphQLInputType,\n onError: (error: GraphQLError, path: ReadonlyArray<string | number>) => void,\n hideSuggestions: Maybe<boolean>,\n path: Path | undefined,\n): void {\n if (isNonNullType(type)) {\n if (inputValue === undefined) {\n reportInvalidValue(\n onError,\n `Expected a value of non-null type \"${type}\" to be provided.`,\n path,\n );\n return;\n }\n if (inputValue === null) {\n reportInvalidValue(\n onError,\n `Expected value of non-null type \"${type}\" not to be null.`,\n path,\n );\n return;\n }\n return validateInputValueImpl(\n inputValue,\n type.ofType,\n onError,\n hideSuggestions,\n path,\n );\n }\n\n if (inputValue == null) {\n return;\n }\n\n if (isListType(type)) {\n if (!isIterableObject(inputValue)) {\n // Lists accept a non-list value as a list of one.\n validateInputValueImpl(\n inputValue,\n type.ofType,\n onError,\n hideSuggestions,\n path,\n );\n } else {\n let index = 0;\n for (const itemValue of inputValue) {\n validateInputValueImpl(\n itemValue,\n type.ofType,\n onError,\n hideSuggestions,\n addPath(path, index++, undefined),\n );\n }\n }\n } else if (isInputObjectType(type)) {\n if (!isObjectLike(inputValue) || Array.isArray(inputValue)) {\n reportInvalidValue(\n onError,\n `Expected value of type \"${type}\" to be an object, found: ${inspect(\n inputValue,\n )}.`,\n path,\n );\n return;\n }\n\n const fieldDefs = type.getFields();\n\n for (const field of Object.values(fieldDefs)) {\n const fieldValue = inputValue[field.name];\n if (fieldValue === undefined) {\n if (isRequiredInputField(field)) {\n reportInvalidValue(\n onError,\n `Expected value of type \"${type}\" to include required field \"${\n field.name\n }\", found: ${inspect(inputValue)}.`,\n path,\n );\n }\n } else {\n validateInputValueImpl(\n fieldValue,\n field.type,\n onError,\n hideSuggestions,\n addPath(path, field.name, type.name),\n );\n }\n }\n\n const fields: Array<string> = [];\n // Ensure every provided field is defined.\n for (const fieldName of Object.keys(inputValue)) {\n if (inputValue[fieldName] === undefined) {\n continue;\n }\n if (!Object.hasOwn(fieldDefs, fieldName)) {\n const suggestion = hideSuggestions\n ? ''\n : didYouMean(suggestionList(fieldName, Object.keys(fieldDefs)));\n reportInvalidValue(\n onError,\n `Expected value of type \"${type}\" not to include unknown field \"${fieldName}\"${\n suggestion ? `.${suggestion} Found` : ', found'\n }: ${inspect(inputValue)}.`,\n path,\n );\n continue;\n }\n fields.push(fieldName);\n }\n\n if (type.isOneOf) {\n if (fields.length !== 1) {\n reportInvalidValue(\n onError,\n getOneOfInputObjectErrorMessage(type),\n path,\n );\n }\n\n const field = fields[0];\n const value = inputValue[field];\n if (value === null) {\n reportInvalidValue(\n onError,\n getOneOfInputObjectErrorMessage(type),\n addPath(path, field, type.name),\n );\n }\n }\n } else {\n assertLeafType(type);\n\n let result;\n let caughtError: unknown;\n\n try {\n result = type.coerceInputValue(inputValue, hideSuggestions);\n } catch (error) {\n if (error instanceof GraphQLError) {\n onError(error, pathToArray(path));\n return;\n }\n caughtError = error;\n }\n\n if (result === undefined) {\n reportInvalidValue(\n onError,\n `Expected value of type \"${type}\"${\n caughtError != null\n ? `, but encountered error \"${getCaughtErrorMessage(caughtError)}\"; found`\n : ', found'\n }: ${inspect(inputValue)}.`,\n path,\n ensureGraphQLError(caughtError),\n );\n }\n }\n}\n\nfunction reportInvalidValue(\n onError: (error: GraphQLError, path: ReadonlyArray<string | number>) => void,\n message: string,\n path: Path | undefined,\n originalError?: GraphQLError,\n): void {\n onError(new GraphQLError(message, { originalError }), pathToArray(path));\n}\n\n/**\n * Validate that the provided input literal is allowed for this type, collecting\n * all errors via a callback function.\n *\n * If variable values are not provided, the literal is validated statically\n * (not assuming that those variables are missing runtime values).\n * @param valueNode - GraphQL value AST node to validate.\n * @param type - GraphQL input type to validate the literal against.\n * @param onError - Callback invoked for each validation error and path.\n * @param variables - Operation variable values returned by getVariableValues.\n * @param fragmentVariableValues - Fragment variable values for the current fragment scope.\n * @param hideSuggestions - Whether suggestion text should be omitted from errors.\n * @returns Nothing.\n * @example\n * ```ts\n * // Validate literal input values and collect literal paths.\n * import { parseValue } from 'graphql/language';\n * import {\n * GraphQLInputObjectType,\n * GraphQLInt,\n * GraphQLNonNull,\n * } from 'graphql/type';\n * import { validateInputLiteral } from 'graphql/utilities';\n *\n * const ReviewInput = new GraphQLInputObjectType({\n * name: 'ReviewInput',\n * fields: {\n * stars: { type: new GraphQLNonNull(GraphQLInt) },\n * },\n * });\n * const errors = [];\n *\n * validateInputLiteral(parseValue('{ stars: \"bad\" }'), ReviewInput, (error, path) => {\n * errors.push({ message: error.message, path });\n * });\n *\n * errors; // => [ { message: 'Expected value of type \"Int\", found: \"bad\".', path: ['stars'] } ]\n * ```\n * @example\n * ```ts\n * // This variant resolves variable references using VariableValues from getVariableValues().\n * import assert from 'node:assert';\n * import { parse, parseValue } from 'graphql/language';\n * import { GraphQLInt } from 'graphql/type';\n * import { getVariableValues } from 'graphql/execution';\n * import { buildSchema, validateInputLiteral } from 'graphql/utilities';\n *\n * const schema = buildSchema(`\n * type Query {\n * review(stars: Int): String\n * }\n * `);\n * const document = parse('query ($stars: Int = 5) { review(stars: $stars) }');\n * const operation = document.definitions[0];\n * const result = getVariableValues(\n * schema,\n * operation.variableDefinitions,\n * { stars: '4' },\n * );\n *\n * assert('variableValues' in result);\n *\n * const errors = [];\n * validateInputLiteral(\n * parseValue('$stars'),\n * GraphQLInt,\n * (error) => errors.push(error.message),\n * result.variableValues,\n * undefined,\n * true,\n * );\n *\n * errors; // => []\n * ```\n */\n// eslint-disable-next-line max-params\nexport function validateInputLiteral(\n valueNode: ValueNode,\n type: GraphQLInputType,\n onError: (error: GraphQLError, path: ReadonlyArray<string | number>) => void,\n variables?: Maybe<VariableValues>,\n fragmentVariableValues?: Maybe<FragmentVariableValues>,\n hideSuggestions?: Maybe<boolean>,\n): void {\n const context: ValidationContext = {\n static: !variables && !fragmentVariableValues,\n onError,\n variables,\n fragmentVariableValues,\n };\n return validateInputLiteralImpl(\n context,\n valueNode,\n type,\n hideSuggestions,\n undefined,\n );\n}\n\ninterface ValidationContext {\n static: boolean;\n onError: (error: GraphQLError, path: ReadonlyArray<string | number>) => void;\n variables?: Maybe<VariableValues>;\n fragmentVariableValues?: Maybe<FragmentVariableValues>;\n}\n\nfunction validateInputLiteralImpl(\n context: ValidationContext,\n valueNode: ValueNode,\n type: GraphQLInputType,\n hideSuggestions: Maybe<boolean>,\n path: Path | undefined,\n): void {\n if (valueNode.kind === Kind.VARIABLE) {\n if (context.static) {\n // If no variable values are provided, this is being validated statically,\n // and cannot yet produce any validation errors for variables.\n return;\n }\n const scopedVariableValues = getScopedVariableValues(context, valueNode);\n const value = scopedVariableValues?.coerced[valueNode.name.value];\n if (isNonNullType(type)) {\n if (value === undefined) {\n reportInvalidLiteral(\n context.onError,\n `Expected variable \"$${valueNode.name.value}\" provided to type \"${type}\" to provide a runtime value.`,\n valueNode,\n path,\n );\n } else if (value === null) {\n reportInvalidLiteral(\n context.onError,\n `Expected variable \"$${valueNode.name.value}\" provided to non-null type \"${type}\" not to be null.`,\n valueNode,\n path,\n );\n }\n }\n // Note: This does no further checking that this variable is correct.\n // This assumes this variable usage has already been validated.\n return;\n }\n\n if (isNonNullType(type)) {\n if (valueNode.kind === Kind.NULL) {\n reportInvalidLiteral(\n context.onError,\n `Expected value of non-null type \"${type}\" not to be null.`,\n valueNode,\n path,\n );\n return;\n }\n return validateInputLiteralImpl(\n context,\n valueNode,\n type.ofType,\n hideSuggestions,\n path,\n );\n }\n\n if (valueNode.kind === Kind.NULL) {\n return;\n }\n\n if (isListType(type)) {\n if (valueNode.kind !== Kind.LIST) {\n // Lists accept a non-list value as a list of one.\n validateInputLiteralImpl(\n context,\n valueNode,\n type.ofType,\n hideSuggestions,\n path,\n );\n } else {\n let index = 0;\n for (const itemNode of valueNode.values) {\n validateInputLiteralImpl(\n context,\n itemNode,\n type.ofType,\n hideSuggestions,\n addPath(path, index++, undefined),\n );\n }\n }\n } else if (isInputObjectType(type)) {\n if (valueNode.kind !== Kind.OBJECT) {\n reportInvalidLiteral(\n context.onError,\n `Expected value of type \"${type}\" to be an object, found: ${print(\n valueNode,\n )}.`,\n valueNode,\n path,\n );\n return;\n }\n\n const fieldDefs = type.getFields();\n const fieldNodes = keyMap(valueNode.fields, (field) => field.name.value);\n\n for (const field of Object.values(fieldDefs)) {\n const fieldNode = fieldNodes[field.name];\n if (fieldNode === undefined) {\n if (isRequiredInputField(field)) {\n reportInvalidLiteral(\n context.onError,\n `Expected value of type \"${type}\" to include required field \"${\n field.name\n }\", found: ${print(valueNode)}.`,\n valueNode,\n path,\n );\n }\n } else {\n const fieldValueNode = fieldNode.value;\n if (fieldValueNode.kind === Kind.VARIABLE && !context.static) {\n const scopedVariableValues = getScopedVariableValues(\n context,\n fieldValueNode,\n );\n const variableName = fieldValueNode.name.value;\n const value = scopedVariableValues?.coerced[variableName];\n if (type.isOneOf) {\n if (value === undefined) {\n reportInvalidLiteral(\n context.onError,\n `Expected variable \"$${variableName}\" provided to field \"${field.name}\" for OneOf Input Object type \"${type}\" to provide a runtime value.`,\n valueNode,\n path,\n );\n } else if (value === null) {\n reportInvalidLiteral(\n context.onError,\n `Expected variable \"$${variableName}\" provided to field \"${field.name}\" for OneOf Input Object type \"${type}\" not to be null.`,\n valueNode,\n path,\n );\n }\n } else if (value === undefined && !isRequiredInputField(field)) {\n continue;\n }\n }\n\n validateInputLiteralImpl(\n context,\n fieldValueNode,\n field.type,\n hideSuggestions,\n addPath(path, field.name, type.name),\n );\n }\n }\n\n const fields = valueNode.fields;\n const knownFields: Array<(typeof fields)[number]> = [];\n // Ensure every provided field is defined.\n for (const fieldNode of fields) {\n const fieldName = fieldNode.name.value;\n if (!Object.hasOwn(fieldDefs, fieldName)) {\n const suggestion = hideSuggestions\n ? ''\n : didYouMean(suggestionList(fieldName, Object.keys(fieldDefs)));\n reportInvalidLiteral(\n context.onError,\n `Expected value of type \"${type}\" not to include unknown field \"${fieldName}\"${\n suggestion ? `.${suggestion} Found` : ', found'\n }: ${print(valueNode)}.`,\n fieldNode,\n path,\n );\n } else {\n knownFields.push(fieldNode);\n }\n }\n\n if (type.isOneOf) {\n const isNotExactlyOneField = knownFields.length !== 1;\n if (isNotExactlyOneField) {\n reportInvalidLiteral(\n context.onError,\n getOneOfInputObjectErrorMessage(type),\n valueNode,\n path,\n );\n return;\n }\n\n const fieldValueNode = knownFields[0].value;\n if (fieldValueNode.kind === Kind.NULL) {\n const fieldName = knownFields[0].name.value;\n reportInvalidLiteral(\n context.onError,\n getOneOfInputObjectErrorMessage(type),\n valueNode,\n addPath(path, fieldName, undefined),\n );\n }\n }\n } else {\n assertLeafType(type);\n\n let result;\n let caughtError: unknown;\n try {\n result = type.coerceInputLiteral\n ? type.coerceInputLiteral(\n replaceVariables(\n valueNode,\n context.variables,\n context.fragmentVariableValues,\n ),\n hideSuggestions,\n )\n : type.parseLiteral(valueNode, undefined, hideSuggestions);\n } catch (error) {\n if (error instanceof GraphQLError) {\n context.onError(error, pathToArray(path));\n return;\n }\n caughtError = error;\n }\n\n if (result === undefined) {\n reportInvalidLiteral(\n context.onError,\n `Expected value of type \"${type}\"${\n caughtError != null\n ? `, but encountered error \"${getCaughtErrorMessage(caughtError)}\"; found`\n : ', found'\n }: ${print(valueNode)}.`,\n valueNode,\n path,\n ensureGraphQLError(caughtError),\n );\n }\n }\n}\n\nfunction getScopedVariableValues(\n context: ValidationContext,\n valueNode: VariableNode,\n): Maybe<VariableValues> {\n const variableName = valueNode.name.value;\n const { fragmentVariableValues, variables } = context;\n return fragmentVariableValues?.sources[variableName]\n ? fragmentVariableValues\n : variables;\n}\n\nfunction reportInvalidLiteral(\n onError: (error: GraphQLError, path: ReadonlyArray<string | number>) => void,\n message: string,\n valueNode: ASTNode,\n path: Path | undefined,\n originalError?: GraphQLError,\n): void {\n onError(\n new GraphQLError(message, {\n nodes: valueNode,\n originalError,\n }),\n pathToArray(path),\n );\n}\n\nfunction getCaughtErrorMessage(caughtError: unknown): string {\n if (isObjectLike(caughtError)) {\n const message = caughtError.message;\n if (typeof message === 'string' && message !== '') {\n return message;\n }\n }\n\n return String(caughtError);\n}\n\nfunction getOneOfInputObjectErrorMessage(type: GraphQLInputType): string {\n return `Within OneOf Input Object type \"${type}\", exactly one field must be specified, and the value for that field must be non-null.`;\n}\n"]}
1
+ {"version":3,"file":"validateInputValue.js","sourceRoot":"","sources":["../../src/utilities/validateInputValue.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,kCAAiC;AACtD,OAAO,EAAE,OAAO,EAAE,+BAA8B;AAChD,OAAO,EAAE,gBAAgB,EAAE,wCAAuC;AAClE,OAAO,EAAE,YAAY,EAAE,oCAAmC;AAC1D,OAAO,EAAE,MAAM,EAAE,8BAA6B;AAG9C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,4BAA2B;AAC1D,OAAO,EAAE,cAAc,EAAE,sCAAqC;AAE9D,OAAO,EAAE,kBAAkB,EAAE,wCAAuC;AACpE,OAAO,EAAE,YAAY,EAAE,kCAAiC;AAGxD,OAAO,EAAE,IAAI,EAAE,8BAA6B;AAC5C,OAAO,EAAE,KAAK,EAAE,gCAA+B;AAG/C,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,oBAAoB,GACrB,+BAA8B;AAK/B,OAAO,EAAE,gBAAgB,EAAE,+BAA8B;AA4DzD,MAAM,UAAU,kBAAkB,CAChC,UAAmB,EACnB,IAAsB,EACtB,OAA4E,EAC5E,eAAgC;IAEhC,OAAO,sBAAsB,CAC3B,UAAU,EACV,IAAI,EACJ,OAAO,EACP,eAAe,EACf,SAAS,CACV,CAAC;AACJ,CAAC;AAED,SAAS,sBAAsB,CAC7B,UAAmB,EACnB,IAAsB,EACtB,OAA4E,EAC5E,eAA+B,EAC/B,IAAsB;IAEtB,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,kBAAkB,CAChB,OAAO,EACP,sCAAsC,IAAI,mBAAmB,EA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AAK,QAAQ,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;YAClD,OAAO,OAAO,CAAC;QACjB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,+BAA+B,CAAC,IAAsB;IAC7D,OAAO,mCAAmC,IAAI,wFAAwF,CAAC;AACzI,CAAC","sourcesContent":["/** @category Values */\n\nimport { didYouMean } from '../jsutils/didYouMean.ts';\nimport { inspect } from '../jsutils/inspect.ts';\nimport { isIterableObject } from '../jsutils/isIterableObject.ts';\nimport { isObjectLike } from '../jsutils/isObjectLike.ts';\nimport { keyMap } from '../jsutils/keyMap.ts';\nimport type { Maybe } from '../jsutils/Maybe.ts';\nimport type { Path } from '../jsutils/Path.ts';\nimport { addPath, pathToArray } from '../jsutils/Path.ts';\nimport { suggestionList } from '../jsutils/suggestionList.ts';\n\nimport { ensureGraphQLError } from '../error/ensureGraphQLError.ts';\nimport { GraphQLError } from '../error/GraphQLError.ts';\n\nimport type { ASTNode, ValueNode, VariableNode } from '../language/ast.ts';\nimport { Kind } from '../language/kinds.ts';\nimport { print } from '../language/printer.ts';\n\nimport type { GraphQLInputType } from '../type/definition.ts';\nimport {\n assertLeafType,\n isInputObjectType,\n isListType,\n isNonNullType,\n isRequiredInputField,\n} from '../type/definition.ts';\n\nimport type { FragmentVariableValues } from '../execution/collectFields.ts';\nimport type { VariableValues } from '../execution/values.ts';\n\nimport { replaceVariables } from './replaceVariables.ts';\n\n/**\n * Validate that the provided input value is allowed for this type, collecting\n * all errors via a callback function.\n * @param inputValue - JavaScript value to validate.\n * @param type - GraphQL input type to validate the value against.\n * @param onError - Callback invoked for each validation error and path.\n * @param hideSuggestions - Whether suggestion text should be omitted from errors.\n * @returns Nothing.\n * @example\n * ```ts\n * // Collect validation errors with their input paths.\n * import {\n * GraphQLInputObjectType,\n * GraphQLInt,\n * GraphQLNonNull,\n * } from 'graphql/type';\n * import { validateInputValue } from 'graphql/utilities';\n *\n * const ReviewInput = new GraphQLInputObjectType({\n * name: 'ReviewInput',\n * fields: {\n * stars: { type: new GraphQLNonNull(GraphQLInt) },\n * },\n * });\n * const errors = [];\n *\n * validateInputValue({ stars: 'bad' }, ReviewInput, (error, path) => {\n * errors.push({ message: error.message, path });\n * });\n *\n * errors; // => [ { message: 'Expected value of type \"Int\", found: \"bad\".', path: ['stars'] } ]\n * ```\n * @example\n * ```ts\n * // This variant hides suggestion text for unknown input fields.\n * import { GraphQLInputObjectType, GraphQLString } from 'graphql/type';\n * import { validateInputValue } from 'graphql/utilities';\n *\n * const ReviewInput = new GraphQLInputObjectType({\n * name: 'ReviewInput',\n * fields: {\n * comment: { type: GraphQLString },\n * },\n * });\n * const errors = [];\n *\n * validateInputValue(\n * { rating: 'extra field' },\n * ReviewInput,\n * (error) => {\n * errors.push(error.message);\n * },\n * true,\n * );\n *\n * errors; // => ['Expected value of type \"ReviewInput\" not to include unknown field \"rating\", found: { rating: \"extra field\" }.']\n * ```\n */\nexport function validateInputValue(\n inputValue: unknown,\n type: GraphQLInputType,\n onError: (error: GraphQLError, path: ReadonlyArray<string | number>) => void,\n hideSuggestions?: Maybe<boolean>,\n): void {\n return validateInputValueImpl(\n inputValue,\n type,\n onError,\n hideSuggestions,\n undefined,\n );\n}\n\nfunction validateInputValueImpl(\n inputValue: unknown,\n type: GraphQLInputType,\n onError: (error: GraphQLError, path: ReadonlyArray<string | number>) => void,\n hideSuggestions: Maybe<boolean>,\n path: Path | undefined,\n): void {\n if (isNonNullType(type)) {\n if (inputValue === undefined) {\n reportInvalidValue(\n onError,\n `Expected a value of non-null type \"${type}\" to be provided.`,\n path,\n );\n return;\n }\n if (inputValue === null) {\n reportInvalidValue(\n onError,\n `Expected value of non-null type \"${type}\" not to be null.`,\n path,\n );\n return;\n }\n return validateInputValueImpl(\n inputValue,\n type.ofType,\n onError,\n hideSuggestions,\n path,\n );\n }\n\n if (inputValue == null) {\n return;\n }\n\n if (isListType(type)) {\n if (!isIterableObject(inputValue)) {\n // Lists accept a non-list value as a list of one.\n validateInputValueImpl(\n inputValue,\n type.ofType,\n onError,\n hideSuggestions,\n path,\n );\n } else {\n let index = 0;\n for (const itemValue of inputValue) {\n validateInputValueImpl(\n itemValue,\n type.ofType,\n onError,\n hideSuggestions,\n addPath(path, index++, undefined),\n );\n }\n }\n } else if (isInputObjectType(type)) {\n if (!isObjectLike(inputValue) || Array.isArray(inputValue)) {\n reportInvalidValue(\n onError,\n `Expected value of type \"${type}\" to be an object, found: ${inspect(\n inputValue,\n )}.`,\n path,\n );\n return;\n }\n\n const fieldDefs = type.getFields();\n\n for (const field of Object.values(fieldDefs)) {\n const fieldValue = inputValue[field.name];\n if (fieldValue === undefined) {\n if (isRequiredInputField(field)) {\n reportInvalidValue(\n onError,\n `Expected value of type \"${type}\" to include required field \"${\n field.name\n }\", found: ${inspect(inputValue)}.`,\n path,\n );\n }\n } else {\n validateInputValueImpl(\n fieldValue,\n field.type,\n onError,\n hideSuggestions,\n addPath(path, field.name, type.name),\n );\n }\n }\n\n const fields: Array<string> = [];\n // Ensure every provided field is defined.\n for (const fieldName of Object.keys(inputValue)) {\n if (inputValue[fieldName] === undefined) {\n continue;\n }\n if (!Object.hasOwn(fieldDefs, fieldName)) {\n const suggestion = hideSuggestions\n ? ''\n : didYouMean(suggestionList(fieldName, Object.keys(fieldDefs)));\n reportInvalidValue(\n onError,\n `Expected value of type \"${type}\" not to include unknown field \"${fieldName}\"${\n suggestion ? `.${suggestion} Found` : ', found'\n }: ${inspect(inputValue)}.`,\n path,\n );\n continue;\n }\n fields.push(fieldName);\n }\n\n if (type.isOneOf) {\n if (fields.length !== 1) {\n reportInvalidValue(\n onError,\n getOneOfInputObjectErrorMessage(type),\n path,\n );\n }\n\n const field = fields[0];\n const value = inputValue[field];\n if (value === null) {\n reportInvalidValue(\n onError,\n getOneOfInputObjectErrorMessage(type),\n addPath(path, field, type.name),\n );\n }\n }\n } else {\n assertLeafType(type);\n\n let result;\n let caughtError: unknown;\n\n try {\n result = type.coerceInputValue(inputValue, hideSuggestions);\n } catch (error) {\n if (error instanceof GraphQLError) {\n onError(error, pathToArray(path));\n return;\n }\n caughtError = error;\n }\n\n if (result === undefined) {\n reportInvalidValue(\n onError,\n `Expected value of type \"${type}\"${\n caughtError != null\n ? `, but encountered error \"${getCaughtErrorMessage(caughtError)}\"; found`\n : ', found'\n }: ${inspect(inputValue)}.`,\n path,\n ensureGraphQLError(caughtError),\n );\n }\n }\n}\n\nfunction reportInvalidValue(\n onError: (error: GraphQLError, path: ReadonlyArray<string | number>) => void,\n message: string,\n path: Path | undefined,\n originalError?: GraphQLError,\n): void {\n onError(new GraphQLError(message, { originalError }), pathToArray(path));\n}\n\n/**\n * Validate that the provided input literal is allowed for this type, collecting\n * all errors via a callback function.\n *\n * If variable values are not provided, the literal is validated statically\n * (not assuming that those variables are missing runtime values).\n * @param valueNode - GraphQL value AST node to validate.\n * @param type - GraphQL input type to validate the literal against.\n * @param onError - Callback invoked for each validation error and path.\n * @param variables - Operation variable values returned by getVariableValues.\n * @param fragmentVariableValues - Fragment variable values for the current fragment scope.\n * @param hideSuggestions - Whether suggestion text should be omitted from errors.\n * @returns Nothing.\n * @example\n * ```ts\n * // Validate literal input values and collect literal paths.\n * import { parseValue } from 'graphql/language';\n * import {\n * GraphQLInputObjectType,\n * GraphQLInt,\n * GraphQLNonNull,\n * } from 'graphql/type';\n * import { validateInputLiteral } from 'graphql/utilities';\n *\n * const ReviewInput = new GraphQLInputObjectType({\n * name: 'ReviewInput',\n * fields: {\n * stars: { type: new GraphQLNonNull(GraphQLInt) },\n * },\n * });\n * const errors = [];\n *\n * validateInputLiteral(\n * parseValue('{ stars: \"bad\" }'),\n * ReviewInput,\n * (error, path) => {\n * errors.push({ message: error.message, path });\n * },\n * );\n *\n * errors; // => [ { message: 'Expected value of type \"Int\", found: \"bad\".', path: ['stars'] } ]\n * ```\n * @example\n * ```ts\n * // This variant resolves variable references using VariableValues from getVariableValues().\n * import assert from 'node:assert';\n * import { parse, parseValue } from 'graphql/language';\n * import { GraphQLInt } from 'graphql/type';\n * import { getVariableValues } from 'graphql/execution';\n * import { buildSchema, validateInputLiteral } from 'graphql/utilities';\n *\n * const schema = buildSchema(`\n * type Query {\n * review(stars: Int): String\n * }\n * `);\n * const document = parse('query ($stars: Int = 5) { review(stars: $stars) }');\n * const operation = document.definitions[0];\n * const result = getVariableValues(schema, operation.variableDefinitions, {\n * stars: '4',\n * });\n *\n * assert('variableValues' in result);\n *\n * const errors = [];\n * validateInputLiteral(\n * parseValue('$stars'),\n * GraphQLInt,\n * (error) => errors.push(error.message),\n * result.variableValues,\n * undefined,\n * true,\n * );\n *\n * errors; // => []\n * ```\n */\n// eslint-disable-next-line max-params\nexport function validateInputLiteral(\n valueNode: ValueNode,\n type: GraphQLInputType,\n onError: (error: GraphQLError, path: ReadonlyArray<string | number>) => void,\n variables?: Maybe<VariableValues>,\n fragmentVariableValues?: Maybe<FragmentVariableValues>,\n hideSuggestions?: Maybe<boolean>,\n): void {\n const context: ValidationContext = {\n static: !variables && !fragmentVariableValues,\n onError,\n variables,\n fragmentVariableValues,\n };\n return validateInputLiteralImpl(\n context,\n valueNode,\n type,\n hideSuggestions,\n undefined,\n );\n}\n\ninterface ValidationContext {\n static: boolean;\n onError: (error: GraphQLError, path: ReadonlyArray<string | number>) => void;\n variables?: Maybe<VariableValues>;\n fragmentVariableValues?: Maybe<FragmentVariableValues>;\n}\n\nfunction validateInputLiteralImpl(\n context: ValidationContext,\n valueNode: ValueNode,\n type: GraphQLInputType,\n hideSuggestions: Maybe<boolean>,\n path: Path | undefined,\n): void {\n if (valueNode.kind === Kind.VARIABLE) {\n if (context.static) {\n // If no variable values are provided, this is being validated statically,\n // and cannot yet produce any validation errors for variables.\n return;\n }\n const scopedVariableValues = getScopedVariableValues(context, valueNode);\n const value = scopedVariableValues?.coerced[valueNode.name.value];\n if (isNonNullType(type)) {\n if (value === undefined) {\n reportInvalidLiteral(\n context.onError,\n `Expected variable \"$${valueNode.name.value}\" provided to type \"${type}\" to provide a runtime value.`,\n valueNode,\n path,\n );\n } else if (value === null) {\n reportInvalidLiteral(\n context.onError,\n `Expected variable \"$${valueNode.name.value}\" provided to non-null type \"${type}\" not to be null.`,\n valueNode,\n path,\n );\n }\n }\n // Note: This does no further checking that this variable is correct.\n // This assumes this variable usage has already been validated.\n return;\n }\n\n if (isNonNullType(type)) {\n if (valueNode.kind === Kind.NULL) {\n reportInvalidLiteral(\n context.onError,\n `Expected value of non-null type \"${type}\" not to be null.`,\n valueNode,\n path,\n );\n return;\n }\n return validateInputLiteralImpl(\n context,\n valueNode,\n type.ofType,\n hideSuggestions,\n path,\n );\n }\n\n if (valueNode.kind === Kind.NULL) {\n return;\n }\n\n if (isListType(type)) {\n if (valueNode.kind !== Kind.LIST) {\n // Lists accept a non-list value as a list of one.\n validateInputLiteralImpl(\n context,\n valueNode,\n type.ofType,\n hideSuggestions,\n path,\n );\n } else {\n let index = 0;\n for (const itemNode of valueNode.values) {\n validateInputLiteralImpl(\n context,\n itemNode,\n type.ofType,\n hideSuggestions,\n addPath(path, index++, undefined),\n );\n }\n }\n } else if (isInputObjectType(type)) {\n if (valueNode.kind !== Kind.OBJECT) {\n reportInvalidLiteral(\n context.onError,\n `Expected value of type \"${type}\" to be an object, found: ${print(\n valueNode,\n )}.`,\n valueNode,\n path,\n );\n return;\n }\n\n const fieldDefs = type.getFields();\n const fieldNodes = keyMap(valueNode.fields, (field) => field.name.value);\n\n for (const field of Object.values(fieldDefs)) {\n const fieldNode = fieldNodes[field.name];\n if (fieldNode === undefined) {\n if (isRequiredInputField(field)) {\n reportInvalidLiteral(\n context.onError,\n `Expected value of type \"${type}\" to include required field \"${\n field.name\n }\", found: ${print(valueNode)}.`,\n valueNode,\n path,\n );\n }\n } else {\n const fieldValueNode = fieldNode.value;\n if (fieldValueNode.kind === Kind.VARIABLE && !context.static) {\n const scopedVariableValues = getScopedVariableValues(\n context,\n fieldValueNode,\n );\n const variableName = fieldValueNode.name.value;\n const value = scopedVariableValues?.coerced[variableName];\n if (type.isOneOf) {\n if (value === undefined) {\n reportInvalidLiteral(\n context.onError,\n `Expected variable \"$${variableName}\" provided to field \"${field.name}\" for OneOf Input Object type \"${type}\" to provide a runtime value.`,\n valueNode,\n path,\n );\n } else if (value === null) {\n reportInvalidLiteral(\n context.onError,\n `Expected variable \"$${variableName}\" provided to field \"${field.name}\" for OneOf Input Object type \"${type}\" not to be null.`,\n valueNode,\n path,\n );\n }\n } else if (value === undefined && !isRequiredInputField(field)) {\n continue;\n }\n }\n\n validateInputLiteralImpl(\n context,\n fieldValueNode,\n field.type,\n hideSuggestions,\n addPath(path, field.name, type.name),\n );\n }\n }\n\n const fields = valueNode.fields;\n const knownFields: Array<(typeof fields)[number]> = [];\n // Ensure every provided field is defined.\n for (const fieldNode of fields) {\n const fieldName = fieldNode.name.value;\n if (!Object.hasOwn(fieldDefs, fieldName)) {\n const suggestion = hideSuggestions\n ? ''\n : didYouMean(suggestionList(fieldName, Object.keys(fieldDefs)));\n reportInvalidLiteral(\n context.onError,\n `Expected value of type \"${type}\" not to include unknown field \"${fieldName}\"${\n suggestion ? `.${suggestion} Found` : ', found'\n }: ${print(valueNode)}.`,\n fieldNode,\n path,\n );\n } else {\n knownFields.push(fieldNode);\n }\n }\n\n if (type.isOneOf) {\n const isNotExactlyOneField = knownFields.length !== 1;\n if (isNotExactlyOneField) {\n reportInvalidLiteral(\n context.onError,\n getOneOfInputObjectErrorMessage(type),\n valueNode,\n path,\n );\n return;\n }\n\n const fieldValueNode = knownFields[0].value;\n if (fieldValueNode.kind === Kind.NULL) {\n const fieldName = knownFields[0].name.value;\n reportInvalidLiteral(\n context.onError,\n getOneOfInputObjectErrorMessage(type),\n valueNode,\n addPath(path, fieldName, undefined),\n );\n }\n }\n } else {\n assertLeafType(type);\n\n let result;\n let caughtError: unknown;\n try {\n result = type.coerceInputLiteral\n ? type.coerceInputLiteral(\n replaceVariables(\n valueNode,\n context.variables,\n context.fragmentVariableValues,\n ),\n hideSuggestions,\n )\n : type.parseLiteral(valueNode, undefined, hideSuggestions);\n } catch (error) {\n if (error instanceof GraphQLError) {\n context.onError(error, pathToArray(path));\n return;\n }\n caughtError = error;\n }\n\n if (result === undefined) {\n reportInvalidLiteral(\n context.onError,\n `Expected value of type \"${type}\"${\n caughtError != null\n ? `, but encountered error \"${getCaughtErrorMessage(caughtError)}\"; found`\n : ', found'\n }: ${print(valueNode)}.`,\n valueNode,\n path,\n ensureGraphQLError(caughtError),\n );\n }\n }\n}\n\nfunction getScopedVariableValues(\n context: ValidationContext,\n valueNode: VariableNode,\n): Maybe<VariableValues> {\n const variableName = valueNode.name.value;\n const { fragmentVariableValues, variables } = context;\n return fragmentVariableValues?.sources[variableName]\n ? fragmentVariableValues\n : variables;\n}\n\nfunction reportInvalidLiteral(\n onError: (error: GraphQLError, path: ReadonlyArray<string | number>) => void,\n message: string,\n valueNode: ASTNode,\n path: Path | undefined,\n originalError?: GraphQLError,\n): void {\n onError(\n new GraphQLError(message, {\n nodes: valueNode,\n originalError,\n }),\n pathToArray(path),\n );\n}\n\nfunction getCaughtErrorMessage(caughtError: unknown): string {\n if (isObjectLike(caughtError)) {\n const message = caughtError.message;\n if (typeof message === 'string' && message !== '') {\n return message;\n }\n }\n\n return String(caughtError);\n}\n\nfunction getOneOfInputObjectErrorMessage(type: GraphQLInputType): string {\n return `Within OneOf Input Object type \"${type}\", exactly one field must be specified, and the value for that field must be non-null.`;\n}\n"]}
@@ -11,7 +11,10 @@ import type { ValidationContext } from "../ValidationContext.mjs";
11
11
  * ```ts
12
12
  * import { parse } from 'graphql/language';
13
13
  * import { buildSchema } from 'graphql/utilities';
14
- * import { validate, DeferStreamDirectiveOnRootFieldRule } from 'graphql/validation';
14
+ * import {
15
+ * validate,
16
+ * DeferStreamDirectiveOnRootFieldRule,
17
+ * } from 'graphql/validation';
15
18
  *
16
19
  * const schema = buildSchema(`
17
20
  * type Query {
@@ -11,7 +11,10 @@ import type { ValidationContext } from "../ValidationContext.js";
11
11
  * ```ts
12
12
  * import { parse } from 'graphql/language';
13
13
  * import { buildSchema } from 'graphql/utilities';
14
- * import { validate, DeferStreamDirectiveOnRootFieldRule } from 'graphql/validation';
14
+ * import {
15
+ * validate,
16
+ * DeferStreamDirectiveOnRootFieldRule,
17
+ * } from 'graphql/validation';
15
18
  *
16
19
  * const schema = buildSchema(`
17
20
  * type Query {
@@ -2,30 +2,83 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DeferStreamDirectiveOnRootFieldRule = DeferStreamDirectiveOnRootFieldRule;
4
4
  const GraphQLError_ts_1 = require("../../error/GraphQLError.js");
5
+ const kinds_ts_1 = require("../../language/kinds.js");
5
6
  const directives_ts_1 = require("../../type/directives.js");
6
7
  function DeferStreamDirectiveOnRootFieldRule(context) {
7
8
  return {
8
- Directive(node) {
9
- const mutationType = context.getSchema().getMutationType();
10
- const subscriptionType = context.getSchema().getSubscriptionType();
11
- const parentType = context.getParentType();
12
- if (parentType && node.name.value === directives_ts_1.GraphQLDeferDirective.name) {
13
- if (mutationType && parentType === mutationType) {
14
- context.reportError(new GraphQLError_ts_1.GraphQLError(`Defer directive cannot be used on root mutation type "${parentType}".`, { nodes: node }));
15
- }
16
- if (subscriptionType && parentType === subscriptionType) {
17
- context.reportError(new GraphQLError_ts_1.GraphQLError(`Defer directive cannot be used on root subscription type "${parentType}".`, { nodes: node }));
9
+ OperationDefinition(node) {
10
+ const document = context.getDocument();
11
+ const fragments = new Map();
12
+ for (const definition of document.definitions) {
13
+ if (definition.kind === kinds_ts_1.Kind.FRAGMENT_DEFINITION) {
14
+ fragments.set(definition.name.value, definition);
18
15
  }
19
16
  }
20
- if (parentType && node.name.value === directives_ts_1.GraphQLStreamDirective.name) {
21
- if (mutationType && parentType === mutationType) {
22
- context.reportError(new GraphQLError_ts_1.GraphQLError(`Stream directive cannot be used on root mutation type "${parentType}".`, { nodes: node }));
23
- }
24
- if (subscriptionType && parentType === subscriptionType) {
25
- context.reportError(new GraphQLError_ts_1.GraphQLError(`Stream directive cannot be used on root subscription type "${parentType}".`, { nodes: node }));
26
- }
17
+ if (node.operation !== 'subscription' && node.operation !== 'mutation') {
18
+ return;
19
+ }
20
+ const schema = context.getSchema();
21
+ const rootType = schema.getRootType(node.operation);
22
+ if (rootType) {
23
+ forbidDeferStream({
24
+ context,
25
+ operationType: node.operation,
26
+ rootType,
27
+ fragments,
28
+ selectionSet: node.selectionSet,
29
+ visitedFragments: new Set(),
30
+ });
27
31
  }
28
32
  },
29
33
  };
30
34
  }
35
+ function forbidDeferStream({ context, operationType, rootType, fragments, selectionSet, visitedFragments, }) {
36
+ for (const selection of selectionSet.selections) {
37
+ if (selection.kind === 'Field') {
38
+ const stream = selection.directives?.find((d) => d.name.value === directives_ts_1.GraphQLStreamDirective.name);
39
+ if (stream) {
40
+ context.reportError(new GraphQLError_ts_1.GraphQLError(`Stream directive cannot be used on root ${operationType} type "${rootType}".`, { nodes: stream }));
41
+ }
42
+ }
43
+ else if (selection.kind === 'FragmentSpread') {
44
+ const fragmentName = selection.name.value;
45
+ if (visitedFragments.has(fragmentName)) {
46
+ continue;
47
+ }
48
+ const fragment = fragments.get(fragmentName);
49
+ if (fragment) {
50
+ const defer = getDeferDirective(selection);
51
+ if (defer !== undefined) {
52
+ context.reportError(new GraphQLError_ts_1.GraphQLError(`Defer directive cannot be used on root ${operationType} type "${rootType}".`, { nodes: defer }));
53
+ }
54
+ forbidDeferStream({
55
+ context,
56
+ operationType,
57
+ rootType,
58
+ fragments,
59
+ selectionSet: fragment.selectionSet,
60
+ visitedFragments,
61
+ });
62
+ }
63
+ visitedFragments.add(fragmentName);
64
+ }
65
+ else if (selection.kind === 'InlineFragment') {
66
+ const defer = getDeferDirective(selection);
67
+ if (defer !== undefined) {
68
+ context.reportError(new GraphQLError_ts_1.GraphQLError(`Defer directive cannot be used on root ${operationType} type "${rootType}".`, { nodes: defer }));
69
+ }
70
+ forbidDeferStream({
71
+ context,
72
+ operationType,
73
+ rootType,
74
+ fragments,
75
+ selectionSet: selection.selectionSet,
76
+ visitedFragments,
77
+ });
78
+ }
79
+ }
80
+ }
81
+ function getDeferDirective(fragment) {
82
+ return fragment.directives?.find((d) => d.name.value === directives_ts_1.GraphQLDeferDirective.name);
83
+ }
31
84
  //# sourceMappingURL=DeferStreamDirectiveOnRootFieldRule.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DeferStreamDirectiveOnRootFieldRule.js","sourceRoot":"","sources":["../../../src/validation/rules/DeferStreamDirectiveOnRootFieldRule.ts"],"names":[],"mappings":";;AA6CA,kFA8CC;AAzFD,iEAA2D;AAI3D,4DAGkC;AAoClC,SAAgB,mCAAmC,CACjD,OAA0B;IAE1B,OAAO;QACL,SAAS,CAAC,IAAI;YACZ,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,eAAe,EAAE,CAAC;YAC3D,MAAM,gBAAgB,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,mBAAmB,EAAE,CAAC;YACnE,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;YAC3C,IAAI,UAAU,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,qCAAqB,CAAC,IAAI,EAAE,CAAC;gBACjE,IAAI,YAAY,IAAI,UAAU,KAAK,YAAY,EAAE,CAAC;oBAChD,OAAO,CAAC,WAAW,CACjB,IAAI,8BAAY,CACd,yDAAyD,UAAU,IAAI,EACvE,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CAAC;gBACJ,CAAC;gBACD,IAAI,gBAAgB,IAAI,UAAU,KAAK,gBAAgB,EAAE,CAAC;oBACxD,OAAO,CAAC,WAAW,CACjB,IAAI,8BAAY,CACd,6DAA6D,UAAU,IAAI,EAC3E,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CAAC;gBACJ,CAAC;YACH,CAAC;YACD,IAAI,UAAU,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,sCAAsB,CAAC,IAAI,EAAE,CAAC;gBAClE,IAAI,YAAY,IAAI,UAAU,KAAK,YAAY,EAAE,CAAC;oBAChD,OAAO,CAAC,WAAW,CACjB,IAAI,8BAAY,CACd,0DAA0D,UAAU,IAAI,EACxE,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CAAC;gBACJ,CAAC;gBACD,IAAI,gBAAgB,IAAI,UAAU,KAAK,gBAAgB,EAAE,CAAC;oBACxD,OAAO,CAAC,WAAW,CACjB,IAAI,8BAAY,CACd,8DAA8D,UAAU,IAAI,EAC5E,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/** @category Validation Rules */\n\nimport { GraphQLError } from '../../error/GraphQLError.ts';\n\nimport type { ASTVisitor } from '../../language/visitor.ts';\n\nimport {\n GraphQLDeferDirective,\n GraphQLStreamDirective,\n} from '../../type/directives.ts';\n\nimport type { ValidationContext } from '../ValidationContext.ts';\n\n/**\n * Defer and stream directives are used on valid root field\n *\n * A GraphQL document is only valid if defer directives are not used on root mutation or subscription types.\n * @param context - The validation context used while checking the document.\n * @returns A visitor that reports validation errors for this rule.\n * @example\n * ```ts\n * import { parse } from 'graphql/language';\n * import { buildSchema } from 'graphql/utilities';\n * import { validate, DeferStreamDirectiveOnRootFieldRule } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * message: String\n * }\n *\n * type Mutation {\n * updateMessage: String\n * }\n * `);\n * const invalidDocument = parse(`\n * mutation { ... @defer { updateMessage } }\n * `);\n * const validDocument = parse(`\n * { ... @defer { message } }\n * `);\n *\n * validate(schema, invalidDocument, [DeferStreamDirectiveOnRootFieldRule]).length; // => 1\n * validate(schema, validDocument, [DeferStreamDirectiveOnRootFieldRule]); // => []\n * ```\n */\nexport function DeferStreamDirectiveOnRootFieldRule(\n context: ValidationContext,\n): ASTVisitor {\n return {\n Directive(node) {\n const mutationType = context.getSchema().getMutationType();\n const subscriptionType = context.getSchema().getSubscriptionType();\n const parentType = context.getParentType();\n if (parentType && node.name.value === GraphQLDeferDirective.name) {\n if (mutationType && parentType === mutationType) {\n context.reportError(\n new GraphQLError(\n `Defer directive cannot be used on root mutation type \"${parentType}\".`,\n { nodes: node },\n ),\n );\n }\n if (subscriptionType && parentType === subscriptionType) {\n context.reportError(\n new GraphQLError(\n `Defer directive cannot be used on root subscription type \"${parentType}\".`,\n { nodes: node },\n ),\n );\n }\n }\n if (parentType && node.name.value === GraphQLStreamDirective.name) {\n if (mutationType && parentType === mutationType) {\n context.reportError(\n new GraphQLError(\n `Stream directive cannot be used on root mutation type \"${parentType}\".`,\n { nodes: node },\n ),\n );\n }\n if (subscriptionType && parentType === subscriptionType) {\n context.reportError(\n new GraphQLError(\n `Stream directive cannot be used on root subscription type \"${parentType}\".`,\n { nodes: node },\n ),\n );\n }\n }\n },\n };\n}\n"]}
1
+ {"version":3,"file":"DeferStreamDirectiveOnRootFieldRule.js","sourceRoot":"","sources":["../../../src/validation/rules/DeferStreamDirectiveOnRootFieldRule.ts"],"names":[],"mappings":";;AA0DA,kFA8BC;AAtFD,iEAA2D;AAU3D,sDAA+C;AAI/C,4DAGkC;AAuClC,SAAgB,mCAAmC,CACjD,OAA0B;IAE1B,OAAO;QACL,mBAAmB,CAAC,IAA6B;YAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;YACvC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAkC,CAAC;YAE5D,KAAK,MAAM,UAAU,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;gBAC9C,IAAI,UAAU,CAAC,IAAI,KAAK,eAAI,CAAC,mBAAmB,EAAE,CAAC;oBACjD,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;gBACnD,CAAC;YACH,CAAC;YACD,IAAI,IAAI,CAAC,SAAS,KAA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AAI,CACnD,CAAC;AACJ,CAAC","sourcesContent":["/** @category Validation Rules */\n\nimport { GraphQLError } from '../../error/GraphQLError.ts';\n\nimport type {\n FragmentDefinitionNode,\n FragmentSpreadNode,\n InlineFragmentNode,\n OperationDefinitionNode,\n OperationTypeNode,\n SelectionSetNode,\n} from '../../language/ast.ts';\nimport { Kind } from '../../language/kinds.ts';\nimport type { ASTVisitor } from '../../language/visitor.ts';\n\nimport type { GraphQLObjectType } from '../../type/definition.ts';\nimport {\n GraphQLDeferDirective,\n GraphQLStreamDirective,\n} from '../../type/directives.ts';\n\nimport type { ValidationContext } from '../ValidationContext.ts';\n\n/**\n * Defer and stream directives are used on valid root field\n *\n * A GraphQL document is only valid if defer directives are not used on root mutation or subscription types.\n * @param context - The validation context used while checking the document.\n * @returns A visitor that reports validation errors for this rule.\n * @example\n * ```ts\n * import { parse } from 'graphql/language';\n * import { buildSchema } from 'graphql/utilities';\n * import {\n * validate,\n * DeferStreamDirectiveOnRootFieldRule,\n * } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * message: String\n * }\n *\n * type Mutation {\n * updateMessage: String\n * }\n * `);\n * const invalidDocument = parse(`\n * mutation { ... @defer { updateMessage } }\n * `);\n * const validDocument = parse(`\n * { ... @defer { message } }\n * `);\n *\n * validate(schema, invalidDocument, [DeferStreamDirectiveOnRootFieldRule]).length; // => 1\n * validate(schema, validDocument, [DeferStreamDirectiveOnRootFieldRule]); // => []\n * ```\n */\nexport function DeferStreamDirectiveOnRootFieldRule(\n context: ValidationContext,\n): ASTVisitor {\n return {\n OperationDefinition(node: OperationDefinitionNode) {\n const document = context.getDocument();\n const fragments = new Map<string, FragmentDefinitionNode>();\n\n for (const definition of document.definitions) {\n if (definition.kind === Kind.FRAGMENT_DEFINITION) {\n fragments.set(definition.name.value, definition);\n }\n }\n if (node.operation !== 'subscription' && node.operation !== 'mutation') {\n return;\n }\n const schema = context.getSchema();\n const rootType = schema.getRootType(node.operation);\n if (rootType) {\n forbidDeferStream({\n context,\n operationType: node.operation,\n rootType,\n fragments,\n selectionSet: node.selectionSet,\n visitedFragments: new Set(),\n });\n }\n },\n };\n}\n\nfunction forbidDeferStream({\n context,\n operationType,\n rootType,\n fragments,\n selectionSet,\n visitedFragments,\n}: {\n context: ValidationContext;\n operationType: OperationTypeNode;\n rootType: GraphQLObjectType;\n fragments: Map<string, FragmentDefinitionNode>;\n selectionSet: SelectionSetNode;\n visitedFragments: Set<string>;\n}) {\n for (const selection of selectionSet.selections) {\n if (selection.kind === 'Field') {\n const stream = selection.directives?.find(\n (d) => d.name.value === GraphQLStreamDirective.name,\n );\n if (stream) {\n context.reportError(\n new GraphQLError(\n `Stream directive cannot be used on root ${operationType} type \"${rootType}\".`,\n { nodes: stream },\n ),\n );\n }\n } else if (selection.kind === 'FragmentSpread') {\n const fragmentName = selection.name.value;\n if (visitedFragments.has(fragmentName)) {\n continue;\n }\n const fragment = fragments.get(fragmentName);\n if (fragment) {\n const defer = getDeferDirective(selection);\n if (defer !== undefined) {\n context.reportError(\n new GraphQLError(\n `Defer directive cannot be used on root ${operationType} type \"${rootType}\".`,\n { nodes: defer },\n ),\n );\n }\n forbidDeferStream({\n context,\n operationType,\n rootType,\n fragments,\n selectionSet: fragment.selectionSet,\n visitedFragments,\n });\n }\n visitedFragments.add(fragmentName);\n } else if (selection.kind === 'InlineFragment') {\n const defer = getDeferDirective(selection);\n if (defer !== undefined) {\n context.reportError(\n new GraphQLError(\n `Defer directive cannot be used on root ${operationType} type \"${rootType}\".`,\n { nodes: defer },\n ),\n );\n }\n forbidDeferStream({\n context,\n operationType,\n rootType,\n fragments,\n selectionSet: selection.selectionSet,\n visitedFragments,\n });\n }\n }\n}\n\nfunction getDeferDirective(fragment: FragmentSpreadNode | InlineFragmentNode) {\n return fragment.directives?.find(\n (d) => d.name.value === GraphQLDeferDirective.name,\n );\n}\n"]}
@@ -1,28 +1,81 @@
1
1
  import { GraphQLError } from "../../error/GraphQLError.mjs";
2
+ import { Kind } from "../../language/kinds.mjs";
2
3
  import { GraphQLDeferDirective, GraphQLStreamDirective, } from "../../type/directives.mjs";
3
4
  export function DeferStreamDirectiveOnRootFieldRule(context) {
4
5
  return {
5
- Directive(node) {
6
- const mutationType = context.getSchema().getMutationType();
7
- const subscriptionType = context.getSchema().getSubscriptionType();
8
- const parentType = context.getParentType();
9
- if (parentType && node.name.value === GraphQLDeferDirective.name) {
10
- if (mutationType && parentType === mutationType) {
11
- context.reportError(new GraphQLError(`Defer directive cannot be used on root mutation type "${parentType}".`, { nodes: node }));
12
- }
13
- if (subscriptionType && parentType === subscriptionType) {
14
- context.reportError(new GraphQLError(`Defer directive cannot be used on root subscription type "${parentType}".`, { nodes: node }));
6
+ OperationDefinition(node) {
7
+ const document = context.getDocument();
8
+ const fragments = new Map();
9
+ for (const definition of document.definitions) {
10
+ if (definition.kind === Kind.FRAGMENT_DEFINITION) {
11
+ fragments.set(definition.name.value, definition);
15
12
  }
16
13
  }
17
- if (parentType && node.name.value === GraphQLStreamDirective.name) {
18
- if (mutationType && parentType === mutationType) {
19
- context.reportError(new GraphQLError(`Stream directive cannot be used on root mutation type "${parentType}".`, { nodes: node }));
20
- }
21
- if (subscriptionType && parentType === subscriptionType) {
22
- context.reportError(new GraphQLError(`Stream directive cannot be used on root subscription type "${parentType}".`, { nodes: node }));
23
- }
14
+ if (node.operation !== 'subscription' && node.operation !== 'mutation') {
15
+ return;
16
+ }
17
+ const schema = context.getSchema();
18
+ const rootType = schema.getRootType(node.operation);
19
+ if (rootType) {
20
+ forbidDeferStream({
21
+ context,
22
+ operationType: node.operation,
23
+ rootType,
24
+ fragments,
25
+ selectionSet: node.selectionSet,
26
+ visitedFragments: new Set(),
27
+ });
24
28
  }
25
29
  },
26
30
  };
27
31
  }
32
+ function forbidDeferStream({ context, operationType, rootType, fragments, selectionSet, visitedFragments, }) {
33
+ for (const selection of selectionSet.selections) {
34
+ if (selection.kind === 'Field') {
35
+ const stream = selection.directives?.find((d) => d.name.value === GraphQLStreamDirective.name);
36
+ if (stream) {
37
+ context.reportError(new GraphQLError(`Stream directive cannot be used on root ${operationType} type "${rootType}".`, { nodes: stream }));
38
+ }
39
+ }
40
+ else if (selection.kind === 'FragmentSpread') {
41
+ const fragmentName = selection.name.value;
42
+ if (visitedFragments.has(fragmentName)) {
43
+ continue;
44
+ }
45
+ const fragment = fragments.get(fragmentName);
46
+ if (fragment) {
47
+ const defer = getDeferDirective(selection);
48
+ if (defer !== undefined) {
49
+ context.reportError(new GraphQLError(`Defer directive cannot be used on root ${operationType} type "${rootType}".`, { nodes: defer }));
50
+ }
51
+ forbidDeferStream({
52
+ context,
53
+ operationType,
54
+ rootType,
55
+ fragments,
56
+ selectionSet: fragment.selectionSet,
57
+ visitedFragments,
58
+ });
59
+ }
60
+ visitedFragments.add(fragmentName);
61
+ }
62
+ else if (selection.kind === 'InlineFragment') {
63
+ const defer = getDeferDirective(selection);
64
+ if (defer !== undefined) {
65
+ context.reportError(new GraphQLError(`Defer directive cannot be used on root ${operationType} type "${rootType}".`, { nodes: defer }));
66
+ }
67
+ forbidDeferStream({
68
+ context,
69
+ operationType,
70
+ rootType,
71
+ fragments,
72
+ selectionSet: selection.selectionSet,
73
+ visitedFragments,
74
+ });
75
+ }
76
+ }
77
+ }
78
+ function getDeferDirective(fragment) {
79
+ return fragment.directives?.find((d) => d.name.value === GraphQLDeferDirective.name);
80
+ }
28
81
  //# sourceMappingURL=DeferStreamDirectiveOnRootFieldRule.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DeferStreamDirectiveOnRootFieldRule.js","sourceRoot":"","sources":["../../../src/validation/rules/DeferStreamDirectiveOnRootFieldRule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,qCAAoC;AAI3D,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,kCAAiC;AAoClC,MAAM,UAAU,mCAAmC,CACjD,OAA0B;IAE1B,OAAO;QACL,SAAS,CAAC,IAAI;YACZ,MAAM,YAAY,GAA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} from '../../error/GraphQLError.ts';\n\nimport type { ASTVisitor } from '../../language/visitor.ts';\n\nimport {\n GraphQLDeferDirective,\n GraphQLStreamDirective,\n} from '../../type/directives.ts';\n\nimport type { ValidationContext } from '../ValidationContext.ts';\n\n/**\n * Defer and stream directives are used on valid root field\n *\n * A GraphQL document is only valid if defer directives are not used on root mutation or subscription types.\n * @param context - The validation context used while checking the document.\n * @returns A visitor that reports validation errors for this rule.\n * @example\n * ```ts\n * import { parse } from 'graphql/language';\n * import { buildSchema } from 'graphql/utilities';\n * import { validate, DeferStreamDirectiveOnRootFieldRule } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * message: String\n * }\n *\n * type Mutation {\n * updateMessage: String\n * }\n * `);\n * const invalidDocument = parse(`\n * mutation { ... @defer { updateMessage } }\n * `);\n * const validDocument = parse(`\n * { ... @defer { message } }\n * `);\n *\n * validate(schema, invalidDocument, [DeferStreamDirectiveOnRootFieldRule]).length; // => 1\n * validate(schema, validDocument, [DeferStreamDirectiveOnRootFieldRule]); // => []\n * ```\n */\nexport function DeferStreamDirectiveOnRootFieldRule(\n context: ValidationContext,\n): ASTVisitor {\n return {\n Directive(node) {\n const mutationType = context.getSchema().getMutationType();\n const subscriptionType = context.getSchema().getSubscriptionType();\n const parentType = context.getParentType();\n if (parentType && node.name.value === GraphQLDeferDirective.name) {\n if (mutationType && parentType === mutationType) {\n context.reportError(\n new GraphQLError(\n `Defer directive cannot be used on root mutation type \"${parentType}\".`,\n { nodes: node },\n ),\n );\n }\n if (subscriptionType && parentType === subscriptionType) {\n context.reportError(\n new GraphQLError(\n `Defer directive cannot be used on root subscription type \"${parentType}\".`,\n { nodes: node },\n ),\n );\n }\n }\n if (parentType && node.name.value === GraphQLStreamDirective.name) {\n if (mutationType && parentType === mutationType) {\n context.reportError(\n new GraphQLError(\n `Stream directive cannot be used on root mutation type \"${parentType}\".`,\n { nodes: node },\n ),\n );\n }\n if (subscriptionType && parentType === subscriptionType) {\n context.reportError(\n new GraphQLError(\n `Stream directive cannot be used on root subscription type \"${parentType}\".`,\n { nodes: node },\n ),\n );\n }\n }\n },\n };\n}\n"]}
1
+ {"version":3,"file":"DeferStreamDirectiveOnRootFieldRule.js","sourceRoot":"","sources":["../../../src/validation/rules/DeferStreamDirectiveOnRootFieldRule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,qCAAoC;AAU3D,OAAO,EAAE,IAAI,EAAE,iCAAgC;AAI/C,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,kCAAiC;AAuClC,MAAM,UAAU,mCAAmC,CACjD,OAA0B;IAE1B,OAAO;QACL,mBAAmB,CAAC,IAA6B;YAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;YACvC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAkC,CAAC;YAE5D,KAAK,MAAM,UAAU,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;gBAC9C,IAAI,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC,mBAAmB,EAAE,CAAC;oBACjD,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;gBACnD,CAAC;YACH,CAAC;YACD,IAAI,IAAI,CAAC,SAAS,KAAK,cAAc,IAAI,IAAI,CAAC,SAAS,KAAK,UAAU,EAAE,CAAC;gBACvE,OAAO;YACT,CAAC;YACD,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;YACnC,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACpD,IAAI,QAAQ,EAAE,CAAC;gBACb,iBAAiB,CAAC;oBAChB,OAAO;oBACP,aAAa,EAAE,IAAI,CAAC,SAAS;oBAC7B,QAAQ;oBACR,SAAS;oBACT,YAAY,EAAE,IAAI,CAAC,YAAY;oBAC/B,gBAAgB,EAAE,IAAI,GAAG,EAAE;iBAC5B,CA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BACR,SAAS;oBACT,YAAY,EAAE,QAAQ,CAAC,YAAY;oBACnC,gBAAgB;iBACjB,CAAC,CAAC;YACL,CAAC;YACD,gBAAgB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACrC,CAAC;aAAM,IAAI,SAAS,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YAC/C,MAAM,KAAK,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;YAC3C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,CAAC,WAAW,CACjB,IAAI,YAAY,CACd,0CAA0C,aAAa,UAAU,QAAQ,IAAI,EAC7E,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CACF,CAAC;YACJ,CAAC;YACD,iBAAiB,CAAC;gBAChB,OAAO;gBACP,aAAa;gBACb,QAAQ;gBACR,SAAS;gBACT,YAAY,EAAE,SAAS,CAAC,YAAY;gBACpC,gBAAgB;aACjB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,QAAiD;IAC1E,OAAO,QAAQ,CAAC,UAAU,EAAE,IAAI,CAC9B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,KAAK,qBAAqB,CAAC,IAAI,CACnD,CAAC;AACJ,CAAC","sourcesContent":["/** @category Validation Rules */\n\nimport { GraphQLError } from '../../error/GraphQLError.ts';\n\nimport type {\n FragmentDefinitionNode,\n FragmentSpreadNode,\n InlineFragmentNode,\n OperationDefinitionNode,\n OperationTypeNode,\n SelectionSetNode,\n} from '../../language/ast.ts';\nimport { Kind } from '../../language/kinds.ts';\nimport type { ASTVisitor } from '../../language/visitor.ts';\n\nimport type { GraphQLObjectType } from '../../type/definition.ts';\nimport {\n GraphQLDeferDirective,\n GraphQLStreamDirective,\n} from '../../type/directives.ts';\n\nimport type { ValidationContext } from '../ValidationContext.ts';\n\n/**\n * Defer and stream directives are used on valid root field\n *\n * A GraphQL document is only valid if defer directives are not used on root mutation or subscription types.\n * @param context - The validation context used while checking the document.\n * @returns A visitor that reports validation errors for this rule.\n * @example\n * ```ts\n * import { parse } from 'graphql/language';\n * import { buildSchema } from 'graphql/utilities';\n * import {\n * validate,\n * DeferStreamDirectiveOnRootFieldRule,\n * } from 'graphql/validation';\n *\n * const schema = buildSchema(`\n * type Query {\n * message: String\n * }\n *\n * type Mutation {\n * updateMessage: String\n * }\n * `);\n * const invalidDocument = parse(`\n * mutation { ... @defer { updateMessage } }\n * `);\n * const validDocument = parse(`\n * { ... @defer { message } }\n * `);\n *\n * validate(schema, invalidDocument, [DeferStreamDirectiveOnRootFieldRule]).length; // => 1\n * validate(schema, validDocument, [DeferStreamDirectiveOnRootFieldRule]); // => []\n * ```\n */\nexport function DeferStreamDirectiveOnRootFieldRule(\n context: ValidationContext,\n): ASTVisitor {\n return {\n OperationDefinition(node: OperationDefinitionNode) {\n const document = context.getDocument();\n const fragments = new Map<string, FragmentDefinitionNode>();\n\n for (const definition of document.definitions) {\n if (definition.kind === Kind.FRAGMENT_DEFINITION) {\n fragments.set(definition.name.value, definition);\n }\n }\n if (node.operation !== 'subscription' && node.operation !== 'mutation') {\n return;\n }\n const schema = context.getSchema();\n const rootType = schema.getRootType(node.operation);\n if (rootType) {\n forbidDeferStream({\n context,\n operationType: node.operation,\n rootType,\n fragments,\n selectionSet: node.selectionSet,\n visitedFragments: new Set(),\n });\n }\n },\n };\n}\n\nfunction forbidDeferStream({\n context,\n operationType,\n rootType,\n fragments,\n selectionSet,\n visitedFragments,\n}: {\n context: ValidationContext;\n operationType: OperationTypeNode;\n rootType: GraphQLObjectType;\n fragments: Map<string, FragmentDefinitionNode>;\n selectionSet: SelectionSetNode;\n visitedFragments: Set<string>;\n}) {\n for (const selection of selectionSet.selections) {\n if (selection.kind === 'Field') {\n const stream = selection.directives?.find(\n (d) => d.name.value === GraphQLStreamDirective.name,\n );\n if (stream) {\n context.reportError(\n new GraphQLError(\n `Stream directive cannot be used on root ${operationType} type \"${rootType}\".`,\n { nodes: stream },\n ),\n );\n }\n } else if (selection.kind === 'FragmentSpread') {\n const fragmentName = selection.name.value;\n if (visitedFragments.has(fragmentName)) {\n continue;\n }\n const fragment = fragments.get(fragmentName);\n if (fragment) {\n const defer = getDeferDirective(selection);\n if (defer !== undefined) {\n context.reportError(\n new GraphQLError(\n `Defer directive cannot be used on root ${operationType} type \"${rootType}\".`,\n { nodes: defer },\n ),\n );\n }\n forbidDeferStream({\n context,\n operationType,\n rootType,\n fragments,\n selectionSet: fragment.selectionSet,\n visitedFragments,\n });\n }\n visitedFragments.add(fragmentName);\n } else if (selection.kind === 'InlineFragment') {\n const defer = getDeferDirective(selection);\n if (defer !== undefined) {\n context.reportError(\n new GraphQLError(\n `Defer directive cannot be used on root ${operationType} type \"${rootType}\".`,\n { nodes: defer },\n ),\n );\n }\n forbidDeferStream({\n context,\n operationType,\n rootType,\n fragments,\n selectionSet: selection.selectionSet,\n visitedFragments,\n });\n }\n }\n}\n\nfunction getDeferDirective(fragment: FragmentSpreadNode | InlineFragmentNode) {\n return fragment.directives?.find(\n (d) => d.name.value === GraphQLDeferDirective.name,\n );\n}\n"]}
@@ -4,7 +4,7 @@ import type { ValidationContext } from "../ValidationContext.mjs";
4
4
  /**
5
5
  * Defer And Stream Directives Are Used On Valid Operations
6
6
  *
7
- * A GraphQL document is only valid if defer directives are not used on root mutation or subscription types.
7
+ * A GraphQL document is only valid if defer and stream directives are not used on root mutation or subscription types.
8
8
  * @param context - The validation context used while checking the document.
9
9
  * @returns A visitor that reports validation errors for this rule.
10
10
  * @example
@@ -4,7 +4,7 @@ import type { ValidationContext } from "../ValidationContext.js";
4
4
  /**
5
5
  * Defer And Stream Directives Are Used On Valid Operations
6
6
  *
7
- * A GraphQL document is only valid if defer directives are not used on root mutation or subscription types.
7
+ * A GraphQL document is only valid if defer and stream directives are not used on root mutation or subscription types.
8
8
  * @param context - The validation context used while checking the document.
9
9
  * @returns A visitor that reports validation errors for this rule.
10
10
  * @example
@@ -20,35 +20,104 @@ function ifArgumentCanBeFalse(node) {
20
20
  }
21
21
  return true;
22
22
  }
23
+ function canBeSkippedViaSkipDirective(node) {
24
+ const ifArgument = node.arguments?.find((arg) => arg.name.value === 'if');
25
+ if (!ifArgument) {
26
+ return true;
27
+ }
28
+ if (ifArgument.value.kind === kinds_ts_1.Kind.BOOLEAN) {
29
+ if (ifArgument.value.value) {
30
+ return true;
31
+ }
32
+ return false;
33
+ }
34
+ return true;
35
+ }
36
+ function canBeSkippedViaIncludeDirective(node) {
37
+ const ifArgument = node.arguments?.find((arg) => arg.name.value === 'if');
38
+ if (!ifArgument) {
39
+ return false;
40
+ }
41
+ if (ifArgument?.value.kind === kinds_ts_1.Kind.BOOLEAN) {
42
+ if (ifArgument.value.value) {
43
+ return false;
44
+ }
45
+ return true;
46
+ }
47
+ return true;
48
+ }
23
49
  function DeferStreamDirectiveOnValidOperationsRule(context) {
24
- const fragmentsUsedOnSubscriptions = new Set();
25
50
  return {
26
51
  OperationDefinition(operation) {
27
- if (operation.operation === ast_ts_1.OperationTypeNode.SUBSCRIPTION) {
28
- for (const fragment of context.getRecursivelyReferencedFragments(operation)) {
29
- fragmentsUsedOnSubscriptions.add(fragment.name.value);
52
+ if (operation.operation !== ast_ts_1.OperationTypeNode.SUBSCRIPTION) {
53
+ return;
54
+ }
55
+ const document = context.getDocument();
56
+ const fragments = new Map();
57
+ for (const definition of document.definitions) {
58
+ if (definition.kind === kinds_ts_1.Kind.FRAGMENT_DEFINITION) {
59
+ fragments.set(definition.name.value, definition);
30
60
  }
31
61
  }
62
+ const visitedFragments = new Set();
63
+ forbidUnconditionalDeferStream({
64
+ context,
65
+ fragments,
66
+ selectionSet: operation.selectionSet,
67
+ parentNodes: [],
68
+ visitedFragments,
69
+ });
32
70
  },
33
- Directive(node, _key, _parent, _path, ancestors) {
34
- const definitionNode = ancestors[2];
35
- if ('kind' in definitionNode &&
36
- ((definitionNode.kind === kinds_ts_1.Kind.FRAGMENT_DEFINITION &&
37
- fragmentsUsedOnSubscriptions.has(definitionNode.name.value)) ||
38
- (definitionNode.kind === kinds_ts_1.Kind.OPERATION_DEFINITION &&
39
- definitionNode.operation === ast_ts_1.OperationTypeNode.SUBSCRIPTION))) {
40
- if (node.name.value === directives_ts_1.GraphQLDeferDirective.name) {
41
- if (!ifArgumentCanBeFalse(node)) {
42
- context.reportError(new GraphQLError_ts_1.GraphQLError('Defer directive not supported on subscription operations. Disable `@defer` by setting the `if` argument to `false`.', { nodes: node }));
43
- }
71
+ };
72
+ }
73
+ function forbidUnconditionalDeferStream({ context, fragments, selectionSet, parentNodes, visitedFragments, }) {
74
+ for (const selection of selectionSet.selections) {
75
+ const skip = selection.directives?.find((d) => d.name.value === directives_ts_1.GraphQLSkipDirective.name);
76
+ if (skip && canBeSkippedViaSkipDirective(skip)) {
77
+ continue;
78
+ }
79
+ const include = selection.directives?.find((d) => d.name.value === directives_ts_1.GraphQLIncludeDirective.name);
80
+ if (include && canBeSkippedViaIncludeDirective(include)) {
81
+ continue;
82
+ }
83
+ for (const directive of selection.directives ?? []) {
84
+ if (directive.name.value === directives_ts_1.GraphQLDeferDirective.name) {
85
+ if (!ifArgumentCanBeFalse(directive)) {
86
+ context.reportError(new GraphQLError_ts_1.GraphQLError('Defer directive not supported on subscription operations. Disable `@defer` by setting the `if` argument to `false`.', { nodes: [directive, ...parentNodes] }));
44
87
  }
45
- else if (node.name.value === directives_ts_1.GraphQLStreamDirective.name) {
46
- if (!ifArgumentCanBeFalse(node)) {
47
- context.reportError(new GraphQLError_ts_1.GraphQLError('Stream directive not supported on subscription operations. Disable `@stream` by setting the `if` argument to `false`.', { nodes: node }));
48
- }
88
+ }
89
+ else if (directive.name.value === directives_ts_1.GraphQLStreamDirective.name) {
90
+ if (!ifArgumentCanBeFalse(directive)) {
91
+ context.reportError(new GraphQLError_ts_1.GraphQLError('Stream directive not supported on subscription operations. Disable `@stream` by setting the `if` argument to `false`.', { nodes: [directive, ...parentNodes] }));
49
92
  }
50
93
  }
51
- },
52
- };
94
+ }
95
+ if (selection.kind === 'FragmentSpread') {
96
+ const fragmentName = selection.name.value;
97
+ if (visitedFragments.has(fragmentName)) {
98
+ continue;
99
+ }
100
+ visitedFragments.add(fragmentName);
101
+ const fragment = fragments.get(fragmentName);
102
+ if (fragment) {
103
+ forbidUnconditionalDeferStream({
104
+ context,
105
+ fragments,
106
+ parentNodes: [selection, ...parentNodes],
107
+ selectionSet: fragment?.selectionSet,
108
+ visitedFragments,
109
+ });
110
+ }
111
+ }
112
+ else if (selection.selectionSet) {
113
+ forbidUnconditionalDeferStream({
114
+ context,
115
+ fragments,
116
+ selectionSet: selection.selectionSet,
117
+ parentNodes,
118
+ visitedFragments,
119
+ });
120
+ }
121
+ }
53
122
  }
54
123
  //# sourceMappingURL=DeferStreamDirectiveOnValidOperationsRule.js.map