@theguild/federation-composition 0.0.0-alpha-20230916192321-bb37b43

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 (355) hide show
  1. package/LICENSE +18 -0
  2. package/cjs/compose.js +85 -0
  3. package/cjs/graphql/helpers.js +32 -0
  4. package/cjs/graphql/printer.js +248 -0
  5. package/cjs/graphql/type-node-info.js +142 -0
  6. package/cjs/index.js +22 -0
  7. package/cjs/package.json +1 -0
  8. package/cjs/specifications/federation.js +211 -0
  9. package/cjs/specifications/inaccessible.js +10 -0
  10. package/cjs/specifications/join.js +35 -0
  11. package/cjs/specifications/link.js +222 -0
  12. package/cjs/specifications/tag.js +12 -0
  13. package/cjs/subgraph/helpers.js +255 -0
  14. package/cjs/subgraph/state.js +1154 -0
  15. package/cjs/subgraph/validation/rules/elements/compose-directive.js +41 -0
  16. package/cjs/subgraph/validation/rules/elements/extends.js +34 -0
  17. package/cjs/subgraph/validation/rules/elements/external.js +57 -0
  18. package/cjs/subgraph/validation/rules/elements/field-set.js +37 -0
  19. package/cjs/subgraph/validation/rules/elements/inaccessible.js +112 -0
  20. package/cjs/subgraph/validation/rules/elements/key.js +148 -0
  21. package/cjs/subgraph/validation/rules/elements/override.js +56 -0
  22. package/cjs/subgraph/validation/rules/elements/provides.js +173 -0
  23. package/cjs/subgraph/validation/rules/elements/requires.js +119 -0
  24. package/cjs/subgraph/validation/rules/elements/shareable.js +43 -0
  25. package/cjs/subgraph/validation/rules/elements/tag.js +120 -0
  26. package/cjs/subgraph/validation/rules/known-argument-names-on-directives-rule.js +34 -0
  27. package/cjs/subgraph/validation/rules/known-directives-rule.js +105 -0
  28. package/cjs/subgraph/validation/rules/known-federation-directive-rule.js +34 -0
  29. package/cjs/subgraph/validation/rules/known-root-type-rule.js +25 -0
  30. package/cjs/subgraph/validation/rules/known-type-names-rule.js +34 -0
  31. package/cjs/subgraph/validation/rules/lone-schema-definition-rule.js +20 -0
  32. package/cjs/subgraph/validation/rules/provided-arguments-on-directives-rule.js +104 -0
  33. package/cjs/subgraph/validation/rules/provided-required-arguments-on-directives-rule.js +46 -0
  34. package/cjs/subgraph/validation/rules/query-root-type-inaccessible-rule.js +33 -0
  35. package/cjs/subgraph/validation/rules/reserved-subgraph-name-rule.js +15 -0
  36. package/cjs/subgraph/validation/rules/root-type-used-rule.js +59 -0
  37. package/cjs/subgraph/validation/rules/unique-argument-definition-names-rule.js +42 -0
  38. package/cjs/subgraph/validation/rules/unique-argument-names-rule.js +27 -0
  39. package/cjs/subgraph/validation/rules/unique-directive-names-rule.js +24 -0
  40. package/cjs/subgraph/validation/rules/unique-directives-per-location-rule.js +52 -0
  41. package/cjs/subgraph/validation/rules/unique-enum-value-names-rule.js +33 -0
  42. package/cjs/subgraph/validation/rules/unique-field-definition-names-rule.js +37 -0
  43. package/cjs/subgraph/validation/rules/unique-input-field-names-rule.js +37 -0
  44. package/cjs/subgraph/validation/rules/unique-operation-types-rule.js +29 -0
  45. package/cjs/subgraph/validation/rules/unique-type-names-rule.js +29 -0
  46. package/cjs/subgraph/validation/validate-state.js +476 -0
  47. package/cjs/subgraph/validation/validate-subgraph.js +329 -0
  48. package/cjs/subgraph/validation/validation-context.js +267 -0
  49. package/cjs/supergraph/composition/ast.js +779 -0
  50. package/cjs/supergraph/composition/common.js +7 -0
  51. package/cjs/supergraph/composition/directive.js +93 -0
  52. package/cjs/supergraph/composition/enum-type.js +132 -0
  53. package/cjs/supergraph/composition/input-object-type.js +119 -0
  54. package/cjs/supergraph/composition/interface-type.js +226 -0
  55. package/cjs/supergraph/composition/object-type.js +380 -0
  56. package/cjs/supergraph/composition/scalar-type.js +63 -0
  57. package/cjs/supergraph/composition/union-type.js +64 -0
  58. package/cjs/supergraph/composition/visitor.js +62 -0
  59. package/cjs/supergraph/state.js +249 -0
  60. package/cjs/supergraph/validation/rules/default-value-uses-inaccessible-rule.js +35 -0
  61. package/cjs/supergraph/validation/rules/directive-composition-rule.js +98 -0
  62. package/cjs/supergraph/validation/rules/enum-values-rule.js +59 -0
  63. package/cjs/supergraph/validation/rules/extension-with-base.js +31 -0
  64. package/cjs/supergraph/validation/rules/external-argument-missing-rule.js +32 -0
  65. package/cjs/supergraph/validation/rules/external-missing-on-base-rule.js +48 -0
  66. package/cjs/supergraph/validation/rules/external-type-mismatch-rule.js +52 -0
  67. package/cjs/supergraph/validation/rules/field-argument-default-mismatch-rule.js +40 -0
  68. package/cjs/supergraph/validation/rules/field-arguments-of-the-same-type-rule.js +49 -0
  69. package/cjs/supergraph/validation/rules/fields-of-the-same-type-rule.js +89 -0
  70. package/cjs/supergraph/validation/rules/input-field-default-mismatch-rule.js +40 -0
  71. package/cjs/supergraph/validation/rules/input-object-values-rule.js +25 -0
  72. package/cjs/supergraph/validation/rules/interface-key-missing-implementation-type.js +46 -0
  73. package/cjs/supergraph/validation/rules/invalid-field-sharing-rule.js +45 -0
  74. package/cjs/supergraph/validation/rules/only-inaccessible-children-rule.js +40 -0
  75. package/cjs/supergraph/validation/rules/override-source-has-override.js +36 -0
  76. package/cjs/supergraph/validation/rules/referenced-inaccessible-rule.js +44 -0
  77. package/cjs/supergraph/validation/rules/required-argument-missing-in-some-subgraph-rule.js +32 -0
  78. package/cjs/supergraph/validation/rules/required-input-field-missing-in-some-subgraph-rule.js +32 -0
  79. package/cjs/supergraph/validation/rules/required-query-rule.js +14 -0
  80. package/cjs/supergraph/validation/rules/satisfiablity-rule.js +866 -0
  81. package/cjs/supergraph/validation/rules/subgraph-name-rule.js +18 -0
  82. package/cjs/supergraph/validation/rules/types-of-the-same-kind-rule.js +54 -0
  83. package/cjs/supergraph/validation/validate-supergraph.js +77 -0
  84. package/cjs/supergraph/validation/validation-context.js +25 -0
  85. package/cjs/types.js +0 -0
  86. package/cjs/utils/dependency-graph.js +227 -0
  87. package/cjs/utils/format.js +27 -0
  88. package/cjs/utils/helpers.js +7 -0
  89. package/cjs/utils/state.js +23 -0
  90. package/cjs/validate.js +117 -0
  91. package/esm/compose.js +78 -0
  92. package/esm/graphql/helpers.js +27 -0
  93. package/esm/graphql/printer.js +244 -0
  94. package/esm/graphql/type-node-info.js +137 -0
  95. package/esm/index.js +4 -0
  96. package/esm/specifications/federation.js +204 -0
  97. package/esm/specifications/inaccessible.js +7 -0
  98. package/esm/specifications/join.js +32 -0
  99. package/esm/specifications/link.js +210 -0
  100. package/esm/specifications/tag.js +9 -0
  101. package/esm/subgraph/helpers.js +245 -0
  102. package/esm/subgraph/state.js +1148 -0
  103. package/esm/subgraph/validation/rules/elements/compose-directive.js +37 -0
  104. package/esm/subgraph/validation/rules/elements/extends.js +30 -0
  105. package/esm/subgraph/validation/rules/elements/external.js +53 -0
  106. package/esm/subgraph/validation/rules/elements/field-set.js +33 -0
  107. package/esm/subgraph/validation/rules/elements/inaccessible.js +108 -0
  108. package/esm/subgraph/validation/rules/elements/key.js +144 -0
  109. package/esm/subgraph/validation/rules/elements/override.js +52 -0
  110. package/esm/subgraph/validation/rules/elements/provides.js +169 -0
  111. package/esm/subgraph/validation/rules/elements/requires.js +115 -0
  112. package/esm/subgraph/validation/rules/elements/shareable.js +39 -0
  113. package/esm/subgraph/validation/rules/elements/tag.js +116 -0
  114. package/esm/subgraph/validation/rules/known-argument-names-on-directives-rule.js +30 -0
  115. package/esm/subgraph/validation/rules/known-directives-rule.js +101 -0
  116. package/esm/subgraph/validation/rules/known-federation-directive-rule.js +30 -0
  117. package/esm/subgraph/validation/rules/known-root-type-rule.js +21 -0
  118. package/esm/subgraph/validation/rules/known-type-names-rule.js +30 -0
  119. package/esm/subgraph/validation/rules/lone-schema-definition-rule.js +16 -0
  120. package/esm/subgraph/validation/rules/provided-arguments-on-directives-rule.js +100 -0
  121. package/esm/subgraph/validation/rules/provided-required-arguments-on-directives-rule.js +42 -0
  122. package/esm/subgraph/validation/rules/query-root-type-inaccessible-rule.js +29 -0
  123. package/esm/subgraph/validation/rules/reserved-subgraph-name-rule.js +11 -0
  124. package/esm/subgraph/validation/rules/root-type-used-rule.js +55 -0
  125. package/esm/subgraph/validation/rules/unique-argument-definition-names-rule.js +38 -0
  126. package/esm/subgraph/validation/rules/unique-argument-names-rule.js +23 -0
  127. package/esm/subgraph/validation/rules/unique-directive-names-rule.js +20 -0
  128. package/esm/subgraph/validation/rules/unique-directives-per-location-rule.js +48 -0
  129. package/esm/subgraph/validation/rules/unique-enum-value-names-rule.js +29 -0
  130. package/esm/subgraph/validation/rules/unique-field-definition-names-rule.js +33 -0
  131. package/esm/subgraph/validation/rules/unique-input-field-names-rule.js +33 -0
  132. package/esm/subgraph/validation/rules/unique-operation-types-rule.js +25 -0
  133. package/esm/subgraph/validation/rules/unique-type-names-rule.js +25 -0
  134. package/esm/subgraph/validation/validate-state.js +463 -0
  135. package/esm/subgraph/validation/validate-subgraph.js +323 -0
  136. package/esm/subgraph/validation/validation-context.js +262 -0
  137. package/esm/supergraph/composition/ast.js +765 -0
  138. package/esm/supergraph/composition/common.js +3 -0
  139. package/esm/supergraph/composition/directive.js +89 -0
  140. package/esm/supergraph/composition/enum-type.js +128 -0
  141. package/esm/supergraph/composition/input-object-type.js +115 -0
  142. package/esm/supergraph/composition/interface-type.js +222 -0
  143. package/esm/supergraph/composition/object-type.js +375 -0
  144. package/esm/supergraph/composition/scalar-type.js +59 -0
  145. package/esm/supergraph/composition/union-type.js +60 -0
  146. package/esm/supergraph/composition/visitor.js +58 -0
  147. package/esm/supergraph/state.js +245 -0
  148. package/esm/supergraph/validation/rules/default-value-uses-inaccessible-rule.js +31 -0
  149. package/esm/supergraph/validation/rules/directive-composition-rule.js +94 -0
  150. package/esm/supergraph/validation/rules/enum-values-rule.js +55 -0
  151. package/esm/supergraph/validation/rules/extension-with-base.js +27 -0
  152. package/esm/supergraph/validation/rules/external-argument-missing-rule.js +28 -0
  153. package/esm/supergraph/validation/rules/external-missing-on-base-rule.js +44 -0
  154. package/esm/supergraph/validation/rules/external-type-mismatch-rule.js +48 -0
  155. package/esm/supergraph/validation/rules/field-argument-default-mismatch-rule.js +36 -0
  156. package/esm/supergraph/validation/rules/field-arguments-of-the-same-type-rule.js +45 -0
  157. package/esm/supergraph/validation/rules/fields-of-the-same-type-rule.js +85 -0
  158. package/esm/supergraph/validation/rules/input-field-default-mismatch-rule.js +36 -0
  159. package/esm/supergraph/validation/rules/input-object-values-rule.js +21 -0
  160. package/esm/supergraph/validation/rules/interface-key-missing-implementation-type.js +42 -0
  161. package/esm/supergraph/validation/rules/invalid-field-sharing-rule.js +41 -0
  162. package/esm/supergraph/validation/rules/only-inaccessible-children-rule.js +36 -0
  163. package/esm/supergraph/validation/rules/override-source-has-override.js +32 -0
  164. package/esm/supergraph/validation/rules/referenced-inaccessible-rule.js +40 -0
  165. package/esm/supergraph/validation/rules/required-argument-missing-in-some-subgraph-rule.js +28 -0
  166. package/esm/supergraph/validation/rules/required-input-field-missing-in-some-subgraph-rule.js +28 -0
  167. package/esm/supergraph/validation/rules/required-query-rule.js +10 -0
  168. package/esm/supergraph/validation/rules/satisfiablity-rule.js +862 -0
  169. package/esm/supergraph/validation/rules/subgraph-name-rule.js +14 -0
  170. package/esm/supergraph/validation/rules/types-of-the-same-kind-rule.js +50 -0
  171. package/esm/supergraph/validation/validate-supergraph.js +73 -0
  172. package/esm/supergraph/validation/validation-context.js +21 -0
  173. package/esm/types.js +0 -0
  174. package/esm/utils/dependency-graph.js +222 -0
  175. package/esm/utils/format.js +23 -0
  176. package/esm/utils/helpers.js +3 -0
  177. package/esm/utils/state.js +15 -0
  178. package/esm/validate.js +113 -0
  179. package/package.json +46 -0
  180. package/typings/compose.d.cts +16 -0
  181. package/typings/compose.d.ts +16 -0
  182. package/typings/graphql/helpers.d.cts +4 -0
  183. package/typings/graphql/helpers.d.ts +4 -0
  184. package/typings/graphql/printer.d.cts +3 -0
  185. package/typings/graphql/printer.d.ts +3 -0
  186. package/typings/graphql/type-node-info.d.cts +19 -0
  187. package/typings/graphql/type-node-info.d.ts +19 -0
  188. package/typings/index.d.cts +5 -0
  189. package/typings/index.d.ts +5 -0
  190. package/typings/specifications/federation.d.cts +45 -0
  191. package/typings/specifications/federation.d.ts +45 -0
  192. package/typings/specifications/inaccessible.d.cts +4 -0
  193. package/typings/specifications/inaccessible.d.ts +4 -0
  194. package/typings/specifications/join.d.cts +2 -0
  195. package/typings/specifications/join.d.ts +2 -0
  196. package/typings/specifications/link.d.cts +61 -0
  197. package/typings/specifications/link.d.ts +61 -0
  198. package/typings/specifications/tag.d.cts +4 -0
  199. package/typings/specifications/tag.d.ts +4 -0
  200. package/typings/subgraph/helpers.d.cts +44 -0
  201. package/typings/subgraph/helpers.d.ts +44 -0
  202. package/typings/subgraph/state.d.cts +322 -0
  203. package/typings/subgraph/state.d.ts +322 -0
  204. package/typings/subgraph/validation/rules/elements/compose-directive.d.cts +4 -0
  205. package/typings/subgraph/validation/rules/elements/compose-directive.d.ts +4 -0
  206. package/typings/subgraph/validation/rules/elements/extends.d.cts +4 -0
  207. package/typings/subgraph/validation/rules/elements/extends.d.ts +4 -0
  208. package/typings/subgraph/validation/rules/elements/external.d.cts +4 -0
  209. package/typings/subgraph/validation/rules/elements/external.d.ts +4 -0
  210. package/typings/subgraph/validation/rules/elements/field-set.d.cts +4 -0
  211. package/typings/subgraph/validation/rules/elements/field-set.d.ts +4 -0
  212. package/typings/subgraph/validation/rules/elements/inaccessible.d.cts +4 -0
  213. package/typings/subgraph/validation/rules/elements/inaccessible.d.ts +4 -0
  214. package/typings/subgraph/validation/rules/elements/key.d.cts +4 -0
  215. package/typings/subgraph/validation/rules/elements/key.d.ts +4 -0
  216. package/typings/subgraph/validation/rules/elements/override.d.cts +4 -0
  217. package/typings/subgraph/validation/rules/elements/override.d.ts +4 -0
  218. package/typings/subgraph/validation/rules/elements/provides.d.cts +4 -0
  219. package/typings/subgraph/validation/rules/elements/provides.d.ts +4 -0
  220. package/typings/subgraph/validation/rules/elements/requires.d.cts +4 -0
  221. package/typings/subgraph/validation/rules/elements/requires.d.ts +4 -0
  222. package/typings/subgraph/validation/rules/elements/shareable.d.cts +4 -0
  223. package/typings/subgraph/validation/rules/elements/shareable.d.ts +4 -0
  224. package/typings/subgraph/validation/rules/elements/tag.d.cts +4 -0
  225. package/typings/subgraph/validation/rules/elements/tag.d.ts +4 -0
  226. package/typings/subgraph/validation/rules/known-argument-names-on-directives-rule.d.cts +6 -0
  227. package/typings/subgraph/validation/rules/known-argument-names-on-directives-rule.d.ts +6 -0
  228. package/typings/subgraph/validation/rules/known-directives-rule.d.cts +6 -0
  229. package/typings/subgraph/validation/rules/known-directives-rule.d.ts +6 -0
  230. package/typings/subgraph/validation/rules/known-federation-directive-rule.d.cts +4 -0
  231. package/typings/subgraph/validation/rules/known-federation-directive-rule.d.ts +4 -0
  232. package/typings/subgraph/validation/rules/known-root-type-rule.d.cts +4 -0
  233. package/typings/subgraph/validation/rules/known-root-type-rule.d.ts +4 -0
  234. package/typings/subgraph/validation/rules/known-type-names-rule.d.cts +4 -0
  235. package/typings/subgraph/validation/rules/known-type-names-rule.d.ts +4 -0
  236. package/typings/subgraph/validation/rules/lone-schema-definition-rule.d.cts +5 -0
  237. package/typings/subgraph/validation/rules/lone-schema-definition-rule.d.ts +5 -0
  238. package/typings/subgraph/validation/rules/provided-arguments-on-directives-rule.d.cts +4 -0
  239. package/typings/subgraph/validation/rules/provided-arguments-on-directives-rule.d.ts +4 -0
  240. package/typings/subgraph/validation/rules/provided-required-arguments-on-directives-rule.d.cts +4 -0
  241. package/typings/subgraph/validation/rules/provided-required-arguments-on-directives-rule.d.ts +4 -0
  242. package/typings/subgraph/validation/rules/query-root-type-inaccessible-rule.d.cts +4 -0
  243. package/typings/subgraph/validation/rules/query-root-type-inaccessible-rule.d.ts +4 -0
  244. package/typings/subgraph/validation/rules/reserved-subgraph-name-rule.d.cts +4 -0
  245. package/typings/subgraph/validation/rules/reserved-subgraph-name-rule.d.ts +4 -0
  246. package/typings/subgraph/validation/rules/root-type-used-rule.d.cts +4 -0
  247. package/typings/subgraph/validation/rules/root-type-used-rule.d.ts +4 -0
  248. package/typings/subgraph/validation/rules/unique-argument-definition-names-rule.d.cts +5 -0
  249. package/typings/subgraph/validation/rules/unique-argument-definition-names-rule.d.ts +5 -0
  250. package/typings/subgraph/validation/rules/unique-argument-names-rule.d.cts +5 -0
  251. package/typings/subgraph/validation/rules/unique-argument-names-rule.d.ts +5 -0
  252. package/typings/subgraph/validation/rules/unique-directive-names-rule.d.cts +5 -0
  253. package/typings/subgraph/validation/rules/unique-directive-names-rule.d.ts +5 -0
  254. package/typings/subgraph/validation/rules/unique-directives-per-location-rule.d.cts +6 -0
  255. package/typings/subgraph/validation/rules/unique-directives-per-location-rule.d.ts +6 -0
  256. package/typings/subgraph/validation/rules/unique-enum-value-names-rule.d.cts +5 -0
  257. package/typings/subgraph/validation/rules/unique-enum-value-names-rule.d.ts +5 -0
  258. package/typings/subgraph/validation/rules/unique-field-definition-names-rule.d.cts +5 -0
  259. package/typings/subgraph/validation/rules/unique-field-definition-names-rule.d.ts +5 -0
  260. package/typings/subgraph/validation/rules/unique-input-field-names-rule.d.cts +5 -0
  261. package/typings/subgraph/validation/rules/unique-input-field-names-rule.d.ts +5 -0
  262. package/typings/subgraph/validation/rules/unique-operation-types-rule.d.cts +5 -0
  263. package/typings/subgraph/validation/rules/unique-operation-types-rule.d.ts +5 -0
  264. package/typings/subgraph/validation/rules/unique-type-names-rule.d.cts +5 -0
  265. package/typings/subgraph/validation/rules/unique-type-names-rule.d.ts +5 -0
  266. package/typings/subgraph/validation/validate-state.d.cts +13 -0
  267. package/typings/subgraph/validation/validate-state.d.ts +13 -0
  268. package/typings/subgraph/validation/validate-subgraph.d.cts +43 -0
  269. package/typings/subgraph/validation/validate-subgraph.d.ts +43 -0
  270. package/typings/subgraph/validation/validation-context.d.cts +182 -0
  271. package/typings/subgraph/validation/validation-context.d.ts +182 -0
  272. package/typings/supergraph/composition/ast.d.cts +216 -0
  273. package/typings/supergraph/composition/ast.d.ts +216 -0
  274. package/typings/supergraph/composition/common.d.cts +19 -0
  275. package/typings/supergraph/composition/common.d.ts +19 -0
  276. package/typings/supergraph/composition/directive.d.cts +32 -0
  277. package/typings/supergraph/composition/directive.d.ts +32 -0
  278. package/typings/supergraph/composition/enum-type.d.cts +32 -0
  279. package/typings/supergraph/composition/enum-type.d.ts +32 -0
  280. package/typings/supergraph/composition/input-object-type.d.cts +32 -0
  281. package/typings/supergraph/composition/input-object-type.d.ts +32 -0
  282. package/typings/supergraph/composition/interface-type.d.cts +61 -0
  283. package/typings/supergraph/composition/interface-type.d.ts +61 -0
  284. package/typings/supergraph/composition/object-type.d.cts +79 -0
  285. package/typings/supergraph/composition/object-type.d.ts +79 -0
  286. package/typings/supergraph/composition/scalar-type.d.cts +20 -0
  287. package/typings/supergraph/composition/scalar-type.d.ts +20 -0
  288. package/typings/supergraph/composition/union-type.d.cts +17 -0
  289. package/typings/supergraph/composition/union-type.d.ts +17 -0
  290. package/typings/supergraph/composition/visitor.d.cts +18 -0
  291. package/typings/supergraph/composition/visitor.d.ts +18 -0
  292. package/typings/supergraph/state.d.cts +51 -0
  293. package/typings/supergraph/state.d.ts +51 -0
  294. package/typings/supergraph/validation/rules/default-value-uses-inaccessible-rule.d.cts +5 -0
  295. package/typings/supergraph/validation/rules/default-value-uses-inaccessible-rule.d.ts +5 -0
  296. package/typings/supergraph/validation/rules/directive-composition-rule.d.cts +5 -0
  297. package/typings/supergraph/validation/rules/directive-composition-rule.d.ts +5 -0
  298. package/typings/supergraph/validation/rules/enum-values-rule.d.cts +4 -0
  299. package/typings/supergraph/validation/rules/enum-values-rule.d.ts +4 -0
  300. package/typings/supergraph/validation/rules/extension-with-base.d.cts +4 -0
  301. package/typings/supergraph/validation/rules/extension-with-base.d.ts +4 -0
  302. package/typings/supergraph/validation/rules/external-argument-missing-rule.d.cts +4 -0
  303. package/typings/supergraph/validation/rules/external-argument-missing-rule.d.ts +4 -0
  304. package/typings/supergraph/validation/rules/external-missing-on-base-rule.d.cts +4 -0
  305. package/typings/supergraph/validation/rules/external-missing-on-base-rule.d.ts +4 -0
  306. package/typings/supergraph/validation/rules/external-type-mismatch-rule.d.cts +4 -0
  307. package/typings/supergraph/validation/rules/external-type-mismatch-rule.d.ts +4 -0
  308. package/typings/supergraph/validation/rules/field-argument-default-mismatch-rule.d.cts +4 -0
  309. package/typings/supergraph/validation/rules/field-argument-default-mismatch-rule.d.ts +4 -0
  310. package/typings/supergraph/validation/rules/field-arguments-of-the-same-type-rule.d.cts +4 -0
  311. package/typings/supergraph/validation/rules/field-arguments-of-the-same-type-rule.d.ts +4 -0
  312. package/typings/supergraph/validation/rules/fields-of-the-same-type-rule.d.cts +4 -0
  313. package/typings/supergraph/validation/rules/fields-of-the-same-type-rule.d.ts +4 -0
  314. package/typings/supergraph/validation/rules/input-field-default-mismatch-rule.d.cts +4 -0
  315. package/typings/supergraph/validation/rules/input-field-default-mismatch-rule.d.ts +4 -0
  316. package/typings/supergraph/validation/rules/input-object-values-rule.d.cts +4 -0
  317. package/typings/supergraph/validation/rules/input-object-values-rule.d.ts +4 -0
  318. package/typings/supergraph/validation/rules/interface-key-missing-implementation-type.d.cts +4 -0
  319. package/typings/supergraph/validation/rules/interface-key-missing-implementation-type.d.ts +4 -0
  320. package/typings/supergraph/validation/rules/invalid-field-sharing-rule.d.cts +4 -0
  321. package/typings/supergraph/validation/rules/invalid-field-sharing-rule.d.ts +4 -0
  322. package/typings/supergraph/validation/rules/only-inaccessible-children-rule.d.cts +4 -0
  323. package/typings/supergraph/validation/rules/only-inaccessible-children-rule.d.ts +4 -0
  324. package/typings/supergraph/validation/rules/override-source-has-override.d.cts +4 -0
  325. package/typings/supergraph/validation/rules/override-source-has-override.d.ts +4 -0
  326. package/typings/supergraph/validation/rules/referenced-inaccessible-rule.d.cts +5 -0
  327. package/typings/supergraph/validation/rules/referenced-inaccessible-rule.d.ts +5 -0
  328. package/typings/supergraph/validation/rules/required-argument-missing-in-some-subgraph-rule.d.cts +4 -0
  329. package/typings/supergraph/validation/rules/required-argument-missing-in-some-subgraph-rule.d.ts +4 -0
  330. package/typings/supergraph/validation/rules/required-input-field-missing-in-some-subgraph-rule.d.cts +4 -0
  331. package/typings/supergraph/validation/rules/required-input-field-missing-in-some-subgraph-rule.d.ts +4 -0
  332. package/typings/supergraph/validation/rules/required-query-rule.d.cts +3 -0
  333. package/typings/supergraph/validation/rules/required-query-rule.d.ts +3 -0
  334. package/typings/supergraph/validation/rules/satisfiablity-rule.d.cts +5 -0
  335. package/typings/supergraph/validation/rules/satisfiablity-rule.d.ts +5 -0
  336. package/typings/supergraph/validation/rules/subgraph-name-rule.d.cts +3 -0
  337. package/typings/supergraph/validation/rules/subgraph-name-rule.d.ts +3 -0
  338. package/typings/supergraph/validation/rules/types-of-the-same-kind-rule.d.cts +3 -0
  339. package/typings/supergraph/validation/rules/types-of-the-same-kind-rule.d.ts +3 -0
  340. package/typings/supergraph/validation/validate-supergraph.d.cts +6 -0
  341. package/typings/supergraph/validation/validate-supergraph.d.ts +6 -0
  342. package/typings/supergraph/validation/validation-context.d.cts +10 -0
  343. package/typings/supergraph/validation/validation-context.d.ts +10 -0
  344. package/typings/types.d.cts +7 -0
  345. package/typings/types.d.ts +7 -0
  346. package/typings/utils/dependency-graph.d.cts +31 -0
  347. package/typings/utils/dependency-graph.d.ts +31 -0
  348. package/typings/utils/format.d.cts +2 -0
  349. package/typings/utils/format.d.ts +2 -0
  350. package/typings/utils/helpers.d.cts +2 -0
  351. package/typings/utils/helpers.d.ts +2 -0
  352. package/typings/utils/state.d.cts +6 -0
  353. package/typings/utils/state.d.ts +6 -0
  354. package/typings/validate.d.cts +37 -0
  355. package/typings/validate.d.ts +37 -0
