@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,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SubgraphNameRule = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function SubgraphNameRule(context) {
6
+ for (const [_, subgraph] of context.subgraphStates) {
7
+ const id = subgraph.graph.id;
8
+ if (id.startsWith('__')) {
9
+ context.reportError(new graphql_1.GraphQLError(`Name "${id}" must not begin with "__", which is reserved by GraphQL introspection.`, {
10
+ extensions: {
11
+ code: 'INVALID_GRAPHQL',
12
+ },
13
+ }));
14
+ }
15
+ }
16
+ return {};
17
+ }
18
+ exports.SubgraphNameRule = SubgraphNameRule;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypesOfTheSameKindRule = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const state_js_1 = require("../../../subgraph/state.js");
6
+ const mapIRKindToString = {
7
+ [state_js_1.TypeKind.OBJECT]: 'Object',
8
+ [state_js_1.TypeKind.INTERFACE]: 'Interface',
9
+ [state_js_1.TypeKind.UNION]: 'Union',
10
+ [state_js_1.TypeKind.ENUM]: 'Enum',
11
+ [state_js_1.TypeKind.INPUT_OBJECT]: 'InputObject',
12
+ [state_js_1.TypeKind.SCALAR]: 'Scalar',
13
+ [state_js_1.TypeKind.DIRECTIVE]: 'Directive',
14
+ };
15
+ function TypesOfTheSameKindRule(context) {
16
+ const typeToKindWithGraphs = new Map();
17
+ const typesWithConflict = new Set();
18
+ for (const [graph, state] of context.subgraphStates) {
19
+ state.types.forEach(type => {
20
+ const kindToGraphs = typeToKindWithGraphs.get(type.name);
21
+ if (kindToGraphs) {
22
+ const graphs = kindToGraphs.get(type.kind);
23
+ if (graphs) {
24
+ graphs.add(graph);
25
+ }
26
+ else {
27
+ kindToGraphs.set(type.kind, new Set([graph]));
28
+ }
29
+ if (kindToGraphs.size > 1) {
30
+ typesWithConflict.add(type.name);
31
+ }
32
+ }
33
+ else {
34
+ typeToKindWithGraphs.set(type.name, new Map([[type.kind, new Set([graph])]]));
35
+ }
36
+ });
37
+ }
38
+ for (const typeName of typesWithConflict) {
39
+ const kindToGraphs = typeToKindWithGraphs.get(typeName);
40
+ const groups = Array.from(kindToGraphs.entries()).map(([kind, graphs]) => {
41
+ const plural = graphs.size > 1 ? 's' : '';
42
+ return `${mapIRKindToString[kind]} Type in subgraph${plural} "${Array.from(graphs)
43
+ .map(context.graphIdToName)
44
+ .join('", "')}"`;
45
+ });
46
+ const [first, second, ...rest] = groups;
47
+ context.reportError(new graphql_1.GraphQLError(`Type "${typeName}" has mismatched kind: it is defined as ${first} but ${second}${rest.length ? ` and ${rest.join(' and ')}` : ''}`, {
48
+ extensions: {
49
+ code: 'TYPE_KIND_MISMATCH',
50
+ },
51
+ }));
52
+ }
53
+ }
54
+ exports.TypesOfTheSameKindRule = TypesOfTheSameKindRule;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateSupergraph = void 0;
4
+ const visitor_js_1 = require("../composition/visitor.js");
5
+ const default_value_uses_inaccessible_rule_js_1 = require("./rules/default-value-uses-inaccessible-rule.js");
6
+ const directive_composition_rule_js_1 = require("./rules/directive-composition-rule.js");
7
+ const enum_values_rule_js_1 = require("./rules/enum-values-rule.js");
8
+ const extension_with_base_js_1 = require("./rules/extension-with-base.js");
9
+ const external_argument_missing_rule_js_1 = require("./rules/external-argument-missing-rule.js");
10
+ const external_missing_on_base_rule_js_1 = require("./rules/external-missing-on-base-rule.js");
11
+ const external_type_mismatch_rule_js_1 = require("./rules/external-type-mismatch-rule.js");
12
+ const field_argument_default_mismatch_rule_js_1 = require("./rules/field-argument-default-mismatch-rule.js");
13
+ const field_arguments_of_the_same_type_rule_js_1 = require("./rules/field-arguments-of-the-same-type-rule.js");
14
+ const fields_of_the_same_type_rule_js_1 = require("./rules/fields-of-the-same-type-rule.js");
15
+ const input_field_default_mismatch_rule_js_1 = require("./rules/input-field-default-mismatch-rule.js");
16
+ const input_object_values_rule_js_1 = require("./rules/input-object-values-rule.js");
17
+ const interface_key_missing_implementation_type_js_1 = require("./rules/interface-key-missing-implementation-type.js");
18
+ const invalid_field_sharing_rule_js_1 = require("./rules/invalid-field-sharing-rule.js");
19
+ const only_inaccessible_children_rule_js_1 = require("./rules/only-inaccessible-children-rule.js");
20
+ const override_source_has_override_js_1 = require("./rules/override-source-has-override.js");
21
+ const referenced_inaccessible_rule_js_1 = require("./rules/referenced-inaccessible-rule.js");
22
+ const required_argument_missing_in_some_subgraph_rule_js_1 = require("./rules/required-argument-missing-in-some-subgraph-rule.js");
23
+ const required_input_field_missing_in_some_subgraph_rule_js_1 = require("./rules/required-input-field-missing-in-some-subgraph-rule.js");
24
+ const required_query_rule_js_1 = require("./rules/required-query-rule.js");
25
+ const satisfiablity_rule_js_1 = require("./rules/satisfiablity-rule.js");
26
+ const subgraph_name_rule_js_1 = require("./rules/subgraph-name-rule.js");
27
+ const types_of_the_same_kind_rule_js_1 = require("./rules/types-of-the-same-kind-rule.js");
28
+ const validation_context_js_1 = require("./validation-context.js");
29
+ function validateSupergraph(subgraphStates, state, __internal) {
30
+ const context = (0, validation_context_js_1.createSupergraphValidationContext)(subgraphStates);
31
+ for (const subgraphState of subgraphStates.values()) {
32
+ state.addGraph(subgraphState.graph);
33
+ }
34
+ const preSupergraphRules = [required_query_rule_js_1.RequiredQueryRule, types_of_the_same_kind_rule_js_1.TypesOfTheSameKindRule];
35
+ const rulesToSkip = __internal?.disableValidationRules ?? [];
36
+ for (const rule of preSupergraphRules) {
37
+ if (rulesToSkip.includes(rule.name)) {
38
+ continue;
39
+ }
40
+ rule(context);
41
+ }
42
+ for (const subgraphState of subgraphStates.values()) {
43
+ state.visitSubgraphState(subgraphState);
44
+ }
45
+ const postSupergraphRules = [
46
+ extension_with_base_js_1.ExtensionWithBaseRule,
47
+ fields_of_the_same_type_rule_js_1.FieldsOfTheSameTypeRule,
48
+ field_arguments_of_the_same_type_rule_js_1.FieldArgumentsOfTheSameTypeRule,
49
+ enum_values_rule_js_1.EnumValuesRule,
50
+ override_source_has_override_js_1.OverrideSourceHasOverrideRule,
51
+ external_missing_on_base_rule_js_1.ExternalMissingOnBaseRule,
52
+ input_object_values_rule_js_1.InputObjectValuesRule,
53
+ required_argument_missing_in_some_subgraph_rule_js_1.RequiredArgumentMissingInSomeSubgraph,
54
+ required_input_field_missing_in_some_subgraph_rule_js_1.RequiredInputFieldMissingInSomeSubgraphRule,
55
+ external_argument_missing_rule_js_1.ExternalArgumentMissingRule,
56
+ input_field_default_mismatch_rule_js_1.InputFieldDefaultMismatchRule,
57
+ field_argument_default_mismatch_rule_js_1.FieldArgumentDefaultMismatchRule,
58
+ default_value_uses_inaccessible_rule_js_1.DefaultValueUsesInaccessibleRule,
59
+ only_inaccessible_children_rule_js_1.OnlyInaccessibleChildrenRule,
60
+ referenced_inaccessible_rule_js_1.ReferencedInaccessibleRule,
61
+ directive_composition_rule_js_1.DirectiveCompositionRule,
62
+ interface_key_missing_implementation_type_js_1.InterfaceKeyMissingImplementationTypeRule,
63
+ external_type_mismatch_rule_js_1.ExternalTypeMismatchRule,
64
+ invalid_field_sharing_rule_js_1.InvalidFieldSharingRule,
65
+ satisfiablity_rule_js_1.SatisfiabilityRule,
66
+ subgraph_name_rule_js_1.SubgraphNameRule,
67
+ ];
68
+ const supergraph = state.getSupergraphState();
69
+ (0, visitor_js_1.visitSupergraphState)(supergraph, postSupergraphRules.map(rule => {
70
+ if (rulesToSkip.includes(rule.name)) {
71
+ return {};
72
+ }
73
+ return rule(context, supergraph);
74
+ }));
75
+ return context.collectReportedErrors();
76
+ }
77
+ exports.validateSupergraph = validateSupergraph;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSupergraphValidationContext = void 0;
4
+ function createSupergraphValidationContext(subgraphStates) {
5
+ let reportedErrors = [];
6
+ return {
7
+ subgraphStates,
8
+ graphIdToName(id) {
9
+ const found = subgraphStates.get(id);
10
+ if (!found) {
11
+ throw new Error(`Could not find subgraph with id ${id}`);
12
+ }
13
+ return found.graph.name;
14
+ },
15
+ reportError(error) {
16
+ reportedErrors.push(error);
17
+ },
18
+ collectReportedErrors() {
19
+ const errors = reportedErrors;
20
+ reportedErrors = [];
21
+ return errors;
22
+ },
23
+ };
24
+ }
25
+ exports.createSupergraphValidationContext = createSupergraphValidationContext;
package/cjs/types.js ADDED
File without changes
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DepGraphCycleError = exports.DepGraph = void 0;
4
+ function createDFS(edges, leavesOnly, result, circular) {
5
+ const visited = {};
6
+ return function (start) {
7
+ if (visited[start]) {
8
+ return;
9
+ }
10
+ const inCurrentPath = {};
11
+ const currentPath = [];
12
+ const todo = [];
13
+ todo.push({ node: start, processed: false });
14
+ while (todo.length > 0) {
15
+ const current = todo[todo.length - 1];
16
+ const processed = current.processed;
17
+ const node = current.node;
18
+ if (!processed) {
19
+ if (visited[node]) {
20
+ todo.pop();
21
+ continue;
22
+ }
23
+ else if (inCurrentPath[node]) {
24
+ if (circular) {
25
+ todo.pop();
26
+ continue;
27
+ }
28
+ currentPath.push(node);
29
+ throw new DepGraphCycleError(currentPath);
30
+ }
31
+ inCurrentPath[node] = true;
32
+ currentPath.push(node);
33
+ const nodeEdges = edges[node];
34
+ for (let i = nodeEdges.length - 1; i >= 0; i--) {
35
+ todo.push({ node: nodeEdges[i], processed: false });
36
+ }
37
+ current.processed = true;
38
+ }
39
+ else {
40
+ todo.pop();
41
+ currentPath.pop();
42
+ inCurrentPath[node] = false;
43
+ visited[node] = true;
44
+ if (!leavesOnly || edges[node].length === 0) {
45
+ result.push(node);
46
+ }
47
+ }
48
+ }
49
+ };
50
+ }
51
+ class DepGraph {
52
+ nodes = {};
53
+ outgoingEdges = {};
54
+ incomingEdges = {};
55
+ circular;
56
+ constructor(opts) {
57
+ this.circular = opts?.circular ?? false;
58
+ }
59
+ size() {
60
+ return Object.keys(this.nodes).length;
61
+ }
62
+ addNode(name, data) {
63
+ if (!this.hasNode(name)) {
64
+ if (arguments.length === 2) {
65
+ this.nodes[name] = data;
66
+ }
67
+ else {
68
+ this.nodes[name] = name;
69
+ }
70
+ this.outgoingEdges[name] = [];
71
+ this.incomingEdges[name] = [];
72
+ }
73
+ }
74
+ removeNode(name) {
75
+ if (this.hasNode(name)) {
76
+ delete this.nodes[name];
77
+ delete this.outgoingEdges[name];
78
+ delete this.incomingEdges[name];
79
+ [this.incomingEdges, this.outgoingEdges].forEach(edgeList => {
80
+ Object.keys(edgeList).forEach(key => {
81
+ const idx = edgeList[key].indexOf(name);
82
+ if (idx >= 0) {
83
+ edgeList[key].splice(idx, 1);
84
+ }
85
+ });
86
+ });
87
+ }
88
+ }
89
+ hasNode(name) {
90
+ return this.nodes.hasOwnProperty(name);
91
+ }
92
+ getNodeData(name) {
93
+ if (this.hasNode(name)) {
94
+ return this.nodes[name];
95
+ }
96
+ else {
97
+ throw new Error('Node does not exist: ' + name);
98
+ }
99
+ }
100
+ setNodeData(name, data) {
101
+ if (this.hasNode(name)) {
102
+ this.nodes[name] = data;
103
+ }
104
+ else {
105
+ throw new Error('Node does not exist: ' + name);
106
+ }
107
+ }
108
+ addDependency(from, to) {
109
+ if (!this.hasNode(from)) {
110
+ throw new Error('Node does not exist: ' + from);
111
+ }
112
+ if (!this.hasNode(to)) {
113
+ throw new Error('Node does not exist: ' + to);
114
+ }
115
+ if (this.outgoingEdges[from].indexOf(to) === -1) {
116
+ this.outgoingEdges[from].push(to);
117
+ }
118
+ if (this.incomingEdges[to].indexOf(from) === -1) {
119
+ this.incomingEdges[to].push(from);
120
+ }
121
+ return true;
122
+ }
123
+ removeDependency(from, to) {
124
+ let idx;
125
+ if (this.hasNode(from)) {
126
+ idx = this.outgoingEdges[from].indexOf(to);
127
+ if (idx >= 0) {
128
+ this.outgoingEdges[from].splice(idx, 1);
129
+ }
130
+ }
131
+ if (this.hasNode(to)) {
132
+ idx = this.incomingEdges[to].indexOf(from);
133
+ if (idx >= 0) {
134
+ this.incomingEdges[to].splice(idx, 1);
135
+ }
136
+ }
137
+ }
138
+ directDependenciesOf(name) {
139
+ if (this.hasNode(name)) {
140
+ return this.outgoingEdges[name].slice(0);
141
+ }
142
+ else {
143
+ throw new Error('Node does not exist: ' + name);
144
+ }
145
+ }
146
+ directDependantsOf(name) {
147
+ if (this.hasNode(name)) {
148
+ return this.incomingEdges[name].slice(0);
149
+ }
150
+ else {
151
+ throw new Error('Node does not exist: ' + name);
152
+ }
153
+ }
154
+ dependenciesOf(name, leavesOnly) {
155
+ if (this.hasNode(name)) {
156
+ const result = [];
157
+ const DFS = createDFS(this.outgoingEdges, leavesOnly, result, this.circular);
158
+ DFS(name);
159
+ const idx = result.indexOf(name);
160
+ if (idx >= 0) {
161
+ result.splice(idx, 1);
162
+ }
163
+ return result;
164
+ }
165
+ else {
166
+ throw new Error('Node does not exist: ' + name);
167
+ }
168
+ }
169
+ dependantsOf(name, leavesOnly) {
170
+ if (this.hasNode(name)) {
171
+ const result = [];
172
+ const DFS = createDFS(this.incomingEdges, leavesOnly, result, this.circular);
173
+ DFS(name);
174
+ const idx = result.indexOf(name);
175
+ if (idx >= 0) {
176
+ result.splice(idx, 1);
177
+ }
178
+ return result;
179
+ }
180
+ else {
181
+ throw new Error('Node does not exist: ' + name);
182
+ }
183
+ }
184
+ overallOrder(leavesOnly) {
185
+ const result = [];
186
+ const keys = Object.keys(this.nodes);
187
+ if (keys.length === 0) {
188
+ return result;
189
+ }
190
+ else {
191
+ if (!this.circular) {
192
+ const CycleDFS = createDFS(this.outgoingEdges, false, [], this.circular);
193
+ keys.forEach(function (n) {
194
+ CycleDFS(n);
195
+ });
196
+ }
197
+ const DFS = createDFS(this.outgoingEdges, leavesOnly, result, this.circular);
198
+ keys
199
+ .filter(node => this.incomingEdges[node].length === 0)
200
+ .forEach(n => {
201
+ DFS(n);
202
+ });
203
+ if (this.circular) {
204
+ keys
205
+ .filter(node => result.indexOf(node) === -1)
206
+ .forEach(function (n) {
207
+ DFS(n);
208
+ });
209
+ }
210
+ return result;
211
+ }
212
+ }
213
+ entryNodes() {
214
+ return Object.keys(this.nodes).filter(node => this.incomingEdges[node].length === 0);
215
+ }
216
+ directDependentsOf = this.directDependantsOf;
217
+ dependentsOf = this.dependantsOf;
218
+ }
219
+ exports.DepGraph = DepGraph;
220
+ class DepGraphCycleError extends Error {
221
+ cyclePath;
222
+ constructor(cyclePath) {
223
+ super('Dependency Cycle Found: ' + cyclePath.join(' -> '));
224
+ this.cyclePath = cyclePath;
225
+ }
226
+ }
227
+ exports.DepGraphCycleError = DepGraphCycleError;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.andList = void 0;
4
+ function andList(items, commaBeforeConjunction = true, wrapper) {
5
+ return formatList('and', items, commaBeforeConjunction, wrapper);
6
+ }
7
+ exports.andList = andList;
8
+ function formatList(conjunction, items, commaBeforeConjunction = true, wrapper) {
9
+ if (items.length === 0) {
10
+ return '';
11
+ }
12
+ switch (items.length) {
13
+ case 1:
14
+ return withWrapper(items[0], wrapper);
15
+ case 2:
16
+ return (withWrapper(items[0], wrapper) + ' ' + conjunction + ' ' + withWrapper(items[1], wrapper));
17
+ }
18
+ const allButLast = items.slice(0, -1).map(item => withWrapper(item, wrapper));
19
+ const lastItem = withWrapper(items.at(-1), wrapper);
20
+ return (allButLast.join(', ') + (commaBeforeConjunction ? ', ' : ' ') + conjunction + ' ' + lastItem);
21
+ }
22
+ function withWrapper(text, wrapper) {
23
+ if (!wrapper) {
24
+ return text;
25
+ }
26
+ return wrapper + text + wrapper;
27
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDefined = void 0;
4
+ function isDefined(value) {
5
+ return value !== undefined && value !== null;
6
+ }
7
+ exports.isDefined = isDefined;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isList = exports.isNonNull = exports.stripList = exports.stripNonNull = exports.stripTypeModifiers = void 0;
4
+ function stripTypeModifiers(type) {
5
+ return type.replaceAll('!', '').replaceAll('[', '').replaceAll(']', '');
6
+ }
7
+ exports.stripTypeModifiers = stripTypeModifiers;
8
+ function stripNonNull(type) {
9
+ return type.replace(/\!$/, '');
10
+ }
11
+ exports.stripNonNull = stripNonNull;
12
+ function stripList(type) {
13
+ return type.replace(/^\[/, '').replace(/\]$/, '');
14
+ }
15
+ exports.stripList = stripList;
16
+ function isNonNull(type) {
17
+ return type.endsWith('!');
18
+ }
19
+ exports.isNonNull = isNonNull;
20
+ function isList(type) {
21
+ return type.endsWith(']');
22
+ }
23
+ exports.isList = isList;
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validate = void 0;
4
+ const constant_case_1 = require("constant-case");
5
+ const federation_js_1 = require("./specifications/federation.js");
6
+ const state_js_1 = require("./subgraph/state.js");
7
+ const validate_subgraph_js_1 = require("./subgraph/validation/validate-subgraph.js");
8
+ const state_js_2 = require("./supergraph/state.js");
9
+ const validate_supergraph_js_1 = require("./supergraph/validation/validate-supergraph.js");
10
+ const numberAtStartRegex = /^\d/;
11
+ function startsWithNumber(value) {
12
+ return numberAtStartRegex.test(value);
13
+ }
14
+ function buildGraphList(subgraphs) {
15
+ const errors = [];
16
+ const graphs = [];
17
+ const names = new Set();
18
+ const idCounter = new Map();
19
+ for (const subgraph of subgraphs) {
20
+ const name = String(subgraph.name);
21
+ const nameStartsWithNumber = startsWithNumber(name);
22
+ if (names.has(name)) {
23
+ throw new Error(`A subgraph named ${name} already exists`);
24
+ }
25
+ const { url, typeDefs } = subgraph;
26
+ names.add(name);
27
+ let proposedId = (0, constant_case_1.constantCase)(name.replace(/[^A-Z0-9]/gi, '_'), {
28
+ stripRegexp: /[^A-Z0-9_]+/gi,
29
+ });
30
+ if (nameStartsWithNumber) {
31
+ proposedId = '_' + proposedId + '_';
32
+ }
33
+ let count = idCounter.get(proposedId);
34
+ if (typeof count === 'number') {
35
+ if (count === 1) {
36
+ graphs.find(g => g.id === proposedId).id += '_1';
37
+ }
38
+ graphs.push({
39
+ name,
40
+ id: proposedId + '_' + (count + 1),
41
+ url,
42
+ typeDefs,
43
+ });
44
+ idCounter.set(proposedId, count + 1);
45
+ }
46
+ else {
47
+ idCounter.set(proposedId, 1);
48
+ graphs.push({
49
+ name,
50
+ id: proposedId,
51
+ url,
52
+ typeDefs,
53
+ });
54
+ }
55
+ }
56
+ if (errors.length > 0) {
57
+ return {
58
+ success: false,
59
+ errors,
60
+ };
61
+ }
62
+ graphs.sort((a, b) => a.id.localeCompare(b.id));
63
+ return {
64
+ success: true,
65
+ graphs,
66
+ };
67
+ }
68
+ function validate(subgraphs, __internal) {
69
+ const graphList = buildGraphList(subgraphs);
70
+ if (!graphList.success) {
71
+ return {
72
+ success: false,
73
+ errors: graphList.errors,
74
+ };
75
+ }
76
+ const corePerSubgraph = graphList.graphs.map(subgraph => (0, validate_subgraph_js_1.validateSubgraphCore)(subgraph));
77
+ const coreErrors = corePerSubgraph.map(core => core.errors ?? []).flat(1);
78
+ if (coreErrors.length > 0) {
79
+ return {
80
+ success: false,
81
+ errors: coreErrors,
82
+ };
83
+ }
84
+ const detectedFederationSpec = new Map(graphList.graphs.map(graph => [graph.id, (0, federation_js_1.detectFederationVersion)(graph.typeDefs)]));
85
+ const subgraphStateBuilders = new Map(graphList.graphs.map((graph, i) => [
86
+ graph.id,
87
+ (0, state_js_1.createSubgraphStateBuilder)(graph, graph.typeDefs, detectedFederationSpec.get(graph.id).version, corePerSubgraph[i].links ?? []),
88
+ ]));
89
+ const subgraphErrors = graphList.graphs
90
+ .map(graph => (0, validate_subgraph_js_1.validateSubgraph)(graph, subgraphStateBuilders.get(graph.id), detectedFederationSpec.get(graph.id), __internal))
91
+ .flat(1);
92
+ if (subgraphErrors.length > 0) {
93
+ return {
94
+ success: false,
95
+ errors: subgraphErrors,
96
+ };
97
+ }
98
+ const state = (0, state_js_2.createSupergraphStateBuilder)();
99
+ const supergraphErrors = (0, validate_supergraph_js_1.validateSupergraph)(new Map(Array.from(subgraphStateBuilders.entries()).map(([id, builder]) => [
100
+ id,
101
+ (0, state_js_1.cleanSubgraphStateFromFederationSpec)((0, state_js_1.cleanSubgraphStateFromLinkSpec)(builder.state)),
102
+ ])), state, __internal);
103
+ if (supergraphErrors.length > 0) {
104
+ return {
105
+ success: false,
106
+ errors: supergraphErrors,
107
+ };
108
+ }
109
+ const nodes = state.build();
110
+ return {
111
+ success: true,
112
+ supergraph: nodes,
113
+ links: state.links(),
114
+ specs: state.getSupergraphState().specs,
115
+ };
116
+ }
117
+ exports.validate = validate;
package/esm/compose.js ADDED
@@ -0,0 +1,78 @@
1
+ import { Kind } from 'graphql';
2
+ import { print } from './graphql/printer.js';
3
+ import { sdl as inaccessibleSDL } from './specifications/inaccessible.js';
4
+ import { sdl as joinSDL } from './specifications/join.js';
5
+ import { sdl as linkSDL, printLink } from './specifications/link.js';
6
+ import { sdl as tagSDL } from './specifications/tag.js';
7
+ import { validate } from './validate.js';
8
+ export function composeServices(services, __internal) {
9
+ const validationResult = validate(services, __internal);
10
+ if (!validationResult.success) {
11
+ return {
12
+ errors: validationResult.errors,
13
+ };
14
+ }
15
+ const rootTypes = {
16
+ query: false,
17
+ mutation: false,
18
+ subscription: false,
19
+ };
20
+ for (const def of validationResult.supergraph) {
21
+ if (def.name.value === 'Query') {
22
+ rootTypes.query = true;
23
+ }
24
+ else if (def.name.value === 'Mutation') {
25
+ rootTypes.mutation = true;
26
+ }
27
+ else if (def.name.value === 'Subscription') {
28
+ rootTypes.subscription = true;
29
+ }
30
+ if (rootTypes.query === true &&
31
+ rootTypes.mutation === true &&
32
+ rootTypes.subscription === true) {
33
+ break;
34
+ }
35
+ }
36
+ const usedTagSpec = validationResult.specs.tag;
37
+ const usedInaccessibleSpec = validationResult.specs.inaccessible;
38
+ return {
39
+ supergraphSdl: `
40
+ schema
41
+ @link(url: "https://specs.apollo.dev/link/v1.0")
42
+ @link(url: "https://specs.apollo.dev/join/v0.3", for: EXECUTION)
43
+ ${usedTagSpec ? '@link(url: "https://specs.apollo.dev/tag/v0.3")' : ''}
44
+ ${usedInaccessibleSpec
45
+ ? '@link(url: "https://specs.apollo.dev/inaccessible/v0.2", for: SECURITY)'
46
+ : ''}
47
+ ${validationResult.links.map(printLink).join('\n ')}
48
+ {
49
+ ${rootTypes.query ? 'query: Query' : ''}
50
+ ${rootTypes.mutation ? 'mutation: Mutation' : ''}
51
+ ${rootTypes.subscription ? 'subscription: Subscription' : ''}
52
+ }
53
+
54
+ ${joinSDL}
55
+ ${linkSDL}
56
+ ${usedTagSpec ? tagSDL : ''}
57
+ ${usedInaccessibleSpec ? inaccessibleSDL : ''}
58
+
59
+ ${print({
60
+ kind: Kind.DOCUMENT,
61
+ definitions: validationResult.supergraph,
62
+ })}
63
+ `,
64
+ };
65
+ }
66
+ export function assertCompositionSuccess(compositionResult, message) {
67
+ if (compositionHasErrors(compositionResult)) {
68
+ throw new Error(message || 'Unexpected test failure');
69
+ }
70
+ }
71
+ export function assertCompositionFailure(compositionResult, message) {
72
+ if (!compositionHasErrors(compositionResult)) {
73
+ throw new Error(message || 'Unexpected test failure');
74
+ }
75
+ }
76
+ export function compositionHasErrors(compositionResult) {
77
+ return 'errors' in compositionResult && !!compositionResult.errors;
78
+ }