@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,249 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSupergraphStateBuilder = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const printer_js_1 = require("../graphql/printer.js");
6
+ const link_js_1 = require("../specifications/link.js");
7
+ const helpers_js_1 = require("../subgraph/helpers.js");
8
+ const ast_js_1 = require("./composition/ast.js");
9
+ const directive_js_1 = require("./composition/directive.js");
10
+ const enum_type_js_1 = require("./composition/enum-type.js");
11
+ const input_object_type_js_1 = require("./composition/input-object-type.js");
12
+ const interface_type_js_1 = require("./composition/interface-type.js");
13
+ const object_type_js_1 = require("./composition/object-type.js");
14
+ const scalar_type_js_1 = require("./composition/scalar-type.js");
15
+ const union_type_js_1 = require("./composition/union-type.js");
16
+ function createSupergraphStateBuilder() {
17
+ const state = {
18
+ graphs: new Map(),
19
+ scalarTypes: new Map(),
20
+ objectTypes: new Map(),
21
+ interfaceTypes: new Map(),
22
+ unionTypes: new Map(),
23
+ enumTypes: new Map(),
24
+ inputObjectTypes: new Map(),
25
+ directives: new Map(),
26
+ links: [],
27
+ specs: {
28
+ tag: false,
29
+ inaccessible: false,
30
+ },
31
+ };
32
+ const directive = (0, directive_js_1.directiveBuilder)();
33
+ const scalarType = (0, scalar_type_js_1.scalarTypeBuilder)();
34
+ const enumType = (0, enum_type_js_1.enumTypeBuilder)();
35
+ const inputObjectType = (0, input_object_type_js_1.inputObjectTypeBuilder)();
36
+ const interfaceType = (0, interface_type_js_1.interfaceTypeBuilder)();
37
+ const objectType = (0, object_type_js_1.objectTypeBuilder)();
38
+ const unionType = (0, union_type_js_1.unionTypeBuilder)();
39
+ return {
40
+ addGraph(graph) {
41
+ if (state.graphs.has(graph.id)) {
42
+ throw new Error(`Graph with ID "${graph.id}" already exists`);
43
+ }
44
+ state.graphs.set(graph.id, {
45
+ id: graph.id,
46
+ name: graph.name,
47
+ url: graph.url,
48
+ version: graph.version,
49
+ });
50
+ },
51
+ getGraph(id) {
52
+ return state.graphs.get(id);
53
+ },
54
+ visitSubgraphState(subgraphState) {
55
+ for (const link of subgraphState.links) {
56
+ state.links.push(linkWithGraph(link, subgraphState.graph.id));
57
+ }
58
+ if (subgraphState.specs.tag) {
59
+ state.specs.tag = true;
60
+ }
61
+ if (subgraphState.specs.inaccessible) {
62
+ state.specs.inaccessible = true;
63
+ }
64
+ for (const [typeName, type] of subgraphState.types) {
65
+ switch (type.kind) {
66
+ case 'OBJECT': {
67
+ objectType.visitSubgraphState(subgraphState.graph, state.objectTypes, typeName, type);
68
+ break;
69
+ }
70
+ case 'INTERFACE': {
71
+ interfaceType.visitSubgraphState(subgraphState.graph, state.interfaceTypes, typeName, type);
72
+ break;
73
+ }
74
+ case 'UNION': {
75
+ unionType.visitSubgraphState(subgraphState.graph, state.unionTypes, typeName, type);
76
+ break;
77
+ }
78
+ case 'ENUM': {
79
+ enumType.visitSubgraphState(subgraphState.graph, state.enumTypes, typeName, type);
80
+ break;
81
+ }
82
+ case 'INPUT_OBJECT': {
83
+ inputObjectType.visitSubgraphState(subgraphState.graph, state.inputObjectTypes, typeName, type);
84
+ break;
85
+ }
86
+ case 'DIRECTIVE': {
87
+ directive.visitSubgraphState(subgraphState.graph, state.directives, typeName, type);
88
+ break;
89
+ }
90
+ case 'SCALAR': {
91
+ scalarType.visitSubgraphState(subgraphState.graph, state.scalarTypes, typeName, type);
92
+ break;
93
+ }
94
+ }
95
+ }
96
+ },
97
+ getSupergraphState() {
98
+ return state;
99
+ },
100
+ links() {
101
+ return (0, link_js_1.mergeLinks)(state.links);
102
+ },
103
+ build() {
104
+ const transformFields = createFieldsTransformer(state);
105
+ const numberOfExpectedNodes = state.directives.size +
106
+ state.scalarTypes.size +
107
+ state.objectTypes.size +
108
+ state.interfaceTypes.size +
109
+ state.unionTypes.size +
110
+ state.enumTypes.size +
111
+ state.inputObjectTypes.size +
112
+ 1;
113
+ const nodes = new Array(numberOfExpectedNodes);
114
+ let i = 0;
115
+ nodes[i++] = (0, ast_js_1.createJoinGraphEnumTypeNode)(Array.from(state.graphs.values()).map(graph => ({
116
+ name: graph.name,
117
+ enumValue: graph.id,
118
+ url: graph.url ?? '',
119
+ })));
120
+ for (const directiveState of state.directives.values()) {
121
+ nodes[i++] = directive.composeSupergraphNode(directiveState, state.graphs);
122
+ }
123
+ for (const scalarTypeState of state.scalarTypes.values()) {
124
+ nodes[i++] = scalarType.composeSupergraphNode(scalarTypeState, state.graphs);
125
+ }
126
+ for (const objectTypeState of state.objectTypes.values()) {
127
+ nodes[i++] = objectType.composeSupergraphNode(transformFields(objectTypeState), state.graphs);
128
+ }
129
+ for (const interfaceTypeState of state.interfaceTypes.values()) {
130
+ nodes[i++] = interfaceType.composeSupergraphNode(interfaceTypeState, state.graphs);
131
+ }
132
+ for (const unionTypeState of state.unionTypes.values()) {
133
+ nodes[i++] = unionType.composeSupergraphNode(unionTypeState, state.graphs);
134
+ }
135
+ for (const enumTypeState of state.enumTypes.values()) {
136
+ nodes[i++] = enumType.composeSupergraphNode(enumTypeState, state.graphs);
137
+ }
138
+ for (const inputObjectTypeState of state.inputObjectTypes.values()) {
139
+ nodes[i++] = inputObjectType.composeSupergraphNode(inputObjectTypeState, state.graphs);
140
+ }
141
+ return nodes;
142
+ },
143
+ };
144
+ }
145
+ exports.createSupergraphStateBuilder = createSupergraphStateBuilder;
146
+ function linkWithGraph(link, graph) {
147
+ link.graph = graph;
148
+ return link;
149
+ }
150
+ function visitSelectionSetNode(selectionSet, locations, currentPath) {
151
+ for (const selection of selectionSet.selections) {
152
+ if (selection.kind === graphql_1.Kind.FIELD) {
153
+ if (selection.selectionSet) {
154
+ visitSelectionSetNode(selection.selectionSet, locations, currentPath.concat(selection.name.value));
155
+ }
156
+ else {
157
+ locations.add(currentPath.concat(selection.name.value).join('.'));
158
+ }
159
+ }
160
+ }
161
+ }
162
+ function createFieldsSet(selectionSet) {
163
+ const locations = new Set();
164
+ visitSelectionSetNode(selectionSet, locations, []);
165
+ return locations;
166
+ }
167
+ function filterSelectionSetNode(selectionSet, removableFields, currentPath) {
168
+ const fieldsToDelete = [];
169
+ for (const selection of selectionSet.selections) {
170
+ if (selection.kind === graphql_1.Kind.FIELD) {
171
+ if (selection.selectionSet) {
172
+ filterSelectionSetNode(selection.selectionSet, removableFields, currentPath + '.' + selection.name.value);
173
+ if (selectionSet.selections.length === 0) {
174
+ fieldsToDelete.push(selection.name.value);
175
+ }
176
+ }
177
+ else {
178
+ const lookingFor = currentPath === '' ? selection.name.value : currentPath + '.' + selection.name.value;
179
+ if (removableFields.has(lookingFor)) {
180
+ fieldsToDelete.push(selection.name.value);
181
+ }
182
+ }
183
+ }
184
+ }
185
+ for (const fieldName of fieldsToDelete) {
186
+ selectionSet.selections = selectionSet.selections.filter(selection => selection.kind === graphql_1.Kind.FIELD && selection.name.value === fieldName ? false : true);
187
+ }
188
+ }
189
+ function createFieldsTransformer(state) {
190
+ function transformFields(removableFields, fields) {
191
+ const parsedFields = (0, helpers_js_1.parseFields)(fields);
192
+ if (!parsedFields) {
193
+ return fields;
194
+ }
195
+ filterSelectionSetNode(parsedFields, removableFields, '');
196
+ const printed = (0, graphql_1.stripIgnoredCharacters)((0, printer_js_1.print)(parsedFields));
197
+ return printed.replace(/^\{/, '').replace(/\}$/, '');
198
+ }
199
+ function mergeKeyFieldsCollection(fieldsCollection) {
200
+ const fieldsSets = [];
201
+ for (const fields of fieldsCollection) {
202
+ const parsedFields = (0, helpers_js_1.parseFields)(fields);
203
+ if (!parsedFields) {
204
+ continue;
205
+ }
206
+ fieldsSets.push(createFieldsSet(parsedFields));
207
+ }
208
+ let commonFields;
209
+ for (const fieldsSet of fieldsSets) {
210
+ if (!commonFields) {
211
+ commonFields = fieldsSet;
212
+ continue;
213
+ }
214
+ for (const field of commonFields) {
215
+ if (!fieldsSet.has(field)) {
216
+ commonFields.delete(field);
217
+ }
218
+ }
219
+ }
220
+ return commonFields ?? new Set();
221
+ }
222
+ return function visitTypeState(typeState) {
223
+ for (const [_, fieldState] of typeState.fields) {
224
+ for (const [graphId, fieldStateInGraph] of fieldState.byGraph) {
225
+ if (fieldStateInGraph.requires) {
226
+ const keyFields = mergeKeyFieldsCollection(typeState.byGraph.get(graphId).keys.map(key => key.fields));
227
+ const newRequires = transformFields(keyFields, fieldStateInGraph.requires);
228
+ fieldStateInGraph.requires = newRequires.trim().length === 0 ? null : newRequires;
229
+ }
230
+ if (fieldStateInGraph.provides) {
231
+ const referencedTypeName = fieldState.type.replace(/[!\[\]]+/g, '');
232
+ const referencedType = state.objectTypes.get(referencedTypeName) ??
233
+ state.interfaceTypes.get(referencedTypeName);
234
+ if (!referencedType) {
235
+ throw new Error('Referenced type not found: ' + referencedTypeName);
236
+ }
237
+ const referencedTypeInGraph = referencedType.byGraph.get(graphId);
238
+ const keyFields = referencedTypeInGraph.extension === true
239
+ ?
240
+ mergeKeyFieldsCollection(referencedTypeInGraph.keys.map(key => key.fields))
241
+ :
242
+ new Set();
243
+ fieldStateInGraph.provides = transformFields(keyFields, fieldStateInGraph.provides);
244
+ }
245
+ }
246
+ }
247
+ return typeState;
248
+ };
249
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultValueUsesInaccessibleRule = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function DefaultValueUsesInaccessibleRule(context, supergraph) {
6
+ return {
7
+ InputObjectTypeField(inputObjectState, fieldState) {
8
+ if (typeof fieldState.defaultValue !== 'string') {
9
+ return;
10
+ }
11
+ detectInaccessibleDefaultValue(context, () => `${inputObjectState.name}.${fieldState.name}`, fieldState.type, fieldState.defaultValue, supergraph.enumTypes);
12
+ },
13
+ ObjectTypeFieldArg(objectState, fieldState, argState) {
14
+ if (typeof argState.defaultValue !== 'string') {
15
+ return;
16
+ }
17
+ detectInaccessibleDefaultValue(context, () => `${objectState.name}.${fieldState.name}(${argState.name}:)`, argState.type, argState.defaultValue, supergraph.enumTypes);
18
+ },
19
+ };
20
+ }
21
+ exports.DefaultValueUsesInaccessibleRule = DefaultValueUsesInaccessibleRule;
22
+ function detectInaccessibleDefaultValue(context, schemaCoordinate, outputType, defaultValue, enumTypes) {
23
+ const outputTypeName = outputType.replace(/[\[\]\!]+/g, '');
24
+ const enumType = enumTypes.get(outputTypeName);
25
+ if (!enumType) {
26
+ return;
27
+ }
28
+ if (enumType.inaccessible === true || enumType.values.get(defaultValue)?.inaccessible === true) {
29
+ context.reportError(new graphql_1.GraphQLError(`Enum value "${outputTypeName}.${defaultValue}" is @inaccessible but is used in the default value of "${schemaCoordinate()}", which is in the API schema.`, {
30
+ extensions: {
31
+ code: 'DEFAULT_VALUE_USES_INACCESSIBLE',
32
+ },
33
+ }));
34
+ }
35
+ }
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DirectiveCompositionRule = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function DirectiveCompositionRule(context, supergraph) {
6
+ const linkIdentityToMajorVersion = new Map();
7
+ const appliedDirectiveToGraphs = new Map();
8
+ const appliedDirectiveToLinkIdentities = new Map();
9
+ for (const link of supergraph.links) {
10
+ if (link.version) {
11
+ const major = parseInt(link.version.replace('v', '').split('.')[0]);
12
+ const existing = linkIdentityToMajorVersion.get(link.identity);
13
+ if (typeof existing === 'number' && existing !== major) {
14
+ context.reportError(new graphql_1.GraphQLError(`Core feature "${link.identity}" requested to be merged has major version mismatch across subgraphs`, {
15
+ extensions: {
16
+ code: 'DIRECTIVE_COMPOSITION_ERROR',
17
+ versions: [existing, major],
18
+ },
19
+ }));
20
+ }
21
+ else {
22
+ linkIdentityToMajorVersion.set(link.identity, major);
23
+ }
24
+ }
25
+ for (const im of link.imports) {
26
+ if (im.kind === 'directive') {
27
+ const appliedName = im.alias ?? im.name;
28
+ const originalName = im.name;
29
+ const appliedDirectiveToGraph = appliedDirectiveToGraphs.get(originalName);
30
+ if (appliedDirectiveToGraph) {
31
+ const graphs = appliedDirectiveToGraph.get(appliedName);
32
+ if (graphs) {
33
+ graphs.add(link.graph);
34
+ }
35
+ else {
36
+ appliedDirectiveToGraph.set(appliedName, new Set([link.graph]));
37
+ }
38
+ }
39
+ else {
40
+ appliedDirectiveToGraphs.set(originalName, new Map([[appliedName, new Set([link.graph])]]));
41
+ }
42
+ const appliedDirectiveToLinkIdentity = appliedDirectiveToLinkIdentities.get(appliedName);
43
+ if (appliedDirectiveToLinkIdentity) {
44
+ appliedDirectiveToLinkIdentity.add(link.identity);
45
+ }
46
+ else {
47
+ appliedDirectiveToLinkIdentities.set(appliedName, new Set([link.identity]));
48
+ }
49
+ }
50
+ }
51
+ }
52
+ for (const [originalDirectiveName, appliedNames] of appliedDirectiveToGraphs) {
53
+ if (appliedNames.size > 1) {
54
+ const groups = Array.from(appliedNames.entries()).map(([appliedName, graphs]) => {
55
+ const plural = graphs.size > 1 ? 's' : '';
56
+ return `name "${appliedName}" in subgraph${plural} "${Array.from(graphs)
57
+ .map(context.graphIdToName)
58
+ .join('", "')}"`;
59
+ });
60
+ const [first, second, ...rest] = groups;
61
+ context.reportError(new graphql_1.GraphQLError(`Composed directive "${originalDirectiveName}" has incompatible name across subgraphs: it has ${first} but ${second}${rest.length ? ` and ${rest.join(' and ')}` : ''}. Composed directive must have the same name across all subgraphs.`, {
62
+ extensions: {
63
+ code: 'DIRECTIVE_COMPOSITION_ERROR',
64
+ },
65
+ }));
66
+ }
67
+ }
68
+ for (const [directiveName, linkIdentities] of appliedDirectiveToLinkIdentities) {
69
+ if (linkIdentities.size > 1) {
70
+ context.reportError(new graphql_1.GraphQLError(`Composed directive "${directiveName}" is not linked by the same core feature in every subgraph`, {
71
+ extensions: {
72
+ code: 'DIRECTIVE_COMPOSITION_ERROR',
73
+ },
74
+ }));
75
+ }
76
+ }
77
+ return {
78
+ Directive(directiveState) {
79
+ if (directiveState.byGraph.size === 1) {
80
+ return;
81
+ }
82
+ const graphsSize = directiveState.byGraph.size;
83
+ const hasLocationDefinedInAllGraphs = Array.from(directiveState.locations).some(location => {
84
+ let count = 0;
85
+ for (const [_, graphState] of directiveState.byGraph) {
86
+ if (graphState.locations.has(location)) {
87
+ count++;
88
+ }
89
+ }
90
+ return count === graphsSize;
91
+ });
92
+ if (!hasLocationDefinedInAllGraphs) {
93
+ context.reportError(new graphql_1.GraphQLError(`Directive "@${directiveState.name}" has no shared locations between subgraphs`));
94
+ }
95
+ },
96
+ };
97
+ }
98
+ exports.DirectiveCompositionRule = DirectiveCompositionRule;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EnumValuesRule = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function EnumValuesRule(context) {
6
+ return {
7
+ EnumType(enumTypeState) {
8
+ if (enumTypeState.referencedByInputType && enumTypeState.referencedByOutputType) {
9
+ const missingValues = [];
10
+ const total = enumTypeState.byGraph.size;
11
+ for (const [valueName, valueState] of enumTypeState.values) {
12
+ if (valueState.byGraph.size !== total) {
13
+ missingValues.push(valueName);
14
+ }
15
+ }
16
+ if (missingValues.length === 0) {
17
+ return;
18
+ }
19
+ const exampleInputType = `(for example, as type of "${enumTypeState.inputTypeReferences.values().next().value}")`;
20
+ const exampleOutputType = `(for example, as type of "${enumTypeState.outputTypeReferences.values().next().value}")`;
21
+ for (const missingValue of missingValues) {
22
+ const valueState = enumTypeState.values.get(missingValue);
23
+ const definedIn = Array.from(valueState.byGraph.keys()).map(context.graphIdToName);
24
+ const notDefinedIn = Array.from(enumTypeState.byGraph.keys())
25
+ .filter(key => !valueState.byGraph.has(key))
26
+ .map(context.graphIdToName);
27
+ const msg = [
28
+ `Enum type "${enumTypeState.name}" is used as both input type ${exampleInputType} and output type ${exampleOutputType},`,
29
+ `but value "${missingValue}" is not defined in all the subgraphs defining "${enumTypeState.name}":`,
30
+ `"${missingValue}" is defined in subgraph${definedIn.length > 1 ? 's' : ''} "${definedIn.join('", "')}"`,
31
+ `but not in subgraph${notDefinedIn.length > 1 ? 's' : ''} "${notDefinedIn.join('", "')}"`,
32
+ ].join(' ');
33
+ context.reportError(new graphql_1.GraphQLError(msg, {
34
+ extensions: {
35
+ code: 'ENUM_VALUE_MISMATCH',
36
+ },
37
+ }));
38
+ }
39
+ }
40
+ else if (enumTypeState.referencedByInputType) {
41
+ const valuesInCommon = [];
42
+ const total = enumTypeState.byGraph.size;
43
+ for (const [valueName, valueState] of enumTypeState.values) {
44
+ if (valueState.byGraph.size === total) {
45
+ valuesInCommon.push(valueName);
46
+ }
47
+ }
48
+ if (valuesInCommon.length === 0) {
49
+ context.reportError(new graphql_1.GraphQLError(`None of the values of enum type "${enumTypeState.name}" are defined consistently in all the subgraphs defining that type. As only values common to all subgraphs are merged, this would result in an empty type.`, {
50
+ extensions: {
51
+ code: 'EMPTY_MERGED_ENUM_TYPE',
52
+ },
53
+ }));
54
+ }
55
+ }
56
+ },
57
+ };
58
+ }
59
+ exports.EnumValuesRule = EnumValuesRule;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExtensionWithBaseRule = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function ExtensionWithBaseRule(context) {
6
+ return {
7
+ ObjectType(objectTypeState) {
8
+ if (objectTypeState.name === 'Query' ||
9
+ objectTypeState.name === 'Mutation' ||
10
+ objectTypeState.name === 'Subscription') {
11
+ return;
12
+ }
13
+ if (!objectTypeState.hasDefinition) {
14
+ if (objectTypeState.byGraph.size > 1 &&
15
+ Array.from(objectTypeState.byGraph).every(([graphId, meta]) => context.subgraphStates.get(graphId).version === 'v1.0'
16
+ ? meta.extensionType === '@extends'
17
+ : false)) {
18
+ return;
19
+ }
20
+ objectTypeState.byGraph.forEach((_, graph) => {
21
+ context.reportError(new graphql_1.GraphQLError(`[${context.graphIdToName(graph)}] Type "${objectTypeState.name}" is an extension type, but there is no type definition for "${objectTypeState.name}" in any subgraph.`, {
22
+ extensions: {
23
+ code: 'EXTENSION_WITH_NO_BASE',
24
+ },
25
+ }));
26
+ });
27
+ }
28
+ },
29
+ };
30
+ }
31
+ exports.ExtensionWithBaseRule = ExtensionWithBaseRule;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExternalArgumentMissingRule = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function ExternalArgumentMissingRule(context) {
6
+ return {
7
+ ObjectTypeFieldArg(objectState, fieldState, argState) {
8
+ if (argState.type.endsWith('!')) {
9
+ if (argState.byGraph.size === 1 && fieldState.byGraph.size === argState.byGraph.size) {
10
+ return;
11
+ }
12
+ if (fieldState.byGraph.size === argState.byGraph.size) {
13
+ return;
14
+ }
15
+ const graphsWithRequiredArg = Array.from(argState.byGraph)
16
+ .filter(([graph, arg]) => arg.type.endsWith('!') && fieldState.byGraph.get(graph)?.external !== true)
17
+ .map(([graph]) => graph);
18
+ const externalGraphsWithoutArg = Array.from(fieldState.byGraph.keys()).filter(graph => !argState.byGraph.has(graph) && fieldState.byGraph.get(graph)?.external === true);
19
+ const requiredIn = `subgraph${graphsWithRequiredArg.length > 1 ? 's' : ''} "${graphsWithRequiredArg.map(context.graphIdToName).join('", "')}"`;
20
+ const missingIn = `subgraph${externalGraphsWithoutArg.length > 1 ? 's' : ''} "${externalGraphsWithoutArg.map(context.graphIdToName).join('", "')}"`;
21
+ const fieldCoordinate = `${objectState.name}.${fieldState.name}`;
22
+ const argCoordinate = `${objectState.name}.${fieldState.name}(${argState.name}:)`;
23
+ context.reportError(new graphql_1.GraphQLError(`Field "${fieldCoordinate}" is missing argument "${argCoordinate}" in some subgraphs where it is marked @external: argument "${argCoordinate}" is declared in ${requiredIn} but not in ${missingIn} (where "${fieldCoordinate}" is @external)`, {
24
+ extensions: {
25
+ code: 'EXTERNAL_ARGUMENT_MISSING',
26
+ },
27
+ }));
28
+ }
29
+ },
30
+ };
31
+ }
32
+ exports.ExternalArgumentMissingRule = ExternalArgumentMissingRule;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExternalMissingOnBaseRule = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const format_js_1 = require("../../../utils/format.js");
6
+ function ExternalMissingOnBaseRule(context) {
7
+ return {
8
+ ObjectType(objectTypeState) {
9
+ if (Array.from(objectTypeState.byGraph).every(([_, stateInGraph]) => stateInGraph.external === true)) {
10
+ const subgraphs = objectTypeState.byGraph.size > 1 ? 'subgraphs' : 'subgraph';
11
+ context.reportError(new graphql_1.GraphQLError(`Type "${objectTypeState.name}" is marked @external on all the subgraphs in which it is listed (${subgraphs} ${((0, format_js_1.andList)(Array.from(objectTypeState.byGraph.keys()).map(graphId => context.graphIdToName(graphId))),
12
+ true,
13
+ '"')}).`, {
14
+ extensions: {
15
+ code: 'EXTERNAL_MISSING_ON_BASE',
16
+ },
17
+ }));
18
+ }
19
+ },
20
+ ObjectTypeField(objectState, fieldState) {
21
+ if (Array.from(fieldState.byGraph).every(([graphId, stateInGraph]) => {
22
+ const graphVersion = context.subgraphStates.get(graphId).version;
23
+ if (stateInGraph.usedAsKey) {
24
+ if (graphVersion === 'v1.0') {
25
+ return stateInGraph.external && !objectState.byGraph.get(graphId).extension;
26
+ }
27
+ return (stateInGraph.external === true &&
28
+ objectState.byGraph.get(graphId).extensionType !== '@extends');
29
+ }
30
+ if (graphVersion === 'v1.0') {
31
+ if (stateInGraph.external === true && stateInGraph.used) {
32
+ return true;
33
+ }
34
+ return false;
35
+ }
36
+ return stateInGraph.external === true;
37
+ })) {
38
+ const subgraphs = fieldState.byGraph.size > 1 ? 'subgraphs' : 'subgraph';
39
+ context.reportError(new graphql_1.GraphQLError(`Field "${objectState.name}.${fieldState.name}" is marked @external on all the subgraphs in which it is listed (${subgraphs} ${(0, format_js_1.andList)(Array.from(fieldState.byGraph.keys()).map(context.graphIdToName), true, '"')}).`, {
40
+ extensions: {
41
+ code: 'EXTERNAL_MISSING_ON_BASE',
42
+ },
43
+ }));
44
+ }
45
+ },
46
+ };
47
+ }
48
+ exports.ExternalMissingOnBaseRule = ExternalMissingOnBaseRule;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExternalTypeMismatchRule = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const format_js_1 = require("../../../utils/format.js");
6
+ const object_type_js_1 = require("../../composition/object-type.js");
7
+ function ExternalTypeMismatchRule(context) {
8
+ return {
9
+ ObjectTypeField(objectTypeState, fieldState) {
10
+ if (fieldState.usedAsKey) {
11
+ return;
12
+ }
13
+ const groupByType = new Map();
14
+ const graphsWithEqualType = [];
15
+ for (const [graphId, field] of fieldState.byGraph) {
16
+ const graphVersion = context.subgraphStates.get(graphId).version;
17
+ const isExternal = graphVersion === 'v1.0'
18
+ ? field.external && (0, object_type_js_1.isRealExtension)(objectTypeState.byGraph.get(graphId), graphVersion)
19
+ : field.external;
20
+ if (!isExternal) {
21
+ graphsWithEqualType.push(graphId);
22
+ continue;
23
+ }
24
+ if (field.type === fieldState.type) {
25
+ graphsWithEqualType.push(graphId);
26
+ continue;
27
+ }
28
+ const existing = groupByType.get(field.type);
29
+ if (existing) {
30
+ existing.push(graphId);
31
+ }
32
+ else {
33
+ groupByType.set(field.type, [graphId]);
34
+ }
35
+ }
36
+ if (groupByType.size && graphsWithEqualType.length) {
37
+ const groups = Array.from(groupByType.entries()).map(([type, graphs]) => {
38
+ const plural = graphs.length > 1 ? 's' : '';
39
+ return `type "${type}" in subgraph${plural} ${(0, format_js_1.andList)(graphs.map(context.graphIdToName), true, '"')}`;
40
+ });
41
+ const [first, ...rest] = groups;
42
+ const nonExternal = `type "${fieldState.type}" in subgraph${graphsWithEqualType.length > 1 ? 's' : ''} ${(0, format_js_1.andList)(graphsWithEqualType.map(context.graphIdToName), true, '"')}`;
43
+ context.reportError(new graphql_1.GraphQLError(`Type of field "${objectTypeState.name}.${fieldState.name}" is incompatible across subgraphs (where marked @external): it has ${nonExternal} but ${first}${rest.length ? ` and ${rest.join(' and ')}` : ''}`, {
44
+ extensions: {
45
+ code: 'EXTERNAL_TYPE_MISMATCH',
46
+ },
47
+ }));
48
+ }
49
+ },
50
+ };
51
+ }
52
+ exports.ExternalTypeMismatchRule = ExternalTypeMismatchRule;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FieldArgumentDefaultMismatchRule = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function FieldArgumentDefaultMismatchRule(context) {
6
+ return {
7
+ ObjectTypeFieldArg(objectState, fieldState, argState) {
8
+ if (typeof argState.defaultValue !== 'string') {
9
+ return;
10
+ }
11
+ const defaultValueToGraphs = new Map();
12
+ argState.byGraph.forEach((arg, graphName) => {
13
+ if (typeof arg.defaultValue === 'string') {
14
+ const existing = defaultValueToGraphs.get(arg.defaultValue);
15
+ if (existing) {
16
+ existing.push(graphName);
17
+ }
18
+ else {
19
+ defaultValueToGraphs.set(arg.defaultValue, [graphName]);
20
+ }
21
+ }
22
+ });
23
+ if (defaultValueToGraphs.size > 1) {
24
+ const groups = Array.from(defaultValueToGraphs.entries()).map(([defaultValue, graphs]) => {
25
+ const plural = graphs.length > 1 ? 's' : '';
26
+ return `default value ${defaultValue} in subgraph${plural} "${graphs
27
+ .map(context.graphIdToName)
28
+ .join('", "')}"`;
29
+ });
30
+ const [first, second, ...rest] = groups;
31
+ context.reportError(new graphql_1.GraphQLError(`Argument "${objectState.name}.${fieldState.name}(${argState.name}:)" has incompatible default values across subgraphs: it has ${first} but ${second}${rest.length ? ` and ${rest.join(' and ')}` : ''}`, {
32
+ extensions: {
33
+ code: 'FIELD_ARGUMENT_DEFAULT_MISMATCH',
34
+ },
35
+ }));
36
+ }
37
+ },
38
+ };
39
+ }
40
+ exports.FieldArgumentDefaultMismatchRule = FieldArgumentDefaultMismatchRule;