@@ -0,0 +1,115 @@
1
+ import { GraphQLError, Kind } from 'graphql';
2
+ import { print } from '../../../../graphql/printer.js';
3
+ import { getFieldsArgument, parseFields, validateDirectiveAgainstOriginal, visitFields, } from '../../../helpers.js';
4
+ export function RequiresRules(context) {
5
+ return {
6
+ DirectiveDefinition(node) {
7
+ validateDirectiveAgainstOriginal(node, 'requires', context);
8
+ },
9
+ Directive(directiveNode) {
10
+ if (!context.isAvailableFederationDirective('requires', directiveNode)) {
11
+ return;
12
+ }
13
+ const annotatedType = context.typeNodeInfo.getTypeDef();
14
+ const annotatedField = context.typeNodeInfo.getFieldDef();
15
+ if (!annotatedType || !annotatedField) {
16
+ return;
17
+ }
18
+ const fieldCoordinate = `${annotatedType.name.value}.${annotatedField.name.value}`;
19
+ const usedOnInterface = annotatedType.kind === Kind.INTERFACE_TYPE_DEFINITION ||
20
+ annotatedType?.kind === Kind.INTERFACE_TYPE_EXTENSION;
21
+ if (annotatedField && usedOnInterface) {
22
+ context.reportError(new GraphQLError(`Cannot use @requires on field "${fieldCoordinate}" of parent type "${annotatedType.name.value}": @requires is not yet supported within interfaces`, {
23
+ nodes: directiveNode,
24
+ extensions: { code: 'REQUIRES_UNSUPPORTED_ON_INTERFACE' },
25
+ }));
26
+ return;
27
+ }
28
+ const fieldsArg = getFieldsArgument(directiveNode);
29
+ if (!fieldsArg) {
30
+ return;
31
+ }
32
+ const printedFieldsValue = print(fieldsArg.value);
33
+ if (fieldsArg.value.kind !== Kind.STRING) {
34
+ context.reportError(new GraphQLError(`On field "${fieldCoordinate}", for @requires(fields: ${printedFieldsValue}): Invalid value for argument "fields": must be a string.`, {
35
+ nodes: directiveNode,
36
+ extensions: {
37
+ code: 'REQUIRES_INVALID_FIELDS_TYPE',
38
+ },
39
+ }));
40
+ return;
41
+ }
42
+ let selectionSet;
43
+ try {
44
+ selectionSet = parseFields(fieldsArg.value.value);
45
+ }
46
+ catch (error) {
47
+ if (error instanceof GraphQLError) {
48
+ context.reportError(new GraphQLError(`On field "${fieldCoordinate}", for @requires(fields: ${printedFieldsValue}): ${error.message}`, {
49
+ nodes: directiveNode,
50
+ extensions: {
51
+ code: 'REQUIRES_INVALID_FIELDS',
52
+ },
53
+ }));
54
+ return;
55
+ }
56
+ throw error;
57
+ }
58
+ if (!selectionSet) {
59
+ return;
60
+ }
61
+ let isValid = true;
62
+ if (annotatedType.kind !== Kind.INTERFACE_TYPE_DEFINITION &&
63
+ annotatedType.kind !== Kind.INTERFACE_TYPE_EXTENSION &&
64
+ annotatedType.kind !== Kind.OBJECT_TYPE_DEFINITION &&
65
+ annotatedType.kind !== Kind.OBJECT_TYPE_EXTENSION) {
66
+ return;
67
+ }
68
+ visitFields({
69
+ context,
70
+ selectionSet,
71
+ typeDefinition: annotatedType,
72
+ interceptField(info) {
73
+ if (info.typeDefinition.kind === Kind.OBJECT_TYPE_DEFINITION ||
74
+ info.typeDefinition.kind === Kind.OBJECT_TYPE_EXTENSION) {
75
+ context.stateBuilder.objectType.field.markedAsRequired(info.typeDefinition.name.value, info.fieldName);
76
+ }
77
+ },
78
+ interceptUnknownField(info) {
79
+ isValid = false;
80
+ context.reportError(new GraphQLError(`On field "${fieldCoordinate}", for @requires(fields: ${printedFieldsValue}): Cannot query field "${info.fieldName}" on type "${info.typeDefinition.name.value}" (if the field is defined in another subgraph, you need to add it to this subgraph with @external).`, { nodes: directiveNode, extensions: { code: 'REQUIRES_INVALID_FIELDS' } }));
81
+ },
82
+ interceptDirective(info) {
83
+ isValid = false;
84
+ if (info.isKnown) {
85
+ context.reportError(new GraphQLError(`On field "${fieldCoordinate}", for @requires(fields: ${printedFieldsValue}): cannot have directive applications in the @requires(fields:) argument but found @${info.directiveName}.`, {
86
+ nodes: directiveNode,
87
+ extensions: { code: 'REQUIRES_DIRECTIVE_IN_FIELDS_ARG' },
88
+ }));
89
+ }
90
+ else {
91
+ context.reportError(new GraphQLError(`On field "${fieldCoordinate}", for @requires(fields: ${printedFieldsValue}): Unknown directive "@${info.directiveName}" in selection`, {
92
+ nodes: directiveNode,
93
+ extensions: { code: 'REQUIRES_INVALID_FIELDS' },
94
+ }));
95
+ }
96
+ },
97
+ interceptNonExternalField(info) {
98
+ isValid = false;
99
+ context.reportError(new GraphQLError(`On field "${fieldCoordinate}", for @requires(fields: ${printedFieldsValue}): field "${info.typeDefinition.name.value}.${info.fieldName}" should not be part of a @requires since it is already provided by this subgraph (it is not marked @external)`, {
100
+ extensions: {
101
+ code: 'REQUIRES_FIELDS_MISSING_EXTERNAL',
102
+ },
103
+ }));
104
+ },
105
+ });
106
+ if (isValid) {
107
+ if (usedOnInterface) {
108
+ context.stateBuilder.interfaceType.field.setRequires(annotatedType.name.value, annotatedField.name.value, fieldsArg.value.value);
109
+ return;
110
+ }
111
+ context.stateBuilder.objectType.field.setRequires(annotatedType.name.value, annotatedField.name.value, fieldsArg.value.value);
112
+ }
113
+ },
114
+ };
115
+ }
@@ -0,0 +1,39 @@
1
+ import { GraphQLError, Kind } from 'graphql';
2
+ import { validateDirectiveAgainstOriginal } from '../../../helpers.js';
3
+ export function ShareableRules(context) {
4
+ return {
5
+ DirectiveDefinition(node) {
6
+ validateDirectiveAgainstOriginal(node, 'shareable', context);
7
+ },
8
+ Directive(node) {
9
+ if (!context.isAvailableFederationDirective('shareable', node)) {
10
+ return;
11
+ }
12
+ const typeDef = context.typeNodeInfo.getTypeDef();
13
+ const fieldDef = context.typeNodeInfo.getFieldDef();
14
+ if (!typeDef) {
15
+ return;
16
+ }
17
+ if (typeDef.kind === Kind.OBJECT_TYPE_DEFINITION ||
18
+ typeDef.kind === Kind.OBJECT_TYPE_EXTENSION) {
19
+ if (fieldDef) {
20
+ context.stateBuilder.objectType.field.setShareable(typeDef.name.value, fieldDef.name.value);
21
+ }
22
+ else {
23
+ context.stateBuilder.objectType.setShareable(typeDef.name.value);
24
+ }
25
+ }
26
+ if (!fieldDef) {
27
+ return;
28
+ }
29
+ if (typeDef.kind === Kind.INTERFACE_TYPE_DEFINITION ||
30
+ typeDef.kind === Kind.INTERFACE_TYPE_EXTENSION) {
31
+ context.reportError(new GraphQLError(`Invalid use of @shareable on field "${typeDef.name.value}.${fieldDef.name.value}": only object type fields can be marked with @shareable`, {
32
+ nodes: node,
33
+ extensions: { code: 'INVALID_SHAREABLE_USAGE' },
34
+ }));
35
+ return;
36
+ }
37
+ },
38
+ };
39
+ }
@@ -0,0 +1,116 @@
1
+ import { Kind } from 'graphql';
2
+ import { validateDirectiveAgainstOriginal } from '../../../helpers.js';
3
+ export function TagRules(context) {
4
+ return {
5
+ DirectiveDefinition(node) {
6
+ validateDirectiveAgainstOriginal(node, 'tag', context);
7
+ },
8
+ Directive(node, _key, _parent, paths, ancestors) {
9
+ if (!context.isAvailableFederationDirective('tag', node)) {
10
+ return;
11
+ }
12
+ const nameArg = node.arguments?.find(arg => arg.name.value === 'name');
13
+ if (!nameArg) {
14
+ throw new Error('Expected @tag to have a "name" argument');
15
+ }
16
+ if (nameArg.value.kind !== Kind.STRING) {
17
+ throw new Error('Expected "@tag(name:)" to be a string');
18
+ }
19
+ const directivesKeyAt = paths.findIndex(path => path === 'directives');
20
+ if (directivesKeyAt === -1) {
21
+ throw new Error('Could not find "directives" key in ancestors');
22
+ }
23
+ const parent = ancestors[directivesKeyAt];
24
+ if (!parent) {
25
+ throw new Error('Could not find the node annotated with @inaccessible');
26
+ }
27
+ if (Array.isArray(parent)) {
28
+ throw new Error('Expected parent to be a single node');
29
+ }
30
+ if (!('kind' in parent)) {
31
+ throw new Error('Expected parent to be a node');
32
+ }
33
+ const tag = nameArg.value.value;
34
+ switch (parent.kind) {
35
+ case Kind.SCALAR_TYPE_DEFINITION:
36
+ case Kind.SCALAR_TYPE_EXTENSION:
37
+ context.stateBuilder.scalarType.setTag(parent.name.value, tag);
38
+ break;
39
+ case Kind.FIELD_DEFINITION: {
40
+ const typeDef = context.typeNodeInfo.getTypeDef();
41
+ if (!typeDef) {
42
+ throw new Error('Could not find the parent type of the field annotated with @tag');
43
+ }
44
+ if (typeDef.kind === Kind.INTERFACE_TYPE_DEFINITION ||
45
+ typeDef.kind === Kind.INTERFACE_TYPE_EXTENSION) {
46
+ context.stateBuilder.interfaceType.field.setTag(typeDef.name.value, parent.name.value, tag);
47
+ }
48
+ else {
49
+ context.stateBuilder.objectType.field.setTag(typeDef.name.value, parent.name.value, tag);
50
+ }
51
+ break;
52
+ }
53
+ case Kind.INPUT_VALUE_DEFINITION: {
54
+ const typeDef = context.typeNodeInfo.getTypeDef();
55
+ if (!typeDef) {
56
+ throw new Error('Could not find the parent type of the field annotated with @tag');
57
+ }
58
+ if (typeDef.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION ||
59
+ typeDef.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION) {
60
+ context.stateBuilder.inputObjectType.field.setTag(typeDef.name.value, parent.name.value, tag);
61
+ }
62
+ else if (typeDef.kind === Kind.OBJECT_TYPE_DEFINITION ||
63
+ typeDef.kind === Kind.OBJECT_TYPE_EXTENSION) {
64
+ const fieldDef = context.typeNodeInfo.getFieldDef();
65
+ if (!fieldDef) {
66
+ throw new Error('Could not find the parent field of the input value annotated with @tag');
67
+ }
68
+ context.stateBuilder.objectType.field.arg.setTag(typeDef.name.value, fieldDef.name.value, parent.name.value, tag);
69
+ }
70
+ else if (typeDef.kind === Kind.INTERFACE_TYPE_DEFINITION ||
71
+ typeDef.kind === Kind.INTERFACE_TYPE_EXTENSION) {
72
+ const fieldDef = context.typeNodeInfo.getFieldDef();
73
+ if (!fieldDef) {
74
+ throw new Error('Could not find the parent field of the input value annotated with @tag');
75
+ }
76
+ context.stateBuilder.interfaceType.field.arg.setTag(typeDef.name.value, fieldDef.name.value, parent.name.value, tag);
77
+ }
78
+ else if (typeDef.kind === Kind.DIRECTIVE_DEFINITION) {
79
+ context.stateBuilder.directive.arg.setTag(typeDef.name.value, parent.name.value, tag);
80
+ }
81
+ break;
82
+ }
83
+ case Kind.OBJECT_TYPE_DEFINITION:
84
+ case Kind.OBJECT_TYPE_EXTENSION:
85
+ context.stateBuilder.objectType.setTag(parent.name.value, tag);
86
+ break;
87
+ case Kind.INTERFACE_TYPE_DEFINITION:
88
+ case Kind.INTERFACE_TYPE_EXTENSION:
89
+ context.stateBuilder.interfaceType.setTag(parent.name.value, tag);
90
+ break;
91
+ case Kind.UNION_TYPE_DEFINITION:
92
+ case Kind.UNION_TYPE_EXTENSION:
93
+ context.stateBuilder.unionType.setTag(parent.name.value, tag);
94
+ break;
95
+ case Kind.INPUT_OBJECT_TYPE_DEFINITION:
96
+ case Kind.INPUT_OBJECT_TYPE_EXTENSION:
97
+ context.stateBuilder.inputObjectType.setTag(parent.name.value, tag);
98
+ break;
99
+ case Kind.ENUM_TYPE_DEFINITION:
100
+ case Kind.ENUM_TYPE_EXTENSION:
101
+ context.stateBuilder.enumType.setTag(parent.name.value, tag);
102
+ break;
103
+ case Kind.ENUM_VALUE_DEFINITION: {
104
+ const enumValue = parent.name.value;
105
+ const typeDef = context.typeNodeInfo.getTypeDef();
106
+ if (!typeDef) {
107
+ throw new Error('Could not find the parent type of the enum value annotated with @tag');
108
+ }
109
+ context.stateBuilder.enumType.value.setTag(typeDef.name.value, enumValue, tag);
110
+ break;
111
+ }
112
+ }
113
+ context.stateBuilder.markSpecAsUsed('tag');
114
+ },
115
+ };
116
+ }
@@ -0,0 +1,30 @@
1
+ import { GraphQLError, Kind } from 'graphql';
2
+ export function KnownArgumentNamesOnDirectivesRule(context) {
3
+ const directiveArgs = new Map();
4
+ const astDefinitions = context.getDocument().definitions;
5
+ for (const def of astDefinitions) {
6
+ if (def.kind === Kind.DIRECTIVE_DEFINITION) {
7
+ const argsNodes = def.arguments ?? [];
8
+ directiveArgs.set(def.name.value, new Set(argsNodes.map(arg => arg.name.value)));
9
+ }
10
+ }
11
+ return {
12
+ Directive(directiveNode) {
13
+ const directiveName = directiveNode.name.value;
14
+ const knownArgs = directiveArgs.get(directiveName);
15
+ if (directiveNode.arguments && knownArgs) {
16
+ for (const argNode of directiveNode.arguments) {
17
+ const argName = argNode.name.value;
18
+ if (!knownArgs.has(argName)) {
19
+ context.reportError(new GraphQLError(`Unknown argument "${argName}" on directive "@${directiveName}".`, {
20
+ nodes: argNode,
21
+ extensions: {
22
+ code: 'INVALID_GRAPHQL',
23
+ },
24
+ }));
25
+ }
26
+ }
27
+ }
28
+ },
29
+ };
30
+ }
@@ -0,0 +1,101 @@
1
+ import { DirectiveLocation, GraphQLError, Kind, OperationTypeNode, specifiedDirectives, } from 'graphql';
2
+ export function KnownDirectivesRule(context) {
3
+ const locationsMap = new Map();
4
+ const astDefinitions = context.getDocument().definitions;
5
+ for (const def of astDefinitions) {
6
+ if (def.kind === Kind.DIRECTIVE_DEFINITION) {
7
+ locationsMap.set(def.name.value, new Set(def.locations.map(name => name.value)));
8
+ }
9
+ }
10
+ for (const specifiedDirective of specifiedDirectives) {
11
+ locationsMap.set(specifiedDirective.name, new Set(specifiedDirective.locations.map(loc => String(loc))));
12
+ }
13
+ return {
14
+ Directive(node, _key, _parent, _path, ancestors) {
15
+ const name = node.name.value;
16
+ const locations = locationsMap.get(name);
17
+ if (!locations) {
18
+ context.reportError(new GraphQLError(`Unknown directive "@${name}".`, {
19
+ nodes: node,
20
+ extensions: {
21
+ code: 'INVALID_GRAPHQL',
22
+ },
23
+ }));
24
+ return;
25
+ }
26
+ const candidateLocation = getDirectiveLocationForASTPath(ancestors);
27
+ if (candidateLocation && !locations.has(candidateLocation)) {
28
+ context.reportError(new GraphQLError(`Directive "@${name}" may not be used on ${candidateLocation}.`, {
29
+ nodes: node,
30
+ extensions: {
31
+ code: 'INVALID_GRAPHQL',
32
+ },
33
+ }));
34
+ }
35
+ },
36
+ };
37
+ }
38
+ function getDirectiveLocationForASTPath(ancestors) {
39
+ const appliedTo = ancestors[ancestors.length - 1];
40
+ if (!('kind' in appliedTo)) {
41
+ throw new Error('Expected a node');
42
+ }
43
+ switch (appliedTo.kind) {
44
+ case Kind.OPERATION_DEFINITION:
45
+ return getDirectiveLocationForOperation(appliedTo.operation);
46
+ case Kind.FIELD:
47
+ return DirectiveLocation.FIELD;
48
+ case Kind.FRAGMENT_SPREAD:
49
+ return DirectiveLocation.FRAGMENT_SPREAD;
50
+ case Kind.INLINE_FRAGMENT:
51
+ return DirectiveLocation.INLINE_FRAGMENT;
52
+ case Kind.FRAGMENT_DEFINITION:
53
+ return DirectiveLocation.FRAGMENT_DEFINITION;
54
+ case Kind.VARIABLE_DEFINITION:
55
+ return DirectiveLocation.VARIABLE_DEFINITION;
56
+ case Kind.SCHEMA_DEFINITION:
57
+ case Kind.SCHEMA_EXTENSION:
58
+ return DirectiveLocation.SCHEMA;
59
+ case Kind.SCALAR_TYPE_DEFINITION:
60
+ case Kind.SCALAR_TYPE_EXTENSION:
61
+ return DirectiveLocation.SCALAR;
62
+ case Kind.OBJECT_TYPE_DEFINITION:
63
+ case Kind.OBJECT_TYPE_EXTENSION:
64
+ return DirectiveLocation.OBJECT;
65
+ case Kind.FIELD_DEFINITION:
66
+ return DirectiveLocation.FIELD_DEFINITION;
67
+ case Kind.INTERFACE_TYPE_DEFINITION:
68
+ case Kind.INTERFACE_TYPE_EXTENSION:
69
+ return DirectiveLocation.INTERFACE;
70
+ case Kind.UNION_TYPE_DEFINITION:
71
+ case Kind.UNION_TYPE_EXTENSION:
72
+ return DirectiveLocation.UNION;
73
+ case Kind.ENUM_TYPE_DEFINITION:
74
+ case Kind.ENUM_TYPE_EXTENSION:
75
+ return DirectiveLocation.ENUM;
76
+ case Kind.ENUM_VALUE_DEFINITION:
77
+ return DirectiveLocation.ENUM_VALUE;
78
+ case Kind.INPUT_OBJECT_TYPE_DEFINITION:
79
+ case Kind.INPUT_OBJECT_TYPE_EXTENSION:
80
+ return DirectiveLocation.INPUT_OBJECT;
81
+ case Kind.INPUT_VALUE_DEFINITION: {
82
+ const parentNode = ancestors[ancestors.length - 3];
83
+ if (!('kind' in parentNode)) {
84
+ throw new Error('Expected a node');
85
+ }
86
+ return parentNode.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION
87
+ ? DirectiveLocation.INPUT_FIELD_DEFINITION
88
+ : DirectiveLocation.ARGUMENT_DEFINITION;
89
+ }
90
+ }
91
+ }
92
+ function getDirectiveLocationForOperation(operation) {
93
+ switch (operation) {
94
+ case OperationTypeNode.QUERY:
95
+ return DirectiveLocation.QUERY;
96
+ case OperationTypeNode.MUTATION:
97
+ return DirectiveLocation.MUTATION;
98
+ case OperationTypeNode.SUBSCRIPTION:
99
+ return DirectiveLocation.SUBSCRIPTION;
100
+ }
101
+ }
@@ -0,0 +1,30 @@
1
+ import { GraphQLError, Kind } from 'graphql';
2
+ export function KnownFederationDirectivesRule(context) {
3
+ const availableDirectivesSet = new Set();
4
+ const knownDirectivesSet = new Set();
5
+ const knownDirectives = context.getKnownFederationDirectives();
6
+ for (const directive of knownDirectives) {
7
+ knownDirectivesSet.add(directive.name.value);
8
+ }
9
+ const availableDirectives = context.getAvailableFederationDirectives();
10
+ for (const directive of availableDirectives) {
11
+ availableDirectivesSet.add(directive.name.value);
12
+ }
13
+ const astDefinitions = context.getDocument().definitions;
14
+ for (const def of astDefinitions) {
15
+ if (def.kind === Kind.DIRECTIVE_DEFINITION) {
16
+ availableDirectivesSet.add(def.name.value);
17
+ }
18
+ }
19
+ return {
20
+ Directive(node) {
21
+ const name = node.name.value;
22
+ if (!availableDirectivesSet.has(name) &&
23
+ knownDirectivesSet.has(name) &&
24
+ !name.startsWith('federation__')) {
25
+ context.reportError(new GraphQLError(`Unknown directive "@${name}". If you meant the "@${name}" federation directive, you should use fully-qualified name "@federation__${name}" or add "@${name}" to the \`import\` argument of the @link to the federation specification.`, { nodes: node, extensions: { code: 'INVALID_GRAPHQL' } }));
26
+ return;
27
+ }
28
+ },
29
+ };
30
+ }
@@ -0,0 +1,21 @@
1
+ import { GraphQLError, isTypeDefinitionNode, isTypeExtensionNode, } from 'graphql';
2
+ export function KnownRootTypeRule(context) {
3
+ const { definitions } = context.getDocument();
4
+ const typeNames = new Set(definitions.filter(isTypeDefinitionOrExtensionNode).map(def => def.name.value));
5
+ return {
6
+ SchemaDefinition(node) {
7
+ node.operationTypes.forEach(operationType => {
8
+ if (!typeNames.has(operationType.type.name.value)) {
9
+ context.reportError(new GraphQLError(`Cannot set schema ${operationType.operation} root to unknown type ${operationType.type.name.value}`, {
10
+ extensions: {
11
+ code: 'INVALID_GRAPHQL',
12
+ },
13
+ }));
14
+ }
15
+ });
16
+ },
17
+ };
18
+ }
19
+ function isTypeDefinitionOrExtensionNode(node) {
20
+ return isTypeDefinitionNode(node) || isTypeExtensionNode(node);
21
+ }
@@ -0,0 +1,30 @@
1
+ import { GraphQLError, isTypeDefinitionNode, isTypeExtensionNode, isTypeSystemDefinitionNode, isTypeSystemExtensionNode, specifiedScalarTypes, } from 'graphql';
2
+ function isTypeDefinitionOrExtensionNode(node) {
3
+ return isTypeDefinitionNode(node) || isTypeExtensionNode(node);
4
+ }
5
+ export function KnownTypeNamesRule(context) {
6
+ const { definitions } = context.getDocument();
7
+ const typeNames = new Set(definitions.filter(isTypeDefinitionOrExtensionNode).map(def => def.name.value));
8
+ return {
9
+ NamedType(node, _1, parent, _2, ancestors) {
10
+ const typeName = node.name.value;
11
+ if (!typeNames.has(typeName)) {
12
+ const definitionNode = ancestors[2] ?? parent;
13
+ const isSDL = definitionNode != null && isSDLNode(definitionNode);
14
+ if (isSDL && standardTypeNames.has(typeName)) {
15
+ return;
16
+ }
17
+ context.reportError(new GraphQLError(`Unknown type ${typeName}`, {
18
+ nodes: node,
19
+ extensions: {
20
+ code: 'INVALID_GRAPHQL',
21
+ },
22
+ }));
23
+ }
24
+ },
25
+ };
26
+ }
27
+ const standardTypeNames = new Set([...specifiedScalarTypes].map(type => type.name));
28
+ function isSDLNode(value) {
29
+ return 'kind' in value && (isTypeSystemDefinitionNode(value) || isTypeSystemExtensionNode(value));
30
+ }
@@ -0,0 +1,16 @@
1
+ import { GraphQLError } from 'graphql';
2
+ export function LoneSchemaDefinitionRule(context) {
3
+ let schemaDefinitionsCount = 0;
4
+ return {
5
+ SchemaDefinition() {
6
+ if (schemaDefinitionsCount > 0) {
7
+ context.reportError(new GraphQLError('Must provide only one schema definition.', {
8
+ extensions: {
9
+ code: 'INVALID_GRAPHQL',
10
+ },
11
+ }));
12
+ }
13
+ ++schemaDefinitionsCount;
14
+ },
15
+ };
16
+ }
@@ -0,0 +1,100 @@
1
+ import { GraphQLError, Kind, specifiedScalarTypes } from 'graphql';
2
+ import { print } from '../../../graphql/printer.js';
3
+ import { namedTypeFromTypeNode } from '../../helpers.js';
4
+ export function ProvidedArgumentsOnDirectivesRule(context) {
5
+ return {
6
+ Directive: {
7
+ leave(directiveNode, _k, _p, _pp, ancestors) {
8
+ const directiveName = directiveNode.name.value;
9
+ const directiveDefinition = context.getKnownDirectiveDefinition(directiveName);
10
+ if (!directiveDefinition) {
11
+ return;
12
+ }
13
+ const args = directiveNode.arguments;
14
+ if (args && directiveDefinition.arguments) {
15
+ const coordinate = context.getSchemaCoordinate(ancestors);
16
+ for (const arg of args) {
17
+ const argDefinition = directiveDefinition.arguments.find(a => a.name.value === arg.name.value);
18
+ if (argDefinition && arg.value) {
19
+ if (argDefinition.type.kind === Kind.NON_NULL_TYPE && arg.value.kind === Kind.NULL) {
20
+ continue;
21
+ }
22
+ const printedType = printTypeNode(argDefinition.type, context);
23
+ const printedValue = printValueNode(arg.value);
24
+ if (!printedType) {
25
+ continue;
26
+ }
27
+ if (printedType !== 'Any' && printedType !== printedValue) {
28
+ const namedType = namedTypeFromTypeNode(argDefinition.type);
29
+ const typeName = namedType.name.value;
30
+ if (printedValue === 'Int' && typeName === 'Float') {
31
+ continue;
32
+ }
33
+ context.reportError(new GraphQLError(`Invalid value for "@${directiveName}(${arg.name.value}:)" of type "${print(argDefinition.type)}" in application of "@${directiveName}" to "${coordinate}".`, {
34
+ nodes: arg,
35
+ extensions: {
36
+ code: 'INVALID_GRAPHQL',
37
+ },
38
+ }));
39
+ }
40
+ }
41
+ }
42
+ }
43
+ },
44
+ },
45
+ };
46
+ }
47
+ function printValueNode(valueNode) {
48
+ switch (valueNode.kind) {
49
+ case Kind.LIST:
50
+ if (!valueNode.values.length) {
51
+ return '[]';
52
+ }
53
+ return printValueNode(valueNode.values[0]);
54
+ case Kind.ENUM:
55
+ return 'Enum';
56
+ case Kind.NULL:
57
+ return 'Null';
58
+ case Kind.INT:
59
+ return 'Int';
60
+ case Kind.FLOAT:
61
+ return 'Float';
62
+ case Kind.STRING:
63
+ return 'String';
64
+ case Kind.BOOLEAN:
65
+ return 'Boolean';
66
+ case Kind.OBJECT:
67
+ return 'Object';
68
+ }
69
+ throw new Error(`Unknown value node kind: ${valueNode}`);
70
+ }
71
+ function printTypeNode(typeNode, context) {
72
+ if (typeNode.kind === Kind.NAMED_TYPE) {
73
+ const def = context.getKnownTypeDefinition(typeNode.name.value);
74
+ if (!def) {
75
+ const specifiedScalar = specifiedScalarTypes.find(s => s.name === typeNode.name.value);
76
+ if (specifiedScalar) {
77
+ return specifiedScalar.name;
78
+ }
79
+ return null;
80
+ }
81
+ switch (def.kind) {
82
+ case Kind.SCALAR_TYPE_DEFINITION:
83
+ case Kind.SCALAR_TYPE_EXTENSION:
84
+ return 'Any';
85
+ case Kind.ENUM_TYPE_DEFINITION:
86
+ case Kind.ENUM_TYPE_EXTENSION:
87
+ return 'Enum';
88
+ case Kind.INPUT_OBJECT_TYPE_DEFINITION:
89
+ case Kind.INPUT_OBJECT_TYPE_EXTENSION:
90
+ case Kind.OBJECT_TYPE_DEFINITION:
91
+ case Kind.OBJECT_TYPE_EXTENSION:
92
+ case Kind.INTERFACE_TYPE_DEFINITION:
93
+ case Kind.INTERFACE_TYPE_EXTENSION:
94
+ case Kind.UNION_TYPE_DEFINITION:
95
+ case Kind.UNION_TYPE_EXTENSION:
96
+ return 'Object';
97
+ }
98
+ }
99
+ return printTypeNode(typeNode.type, context);
100
+ }
@@ -0,0 +1,42 @@
1
+ import { GraphQLError, Kind } from 'graphql';
2
+ import { print } from '../../../graphql/printer.js';
3
+ export function ProvidedRequiredArgumentsOnDirectivesRule(context) {
4
+ const requiredArgsMap = Object.create(null);
5
+ const astDefinitions = context.getDocument().definitions;
6
+ for (const def of astDefinitions) {
7
+ if (def.kind === Kind.DIRECTIVE_DEFINITION) {
8
+ const argNodes = def.arguments ?? [];
9
+ const requiredArgs = argNodes.filter(isRequiredArgumentNode);
10
+ requiredArgsMap[def.name.value] = {};
11
+ for (const requiredArg of requiredArgs) {
12
+ requiredArgsMap[def.name.value][requiredArg.name.value] = requiredArg;
13
+ }
14
+ }
15
+ }
16
+ return {
17
+ Directive: {
18
+ leave(directiveNode) {
19
+ const directiveName = directiveNode.name.value;
20
+ const requiredArgs = requiredArgsMap[directiveName];
21
+ if (requiredArgs) {
22
+ const argNodes = directiveNode.arguments ?? [];
23
+ const argNodeMap = new Set(argNodes.map(arg => arg.name.value));
24
+ for (const [argName, argDef] of Object.entries(requiredArgs)) {
25
+ if (!argNodeMap.has(argName)) {
26
+ const argType = print(argDef.type);
27
+ context.reportError(new GraphQLError(`Directive "@${directiveName}" argument "${argName}" of type "${argType}" is required, but it was not provided.`, {
28
+ nodes: directiveNode,
29
+ extensions: {
30
+ code: 'INVALID_GRAPHQL',
31
+ },
32
+ }));
33
+ }
34
+ }
35
+ }
36
+ },
37
+ },
38
+ };
39
+ }
40
+ function isRequiredArgumentNode(arg) {
41
+ return arg.type.kind === Kind.NON_NULL_TYPE && arg.defaultValue == null;
42
+ }