@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,765 @@
1
+ import { Kind, OperationTypeNode, parseConstValue, parseType, specifiedDirectives, visit, visitInParallel, } from 'graphql';
2
+ export function createSchemaNode(schema) {
3
+ return {
4
+ kind: Kind.SCHEMA_DEFINITION,
5
+ directives: schema.links?.map(createLinkDirectiveNode),
6
+ operationTypes: [].concat(schema.query
7
+ ? {
8
+ kind: Kind.OPERATION_TYPE_DEFINITION,
9
+ operation: OperationTypeNode.QUERY,
10
+ type: createNamedTypeNode(schema.query),
11
+ }
12
+ : [], schema.mutation
13
+ ? {
14
+ kind: Kind.OPERATION_TYPE_DEFINITION,
15
+ operation: OperationTypeNode.MUTATION,
16
+ type: createNamedTypeNode(schema.mutation),
17
+ }
18
+ : [], schema.subscription
19
+ ? {
20
+ kind: Kind.OPERATION_TYPE_DEFINITION,
21
+ operation: OperationTypeNode.SUBSCRIPTION,
22
+ type: createNamedTypeNode(schema.subscription),
23
+ }
24
+ : []),
25
+ };
26
+ }
27
+ export function createDirectiveNode(directive) {
28
+ return {
29
+ kind: Kind.DIRECTIVE_DEFINITION,
30
+ name: {
31
+ kind: Kind.NAME,
32
+ value: directive.name,
33
+ },
34
+ locations: Array.from(directive.locations).map(location => ({
35
+ kind: Kind.NAME,
36
+ value: location,
37
+ })),
38
+ repeatable: directive.repeatable,
39
+ arguments: directive.arguments.map(createFieldArgumentNode),
40
+ };
41
+ }
42
+ export function createObjectTypeNode(objectType) {
43
+ return {
44
+ kind: Kind.OBJECT_TYPE_DEFINITION,
45
+ name: {
46
+ kind: Kind.NAME,
47
+ value: objectType.name,
48
+ },
49
+ directives: applyDirectives(objectType),
50
+ fields: objectType.fields.map(createFieldNode),
51
+ description: objectType.description ? createDescriptionNode(objectType.description) : undefined,
52
+ interfaces: objectType.interfaces?.map(createNamedTypeNode),
53
+ };
54
+ }
55
+ export function createInterfaceTypeNode(interfaceType) {
56
+ return {
57
+ kind: Kind.INTERFACE_TYPE_DEFINITION,
58
+ name: {
59
+ kind: Kind.NAME,
60
+ value: interfaceType.name,
61
+ },
62
+ directives: applyDirectives(interfaceType),
63
+ description: interfaceType.description
64
+ ? createDescriptionNode(interfaceType.description)
65
+ : undefined,
66
+ fields: interfaceType.fields.map(createFieldNode),
67
+ interfaces: interfaceType.interfaces?.map(createNamedTypeNode),
68
+ };
69
+ }
70
+ export function createInputObjectTypeNode(inputObjectType) {
71
+ return {
72
+ kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,
73
+ name: {
74
+ kind: Kind.NAME,
75
+ value: inputObjectType.name,
76
+ },
77
+ directives: applyDirectives(inputObjectType),
78
+ fields: inputObjectType.fields.map(createInputFieldNode),
79
+ description: inputObjectType.description
80
+ ? createDescriptionNode(inputObjectType.description)
81
+ : undefined,
82
+ };
83
+ }
84
+ export function createUnionTypeNode(unionType) {
85
+ return {
86
+ kind: Kind.UNION_TYPE_DEFINITION,
87
+ name: {
88
+ kind: Kind.NAME,
89
+ value: unionType.name,
90
+ },
91
+ directives: applyDirectives(unionType),
92
+ description: unionType.description ? createDescriptionNode(unionType.description) : undefined,
93
+ types: unionType.members.map(member => ({
94
+ kind: Kind.NAMED_TYPE,
95
+ name: {
96
+ kind: Kind.NAME,
97
+ value: member,
98
+ },
99
+ })),
100
+ };
101
+ }
102
+ export function createEnumTypeNode(enumType) {
103
+ return {
104
+ kind: Kind.ENUM_TYPE_DEFINITION,
105
+ name: {
106
+ kind: Kind.NAME,
107
+ value: enumType.name,
108
+ },
109
+ directives: applyDirectives(enumType),
110
+ description: enumType.description ? createDescriptionNode(enumType.description) : undefined,
111
+ values: enumType.values.map(createEnumValueNode),
112
+ };
113
+ }
114
+ export function createScalarTypeNode(scalarType) {
115
+ return {
116
+ kind: Kind.SCALAR_TYPE_DEFINITION,
117
+ name: {
118
+ kind: Kind.NAME,
119
+ value: scalarType.name,
120
+ },
121
+ description: scalarType.description ? createDescriptionNode(scalarType.description) : undefined,
122
+ directives: applyDirectives(scalarType),
123
+ };
124
+ }
125
+ export function createJoinGraphEnumTypeNode(graphs) {
126
+ return createEnumTypeNode({
127
+ name: 'join__Graph',
128
+ values: graphs.map(graph => ({
129
+ name: graph.enumValue,
130
+ ast: {
131
+ directives: [createJoinGraphDirectiveNode(graph)],
132
+ },
133
+ })),
134
+ });
135
+ }
136
+ function createFieldNode(field) {
137
+ return {
138
+ kind: Kind.FIELD_DEFINITION,
139
+ name: {
140
+ kind: Kind.NAME,
141
+ value: field.name,
142
+ },
143
+ type: parseType(field.type),
144
+ directives: applyDirectives(field),
145
+ description: field.description ? createDescriptionNode(field.description) : undefined,
146
+ arguments: field.arguments?.map(createFieldArgumentNode),
147
+ };
148
+ }
149
+ function createInputFieldNode(inputField) {
150
+ return {
151
+ kind: Kind.INPUT_VALUE_DEFINITION,
152
+ name: {
153
+ kind: Kind.NAME,
154
+ value: inputField.name,
155
+ },
156
+ type: parseType(inputField.type),
157
+ directives: applyDirectives(inputField),
158
+ description: inputField.description ? createDescriptionNode(inputField.description) : undefined,
159
+ defaultValue: typeof inputField.defaultValue === 'string'
160
+ ? parseConstValue(inputField.defaultValue)
161
+ : undefined,
162
+ };
163
+ }
164
+ function createEnumValueNode(enumValue) {
165
+ return {
166
+ kind: Kind.ENUM_VALUE_DEFINITION,
167
+ name: {
168
+ kind: Kind.NAME,
169
+ value: enumValue.name,
170
+ },
171
+ directives: applyDirectives(enumValue),
172
+ description: enumValue.description ? createDescriptionNode(enumValue.description) : undefined,
173
+ };
174
+ }
175
+ function createFieldArgumentNode(argument) {
176
+ return {
177
+ kind: Kind.INPUT_VALUE_DEFINITION,
178
+ name: {
179
+ kind: Kind.NAME,
180
+ value: argument.name,
181
+ },
182
+ defaultValue: typeof argument.defaultValue === 'string'
183
+ ? parseConstValue(argument.defaultValue)
184
+ : undefined,
185
+ type: parseType(argument.type),
186
+ directives: applyDirectives(argument),
187
+ description: argument.description ? createDescriptionNode(argument.description) : undefined,
188
+ };
189
+ }
190
+ function createJoinTypeDirectiveNode(join) {
191
+ return {
192
+ kind: Kind.DIRECTIVE,
193
+ name: {
194
+ kind: Kind.NAME,
195
+ value: 'join__type',
196
+ },
197
+ arguments: [
198
+ {
199
+ kind: Kind.ARGUMENT,
200
+ name: {
201
+ kind: Kind.NAME,
202
+ value: 'graph',
203
+ },
204
+ value: {
205
+ kind: Kind.ENUM,
206
+ value: join.graph,
207
+ },
208
+ },
209
+ join.key
210
+ ? {
211
+ kind: Kind.ARGUMENT,
212
+ name: {
213
+ kind: Kind.NAME,
214
+ value: 'key',
215
+ },
216
+ value: {
217
+ kind: Kind.STRING,
218
+ value: join.key,
219
+ },
220
+ }
221
+ : null,
222
+ join.resolvable === false
223
+ ? {
224
+ kind: Kind.ARGUMENT,
225
+ name: {
226
+ kind: Kind.NAME,
227
+ value: 'resolvable',
228
+ },
229
+ value: {
230
+ kind: Kind.BOOLEAN,
231
+ value: false,
232
+ },
233
+ }
234
+ : null,
235
+ join.isInterfaceObject
236
+ ? {
237
+ kind: Kind.ARGUMENT,
238
+ name: {
239
+ kind: Kind.NAME,
240
+ value: 'isInterfaceObject',
241
+ },
242
+ value: {
243
+ kind: Kind.BOOLEAN,
244
+ value: true,
245
+ },
246
+ }
247
+ : null,
248
+ join.extension
249
+ ? {
250
+ kind: Kind.ARGUMENT,
251
+ name: {
252
+ kind: Kind.NAME,
253
+ value: 'extension',
254
+ },
255
+ value: {
256
+ kind: Kind.BOOLEAN,
257
+ value: true,
258
+ },
259
+ }
260
+ : null,
261
+ ].filter(nonEmpty),
262
+ };
263
+ }
264
+ function createJoinImplementsDirectiveNode(join) {
265
+ return {
266
+ kind: Kind.DIRECTIVE,
267
+ name: {
268
+ kind: Kind.NAME,
269
+ value: 'join__implements',
270
+ },
271
+ arguments: [
272
+ {
273
+ kind: Kind.ARGUMENT,
274
+ name: {
275
+ kind: Kind.NAME,
276
+ value: 'graph',
277
+ },
278
+ value: {
279
+ kind: Kind.ENUM,
280
+ value: join.graph,
281
+ },
282
+ },
283
+ {
284
+ kind: Kind.ARGUMENT,
285
+ name: {
286
+ kind: Kind.NAME,
287
+ value: 'interface',
288
+ },
289
+ value: {
290
+ kind: Kind.STRING,
291
+ value: join.interface,
292
+ },
293
+ },
294
+ ],
295
+ };
296
+ }
297
+ function createJoinFieldDirectiveNode(join) {
298
+ return {
299
+ kind: Kind.DIRECTIVE,
300
+ name: {
301
+ kind: Kind.NAME,
302
+ value: 'join__field',
303
+ },
304
+ arguments: [
305
+ join.graph
306
+ ? {
307
+ kind: Kind.ARGUMENT,
308
+ name: {
309
+ kind: Kind.NAME,
310
+ value: 'graph',
311
+ },
312
+ value: {
313
+ kind: Kind.ENUM,
314
+ value: join.graph,
315
+ },
316
+ }
317
+ : null,
318
+ join.type
319
+ ? {
320
+ kind: Kind.ARGUMENT,
321
+ name: {
322
+ kind: Kind.NAME,
323
+ value: 'type',
324
+ },
325
+ value: {
326
+ kind: Kind.STRING,
327
+ value: join.type,
328
+ },
329
+ }
330
+ : null,
331
+ join.override
332
+ ? {
333
+ kind: Kind.ARGUMENT,
334
+ name: {
335
+ kind: Kind.NAME,
336
+ value: 'override',
337
+ },
338
+ value: {
339
+ kind: Kind.STRING,
340
+ value: join.override,
341
+ },
342
+ }
343
+ : null,
344
+ join.external
345
+ ? {
346
+ kind: Kind.ARGUMENT,
347
+ name: {
348
+ kind: Kind.NAME,
349
+ value: 'external',
350
+ },
351
+ value: {
352
+ kind: Kind.BOOLEAN,
353
+ value: true,
354
+ },
355
+ }
356
+ : null,
357
+ join.provides
358
+ ? {
359
+ kind: Kind.ARGUMENT,
360
+ name: {
361
+ kind: Kind.NAME,
362
+ value: 'provides',
363
+ },
364
+ value: {
365
+ kind: Kind.STRING,
366
+ value: join.provides,
367
+ },
368
+ }
369
+ : null,
370
+ join.requires
371
+ ? {
372
+ kind: Kind.ARGUMENT,
373
+ name: {
374
+ kind: Kind.NAME,
375
+ value: 'requires',
376
+ },
377
+ value: {
378
+ kind: Kind.STRING,
379
+ value: join.requires,
380
+ },
381
+ }
382
+ : null,
383
+ ].filter(nonEmpty),
384
+ };
385
+ }
386
+ function createJoinUnionMemberDirectiveNode(join) {
387
+ return {
388
+ kind: Kind.DIRECTIVE,
389
+ name: {
390
+ kind: Kind.NAME,
391
+ value: 'join__unionMember',
392
+ },
393
+ arguments: [
394
+ {
395
+ kind: Kind.ARGUMENT,
396
+ name: {
397
+ kind: Kind.NAME,
398
+ value: 'graph',
399
+ },
400
+ value: {
401
+ kind: Kind.ENUM,
402
+ value: join.graph,
403
+ },
404
+ },
405
+ {
406
+ kind: Kind.ARGUMENT,
407
+ name: {
408
+ kind: Kind.NAME,
409
+ value: 'member',
410
+ },
411
+ value: {
412
+ kind: Kind.STRING,
413
+ value: join.member,
414
+ },
415
+ },
416
+ ],
417
+ };
418
+ }
419
+ function createJoinEnumValueDirectiveNode(join) {
420
+ return {
421
+ kind: Kind.DIRECTIVE,
422
+ name: {
423
+ kind: Kind.NAME,
424
+ value: 'join__enumValue',
425
+ },
426
+ arguments: [
427
+ {
428
+ kind: Kind.ARGUMENT,
429
+ name: {
430
+ kind: Kind.NAME,
431
+ value: 'graph',
432
+ },
433
+ value: {
434
+ kind: Kind.ENUM,
435
+ value: join.graph,
436
+ },
437
+ },
438
+ ],
439
+ };
440
+ }
441
+ function createInaccessibleDirectiveNode() {
442
+ return {
443
+ kind: Kind.DIRECTIVE,
444
+ name: {
445
+ kind: Kind.NAME,
446
+ value: 'inaccessible',
447
+ },
448
+ arguments: [],
449
+ };
450
+ }
451
+ function createTagDirectiveNode(name) {
452
+ return {
453
+ kind: Kind.DIRECTIVE,
454
+ name: {
455
+ kind: Kind.NAME,
456
+ value: 'tag',
457
+ },
458
+ arguments: [
459
+ {
460
+ kind: Kind.ARGUMENT,
461
+ name: {
462
+ kind: Kind.NAME,
463
+ value: 'name',
464
+ },
465
+ value: {
466
+ kind: Kind.STRING,
467
+ value: name,
468
+ },
469
+ },
470
+ ],
471
+ };
472
+ }
473
+ function createJoinGraphDirectiveNode(join) {
474
+ return {
475
+ kind: Kind.DIRECTIVE,
476
+ name: {
477
+ kind: Kind.NAME,
478
+ value: 'join__graph',
479
+ },
480
+ arguments: [
481
+ {
482
+ kind: Kind.ARGUMENT,
483
+ name: {
484
+ kind: Kind.NAME,
485
+ value: 'name',
486
+ },
487
+ value: {
488
+ kind: Kind.STRING,
489
+ value: join.name,
490
+ },
491
+ },
492
+ {
493
+ kind: Kind.ARGUMENT,
494
+ name: {
495
+ kind: Kind.NAME,
496
+ value: 'url',
497
+ },
498
+ value: {
499
+ kind: Kind.STRING,
500
+ value: join.url ?? '',
501
+ },
502
+ },
503
+ ],
504
+ };
505
+ }
506
+ function createDescriptionNode(description) {
507
+ return {
508
+ kind: Kind.STRING,
509
+ value: description.value,
510
+ block: true,
511
+ };
512
+ }
513
+ function createDeprecatedDirectiveNode(deprecated) {
514
+ return {
515
+ kind: Kind.DIRECTIVE,
516
+ name: {
517
+ kind: Kind.NAME,
518
+ value: 'deprecated',
519
+ },
520
+ arguments: typeof deprecated.reason === 'string'
521
+ ? [
522
+ {
523
+ kind: Kind.ARGUMENT,
524
+ name: {
525
+ kind: Kind.NAME,
526
+ value: 'reason',
527
+ },
528
+ value: {
529
+ kind: Kind.STRING,
530
+ value: deprecated.reason,
531
+ },
532
+ },
533
+ ]
534
+ : [],
535
+ };
536
+ }
537
+ function createSpecifiedByDirectiveNode(url) {
538
+ return {
539
+ kind: Kind.DIRECTIVE,
540
+ name: {
541
+ kind: Kind.NAME,
542
+ value: 'specifiedBy',
543
+ },
544
+ arguments: [
545
+ {
546
+ kind: Kind.ARGUMENT,
547
+ name: {
548
+ kind: Kind.NAME,
549
+ value: 'url',
550
+ },
551
+ value: {
552
+ kind: Kind.STRING,
553
+ value: url,
554
+ },
555
+ },
556
+ ],
557
+ };
558
+ }
559
+ function createLinkDirectiveNode(link) {
560
+ return {
561
+ kind: Kind.DIRECTIVE,
562
+ name: {
563
+ kind: Kind.NAME,
564
+ value: 'link',
565
+ },
566
+ arguments: [].concat([
567
+ {
568
+ kind: Kind.ARGUMENT,
569
+ name: {
570
+ kind: Kind.NAME,
571
+ value: 'url',
572
+ },
573
+ value: {
574
+ kind: Kind.STRING,
575
+ value: link.url,
576
+ },
577
+ },
578
+ ], link.for
579
+ ? [
580
+ {
581
+ kind: Kind.ARGUMENT,
582
+ name: {
583
+ kind: Kind.NAME,
584
+ value: 'for',
585
+ },
586
+ value: {
587
+ kind: Kind.ENUM,
588
+ value: link.for,
589
+ },
590
+ },
591
+ ]
592
+ : [], link.import
593
+ ? [
594
+ {
595
+ kind: Kind.ARGUMENT,
596
+ name: {
597
+ kind: Kind.NAME,
598
+ value: 'import',
599
+ },
600
+ value: {
601
+ kind: Kind.LIST,
602
+ values: link.import.map(imported => {
603
+ if (imported.alias) {
604
+ return {
605
+ kind: Kind.OBJECT,
606
+ fields: [
607
+ {
608
+ kind: Kind.OBJECT_FIELD,
609
+ name: {
610
+ kind: Kind.NAME,
611
+ value: 'name',
612
+ },
613
+ value: {
614
+ kind: Kind.STRING,
615
+ value: imported.name,
616
+ },
617
+ },
618
+ ],
619
+ };
620
+ }
621
+ return {
622
+ kind: Kind.STRING,
623
+ value: imported.name,
624
+ };
625
+ }),
626
+ },
627
+ },
628
+ ]
629
+ : []),
630
+ };
631
+ }
632
+ function createNamedTypeNode(name) {
633
+ return {
634
+ kind: Kind.NAMED_TYPE,
635
+ name: {
636
+ kind: Kind.NAME,
637
+ value: name,
638
+ },
639
+ };
640
+ }
641
+ function applyDirectives(common) {
642
+ return [].concat(common.ast?.directives ?? [], common.join?.type?.map(createJoinTypeDirectiveNode) ?? [], common.join?.implements?.map(createJoinImplementsDirectiveNode) ?? [], common.join?.field?.map(createJoinFieldDirectiveNode) ?? [], common.join?.unionMember?.map(createJoinUnionMemberDirectiveNode) ?? [], common.join?.enumValue?.map(createJoinEnumValueDirectiveNode) ?? [], common.tags?.map(createTagDirectiveNode) ?? [], common.inaccessible ? [createInaccessibleDirectiveNode()] : [], common.deprecated ? [createDeprecatedDirectiveNode(common.deprecated)] : [], common.specifiedBy ? [createSpecifiedByDirectiveNode(common.specifiedBy)] : []);
643
+ }
644
+ function nonEmpty(value) {
645
+ return value != null;
646
+ }
647
+ const buildInDirectives = new Set(specifiedDirectives.map(directive => directive.name));
648
+ function isBuiltInDirective(directiveName) {
649
+ return buildInDirectives.has(directiveName);
650
+ }
651
+ function isFederationDirective(name) {
652
+ return (name === 'tag' || name === 'link' || name.startsWith('join__') || name.startsWith('link__'));
653
+ }
654
+ function isFederationEnum(name) {
655
+ return name.startsWith('join__') || name.startsWith('link__');
656
+ }
657
+ function isFederationScalar(name) {
658
+ return name.startsWith('join__') || name.startsWith('link__');
659
+ }
660
+ export function schemaCoordinate(paths, nodes) {
661
+ let coordinate = '';
662
+ for (let i = 0; i < Math.max(paths.length, nodes.length); i++) {
663
+ const prop = paths[i];
664
+ const current = nodes[i];
665
+ if (typeof prop === 'number' && Array.isArray(current)) {
666
+ const node = current[prop];
667
+ if (coordinate.length > 0) {
668
+ coordinate = coordinate + '.' + node.name.value;
669
+ }
670
+ else {
671
+ coordinate = node.name.value;
672
+ }
673
+ }
674
+ }
675
+ return coordinate;
676
+ }
677
+ export function stripFederation(supergraph) {
678
+ const inaccessible = new Set();
679
+ const documentWithoutFederation = visit(supergraph, visitInParallel([
680
+ {
681
+ DirectiveDefinition(node) {
682
+ if (isBuiltInDirective(node.name.value) || isFederationDirective(node.name.value)) {
683
+ return null;
684
+ }
685
+ },
686
+ Directive(node) {
687
+ if (isBuiltInDirective(node.name.value) || isFederationDirective(node.name.value)) {
688
+ return null;
689
+ }
690
+ },
691
+ EnumTypeDefinition(node) {
692
+ if (isFederationEnum(node.name.value)) {
693
+ return null;
694
+ }
695
+ },
696
+ ScalarTypeDefinition(node) {
697
+ if (isFederationScalar(node.name.value)) {
698
+ return null;
699
+ }
700
+ },
701
+ },
702
+ {
703
+ Directive(directive, _, __, paths, nodes) {
704
+ if (directive.name.value === 'inaccessible') {
705
+ inaccessible.add(schemaCoordinate(paths, nodes));
706
+ }
707
+ },
708
+ },
709
+ ]));
710
+ if (inaccessible.size === 0) {
711
+ return documentWithoutFederation;
712
+ }
713
+ function hideByNodeName(node) {
714
+ if (inaccessible.has(node.name.value)) {
715
+ return null;
716
+ }
717
+ }
718
+ function hideObjectOrInterface(node) {
719
+ if (inaccessible.has(node.name.value)) {
720
+ return null;
721
+ }
722
+ const inaccessibleInterfaces = node.interfaces?.filter(i => inaccessible.has(i.name.value));
723
+ if (inaccessibleInterfaces?.length) {
724
+ return {
725
+ ...node,
726
+ interfaces: node.interfaces?.filter(i => !inaccessible.has(i.name.value)),
727
+ };
728
+ }
729
+ }
730
+ function hideField(node, _, __, paths, nodes) {
731
+ if (inaccessible.has(schemaCoordinate(paths, nodes) + '.' + node.name.value)) {
732
+ return null;
733
+ }
734
+ if (inaccessible.has(namedTypeFromTypeNode(node.type).name.value)) {
735
+ return null;
736
+ }
737
+ }
738
+ return visit(documentWithoutFederation, {
739
+ ObjectTypeDefinition: hideObjectOrInterface,
740
+ InterfaceTypeDefinition: hideObjectOrInterface,
741
+ InputObjectTypeDefinition: hideByNodeName,
742
+ EnumTypeDefinition: hideByNodeName,
743
+ UnionTypeDefinition: hideByNodeName,
744
+ ScalarTypeDefinition: hideByNodeName,
745
+ FieldDefinition: hideField,
746
+ InputValueDefinition: hideField,
747
+ EnumValueDefinition(node, _, __, paths, nodes) {
748
+ if (inaccessible.has(schemaCoordinate(paths, nodes) + '.' + node.name.value)) {
749
+ return null;
750
+ }
751
+ },
752
+ });
753
+ }
754
+ function namedTypeFromTypeNode(type) {
755
+ if (type.kind === Kind.NAMED_TYPE) {
756
+ return type;
757
+ }
758
+ if (type.kind === Kind.LIST_TYPE) {
759
+ return namedTypeFromTypeNode(type.type);
760
+ }
761
+ if (type.kind === Kind.NON_NULL_TYPE) {
762
+ return namedTypeFromTypeNode(type.type);
763
+ }
764
+ throw new Error('Unknown type node: ' + type);
765
+ }