@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,323 @@
1
+ import { concatAST, GraphQLError, Kind, parse, visit, visitInParallel, } from 'graphql';
2
+ import { TypeNodeInfo, visitWithTypeNodeInfo } from '../../graphql/type-node-info.js';
3
+ import { createSpecSchema } from '../../specifications/federation.js';
4
+ import { parseLinkDirective } from '../../specifications/link.js';
5
+ import { ComposeDirectiveRules } from './rules/elements/compose-directive.js';
6
+ import { ExtendsRules } from './rules/elements/extends.js';
7
+ import { ExternalRules } from './rules/elements/external.js';
8
+ import { FieldSetRules } from './rules/elements/field-set.js';
9
+ import { InaccessibleRules } from './rules/elements/inaccessible.js';
10
+ import { KeyRules } from './rules/elements/key.js';
11
+ import { OverrideRules } from './rules/elements/override.js';
12
+ import { ProvidesRules } from './rules/elements/provides.js';
13
+ import { RequiresRules } from './rules/elements/requires.js';
14
+ import { ShareableRules } from './rules/elements/shareable.js';
15
+ import { TagRules } from './rules/elements/tag.js';
16
+ import { KnownArgumentNamesOnDirectivesRule } from './rules/known-argument-names-on-directives-rule.js';
17
+ import { KnownDirectivesRule } from './rules/known-directives-rule.js';
18
+ import { KnownFederationDirectivesRule } from './rules/known-federation-directive-rule.js';
19
+ import { KnownRootTypeRule } from './rules/known-root-type-rule.js';
20
+ import { KnownTypeNamesRule } from './rules/known-type-names-rule.js';
21
+ import { LoneSchemaDefinitionRule } from './rules/lone-schema-definition-rule.js';
22
+ import { ProvidedArgumentsOnDirectivesRule } from './rules/provided-arguments-on-directives-rule.js';
23
+ import { ProvidedRequiredArgumentsOnDirectivesRule } from './rules/provided-required-arguments-on-directives-rule.js';
24
+ import { QueryRootTypeInaccessibleRule } from './rules/query-root-type-inaccessible-rule.js';
25
+ import { ReservedSubgraphNameRule } from './rules/reserved-subgraph-name-rule.js';
26
+ import { RootTypeUsedRule } from './rules/root-type-used-rule.js';
27
+ import { UniqueArgumentDefinitionNamesRule } from './rules/unique-argument-definition-names-rule.js';
28
+ import { UniqueArgumentNamesRule } from './rules/unique-argument-names-rule.js';
29
+ import { UniqueDirectiveNamesRule } from './rules/unique-directive-names-rule.js';
30
+ import { UniqueDirectivesPerLocationRule } from './rules/unique-directives-per-location-rule.js';
31
+ import { UniqueEnumValueNamesRule } from './rules/unique-enum-value-names-rule.js';
32
+ import { UniqueFieldDefinitionNamesRule } from './rules/unique-field-definition-names-rule.js';
33
+ import { UniqueInputFieldNamesRule } from './rules/unique-input-field-names-rule.js';
34
+ import { UniqueOperationTypesRule } from './rules/unique-operation-types-rule.js';
35
+ import { UniqueTypeNamesRule } from './rules/unique-type-names-rule.js';
36
+ import { validateSubgraphState } from './validate-state.js';
37
+ import { createSimpleValidationContext, createSubgraphValidationContext, } from './validation-context.js';
38
+ export function assertUniqueSubgraphNames(subgraphs) {
39
+ const names = new Set();
40
+ for (const subgraph of subgraphs) {
41
+ if (names.has(subgraph.name)) {
42
+ throw new Error(`A subgraph named ${subgraph.name} already exists`);
43
+ }
44
+ names.add(subgraph.name);
45
+ }
46
+ }
47
+ export function validateSubgraphCore(subgraph) {
48
+ const extractedLinks = extractLinks(subgraph);
49
+ if (extractedLinks.errors) {
50
+ extractedLinks.errors.forEach(error => enrichErrorWithSubgraphName(error, subgraph.name));
51
+ }
52
+ return extractedLinks;
53
+ }
54
+ export function validateSubgraph(subgraph, stateBuilder, federation, __internal) {
55
+ subgraph.typeDefs = cleanSubgraphTypeDefsFromSubgraphSpec(subgraph.typeDefs);
56
+ const rulesToSkip = __internal?.disableValidationRules ?? [];
57
+ const typeNodeInfo = new TypeNodeInfo();
58
+ const validationContext = createSubgraphValidationContext(subgraph, federation, typeNodeInfo, stateBuilder);
59
+ const federationRules = [
60
+ ReservedSubgraphNameRule,
61
+ KnownFederationDirectivesRule,
62
+ FieldSetRules,
63
+ InaccessibleRules,
64
+ OverrideRules,
65
+ ExtendsRules,
66
+ QueryRootTypeInaccessibleRule,
67
+ KnownTypeNamesRule,
68
+ KnownRootTypeRule,
69
+ RootTypeUsedRule,
70
+ ShareableRules,
71
+ KeyRules,
72
+ ProvidesRules,
73
+ RequiresRules,
74
+ ExternalRules,
75
+ TagRules,
76
+ ComposeDirectiveRules,
77
+ ];
78
+ const graphqlRules = [
79
+ LoneSchemaDefinitionRule,
80
+ UniqueOperationTypesRule,
81
+ UniqueTypeNamesRule,
82
+ UniqueEnumValueNamesRule,
83
+ UniqueFieldDefinitionNamesRule,
84
+ UniqueArgumentDefinitionNamesRule,
85
+ KnownDirectivesRule,
86
+ UniqueDirectivesPerLocationRule,
87
+ KnownArgumentNamesOnDirectivesRule,
88
+ UniqueArgumentNamesRule,
89
+ UniqueInputFieldNamesRule,
90
+ UniqueDirectiveNamesRule,
91
+ ProvidedRequiredArgumentsOnDirectivesRule,
92
+ ProvidedArgumentsOnDirectivesRule,
93
+ ];
94
+ visit(subgraph.typeDefs, visitWithTypeNodeInfo(typeNodeInfo, visitInParallel([stateBuilder.visitor(typeNodeInfo)].concat(federationRules.map(rule => {
95
+ if (rulesToSkip.includes(rule.name)) {
96
+ return {};
97
+ }
98
+ return rule(validationContext);
99
+ })))));
100
+ const federationDefinitionReplacements = validationContext.collectFederationDefinitionReplacements();
101
+ const fullTypeDefs = concatAST([
102
+ {
103
+ kind: Kind.DOCUMENT,
104
+ definitions: validationContext
105
+ .getAvailableFederationTypeAndDirectiveDefinitions()
106
+ .filter(def => !federationDefinitionReplacements.has(def.name.value)),
107
+ },
108
+ validationContext.satisfiesVersionRange('> v1.0') && !stateBuilder.state.specs.link
109
+ ?
110
+ parse(`
111
+ scalar Import
112
+ enum Purpose {
113
+ EXECUTION
114
+ SECURITY
115
+ }
116
+
117
+ directive @link(
118
+ url: String
119
+ as: String
120
+ for: link__Purpose
121
+ import: [link__Import]
122
+ ) repeatable on SCHEMA
123
+
124
+ scalar link__Import
125
+
126
+ enum link__Purpose {
127
+ """
128
+ \`SECURITY\` features provide metadata necessary to securely resolve fields.
129
+ """
130
+ SECURITY
131
+
132
+ """
133
+ \`EXECUTION\` features provide metadata necessary for operation execution.
134
+ """
135
+ EXECUTION
136
+ }
137
+ `)
138
+ : null,
139
+ subgraph.typeDefs,
140
+ ].filter(onlyDocumentNode));
141
+ const subgraphStateErrors = validateSubgraphState(stateBuilder.state);
142
+ const simpleValidationContext = createSimpleValidationContext(fullTypeDefs, typeNodeInfo);
143
+ visit(fullTypeDefs, visitInParallel(graphqlRules.map(rule => {
144
+ if (rulesToSkip.includes(rule.name)) {
145
+ return {};
146
+ }
147
+ return rule(simpleValidationContext);
148
+ })));
149
+ return validationContext
150
+ .collectReportedErrors()
151
+ .concat(validationContext.collectUnusedExternal().map(coordinate => enrichErrorWithSubgraphName(new GraphQLError(`Field "${coordinate}" is marked @external but is not used in any federation directive (@key, @provides, @requires) or to satisfy an interface; the field declaration has no use and should be removed (or the field should not be @external).`, {
152
+ extensions: {
153
+ code: 'EXTERNAL_UNUSED',
154
+ },
155
+ }), subgraph.name)))
156
+ .concat(simpleValidationContext.collectReportedErrors())
157
+ .concat(subgraphStateErrors)
158
+ .map(error => enrichErrorWithSubgraphName(error, subgraph.name));
159
+ }
160
+ function enrichErrorWithSubgraphName(error, subgraphName) {
161
+ if (error.extensions.subgraphName) {
162
+ return error;
163
+ }
164
+ error.message = `[${subgraphName}] ${error.message}`;
165
+ error.extensions.subgraphName = subgraphName;
166
+ return error;
167
+ }
168
+ const availableFeatures = {
169
+ link: ['v1.0'],
170
+ tag: ['v0.1', 'v0.2'],
171
+ kotlin_labs: ['v0.1', 'v0.2'],
172
+ join: ['v0.1', 'v0.2', 'v0.3'],
173
+ inaccessible: ['v0.1', 'v0.2'],
174
+ core: ['v0.1', 'v0.2'],
175
+ };
176
+ function extractLinks(subgraph) {
177
+ const schemaNodes = subgraph.typeDefs.definitions.filter(isSchemaDefinitionOrExtensionNode);
178
+ if (schemaNodes.length === 0) {
179
+ return {
180
+ links: [],
181
+ };
182
+ }
183
+ const linkDirectives = [];
184
+ for (const schemaNode of schemaNodes) {
185
+ if (schemaNode.directives?.length) {
186
+ for (const directiveNode of schemaNode.directives) {
187
+ if (directiveNode.name.value === 'link') {
188
+ linkDirectives.push(directiveNode);
189
+ }
190
+ }
191
+ }
192
+ }
193
+ if (!linkDirectives) {
194
+ return {
195
+ links: [],
196
+ };
197
+ }
198
+ const errors = [];
199
+ const links = [];
200
+ const identities = new Set();
201
+ const reportedAsDuplicate = new Set();
202
+ for (let i = 0; i < linkDirectives.length; i++) {
203
+ const linkDirective = linkDirectives[i];
204
+ try {
205
+ const link = parseLinkDirective(linkDirective);
206
+ if (!link) {
207
+ continue;
208
+ }
209
+ if (identities.has(link.identity) && !reportedAsDuplicate.has(link.identity)) {
210
+ errors.push(new GraphQLError(`Duplicate inclusion of feature ${link.identity}`, {
211
+ extensions: {
212
+ code: 'INVALID_LINK_DIRECTIVE_USAGE',
213
+ },
214
+ }));
215
+ reportedAsDuplicate.add(link.identity);
216
+ }
217
+ identities.add(link.identity);
218
+ if (link.version && !/^v\d+\.\d+/.test(link.version)) {
219
+ errors.push(new GraphQLError(`Expected a version string (of the form v1.2), got ${link.version}`, {
220
+ extensions: {
221
+ code: 'INVALID_LINK_IDENTIFIER',
222
+ },
223
+ }));
224
+ continue;
225
+ }
226
+ if (!link.name) {
227
+ errors.push(new GraphQLError(`Missing path in feature url '${link.identity}'`, {
228
+ extensions: {
229
+ code: 'INVALID_LINK_IDENTIFIER',
230
+ },
231
+ }));
232
+ continue;
233
+ }
234
+ if (link.identity.startsWith('https://specs.apollo.dev/')) {
235
+ if (link.name === 'federation') {
236
+ if (!link.version) {
237
+ errors.push(new GraphQLError(`Missing version in feature url '${link.identity}'`, {
238
+ extensions: {
239
+ code: 'TODO',
240
+ },
241
+ }));
242
+ continue;
243
+ }
244
+ const spec = createSpecSchema(link.version);
245
+ const availableElements = new Set(spec.directives.map(d => d.name.value).concat(spec.types.map(t => t.name.value)));
246
+ let pushedError = false;
247
+ for (const im of link.imports) {
248
+ if (!availableElements.has(im.name.replace(/^@/, ''))) {
249
+ pushedError = true;
250
+ errors.push(new GraphQLError(`Cannot import unknown element "${im.name}".`, {
251
+ extensions: {
252
+ code: 'INVALID_LINK_DIRECTIVE_USAGE',
253
+ },
254
+ }));
255
+ }
256
+ }
257
+ if (pushedError) {
258
+ continue;
259
+ }
260
+ }
261
+ else if (link.version && availableFeatures[link.name]) {
262
+ if (!availableFeatures[link.name].includes(link.version)) {
263
+ errors.push(new GraphQLError(`Schema uses unknown version ${link.version} of the ${link.name} spec`, {
264
+ extensions: {
265
+ code: 'UNKNOWN_LINK_VERSION',
266
+ },
267
+ }));
268
+ continue;
269
+ }
270
+ }
271
+ }
272
+ links.push(link);
273
+ }
274
+ catch (error) {
275
+ errors.push(error instanceof GraphQLError ? error : new GraphQLError(String(error)));
276
+ }
277
+ }
278
+ if (errors.length > 0) {
279
+ return {
280
+ errors,
281
+ };
282
+ }
283
+ return {
284
+ links,
285
+ };
286
+ }
287
+ function isSchemaDefinitionOrExtensionNode(node) {
288
+ return (node.kind === Kind.SCHEMA_DEFINITION || node.kind === Kind.SCHEMA_EXTENSION);
289
+ }
290
+ function onlyDocumentNode(item) {
291
+ return item != null;
292
+ }
293
+ function cleanSubgraphTypeDefsFromSubgraphSpec(typeDefs) {
294
+ let queryTypes = [];
295
+ typeDefs.definitions = typeDefs.definitions.filter(def => {
296
+ if (def.kind === Kind.SCALAR_TYPE_DEFINITION && def.name.value === '_Any') {
297
+ return false;
298
+ }
299
+ if (def.kind === Kind.UNION_TYPE_DEFINITION && def.name.value === '_Entity') {
300
+ return false;
301
+ }
302
+ if (def.kind === Kind.OBJECT_TYPE_DEFINITION && def.name.value === '_Service') {
303
+ return false;
304
+ }
305
+ if ((def.kind === Kind.OBJECT_TYPE_DEFINITION || def.kind === Kind.OBJECT_TYPE_EXTENSION) &&
306
+ def.name.value === 'Query') {
307
+ queryTypes.push(def);
308
+ }
309
+ return true;
310
+ });
311
+ if (queryTypes.length > 0) {
312
+ for (const queryType of queryTypes) {
313
+ queryType.fields =
314
+ queryType.fields?.filter(field => {
315
+ if (field.name.value === '_service' || field.name.value === '_entities') {
316
+ return false;
317
+ }
318
+ return true;
319
+ }) ?? [];
320
+ }
321
+ }
322
+ return typeDefs;
323
+ }
@@ -0,0 +1,262 @@
1
+ import { Kind, specifiedScalarTypes, } from 'graphql';
2
+ import { createSpecSchema } from '../../specifications/federation.js';
3
+ import { stripTypeModifiers } from '../../utils/state.js';
4
+ import { TypeKind } from '../state.js';
5
+ export function createSimpleValidationContext(typeDefs, typeNodeInfo) {
6
+ let reportedErrors = [];
7
+ const directiveDefinitionMap = new Map();
8
+ const typeDefinitionMap = new Map();
9
+ for (const definition of typeDefs.definitions) {
10
+ if (definition.kind === Kind.DIRECTIVE_DEFINITION) {
11
+ directiveDefinitionMap.set(definition.name.value, definition);
12
+ }
13
+ else if ('name' in definition && definition.name && definition.name.kind === Kind.NAME) {
14
+ typeDefinitionMap.set(definition.name.value, {
15
+ name: definition.name,
16
+ kind: definition.kind,
17
+ });
18
+ }
19
+ }
20
+ return {
21
+ getDocument() {
22
+ return typeDefs;
23
+ },
24
+ getKnownDirectiveDefinition(name) {
25
+ return directiveDefinitionMap.get(name);
26
+ },
27
+ getKnownTypeDefinition(name) {
28
+ return typeDefinitionMap.get(name);
29
+ },
30
+ getSchemaCoordinate(ancestors) {
31
+ let coordinate = '';
32
+ for (let i = 0; i < ancestors.length; i++) {
33
+ const ancestor = ancestors[i];
34
+ if ('kind' in ancestor && ancestor.kind !== Kind.DOCUMENT) {
35
+ const name = ancestor.kind === Kind.SCHEMA_DEFINITION || ancestor.kind === Kind.SCHEMA_EXTENSION
36
+ ? 'schema'
37
+ : 'name' in ancestor && ancestor.name
38
+ ? ancestor.name.value
39
+ : '';
40
+ if (coordinate.length > 0) {
41
+ coordinate = coordinate + '.' + name;
42
+ }
43
+ else {
44
+ coordinate = name;
45
+ }
46
+ }
47
+ }
48
+ return coordinate;
49
+ },
50
+ reportError(error) {
51
+ reportedErrors.push(error);
52
+ },
53
+ collectReportedErrors() {
54
+ const errors = reportedErrors;
55
+ reportedErrors = [];
56
+ return errors;
57
+ },
58
+ };
59
+ }
60
+ export function createSubgraphValidationContext(subgraph, federation, typeNodeInfo, stateBuilder) {
61
+ const { version, imports } = federation;
62
+ const availableSpec = createSpecSchema(version, imports);
63
+ const knownSpec = createSpecSchema(version);
64
+ const knownSubgraphEntities = new Map(subgraph.typeDefs.definitions.filter(def => def.kind === Kind.OBJECT_TYPE_DEFINITION ||
65
+ def.kind === Kind.OBJECT_TYPE_EXTENSION ||
66
+ def.kind === Kind.INTERFACE_TYPE_DEFINITION ||
67
+ def.kind === Kind.INTERFACE_TYPE_EXTENSION).map(def => [def.name.value, def]));
68
+ const knownSubgraphDirectiveDefinitions = new Map(subgraph.typeDefs.definitions.filter(def => def.kind === Kind.DIRECTIVE_DEFINITION).map(def => [def.name.value, def]));
69
+ const leafTypeNames = new Set(specifiedScalarTypes.map(type => type.name));
70
+ for (const def of subgraph.typeDefs.definitions) {
71
+ if (def.kind === Kind.SCALAR_TYPE_DEFINITION ||
72
+ def.kind === Kind.SCALAR_TYPE_EXTENSION ||
73
+ def.kind === Kind.ENUM_TYPE_DEFINITION ||
74
+ def.kind === Kind.ENUM_TYPE_EXTENSION) {
75
+ leafTypeNames.add(def.name.value);
76
+ }
77
+ }
78
+ let reportedErrors = [];
79
+ const markedAsExternal = new Set();
80
+ const markedAsUsed = new Set();
81
+ const markedAsKeyField = new Set();
82
+ const overwrittenFederationDefinitionNames = new Set();
83
+ const directiveAlternativeNamesMap = new Map();
84
+ for (const specDirective of availableSpec.directives) {
85
+ const isFederationPrefixed = specDirective.name.value.startsWith('federation__');
86
+ if (isFederationPrefixed) {
87
+ const normalizedName = specDirective.name.value.replace('federation__', '');
88
+ const setOfNames = directiveAlternativeNamesMap.get(normalizedName);
89
+ if (!setOfNames) {
90
+ directiveAlternativeNamesMap.set(normalizedName, new Set([specDirective.name.value]));
91
+ }
92
+ }
93
+ else {
94
+ const { alias } = imports.find(i => i.name.replace(/^@/, '') === specDirective.name.value) ?? {
95
+ alias: undefined,
96
+ };
97
+ let setOfNames = directiveAlternativeNamesMap.get(specDirective.name.value);
98
+ if (!setOfNames) {
99
+ directiveAlternativeNamesMap.set(specDirective.name.value, new Set());
100
+ setOfNames = directiveAlternativeNamesMap.get(specDirective.name.value);
101
+ }
102
+ setOfNames.add(alias ? alias.replace(/^@/, '') : specDirective.name.value);
103
+ }
104
+ }
105
+ const typeAlternativeNamesMap = new Map();
106
+ for (const specType of availableSpec.types) {
107
+ const isFederationPrefixed = specType.name.value.startsWith('federation__');
108
+ if (isFederationPrefixed) {
109
+ const normalizedName = specType.name.value.replace('federation__', '');
110
+ const setOfNames = typeAlternativeNamesMap.get(normalizedName);
111
+ if (!setOfNames) {
112
+ typeAlternativeNamesMap.set(normalizedName, new Set([specType.name.value]));
113
+ }
114
+ }
115
+ else {
116
+ const { alias } = imports.find(i => i.name === specType.name.value) ?? {
117
+ alias: undefined,
118
+ };
119
+ let setOfNames = typeAlternativeNamesMap.get(specType.name.value);
120
+ if (!setOfNames) {
121
+ typeAlternativeNamesMap.set(specType.name.value, new Set());
122
+ setOfNames = typeAlternativeNamesMap.get(specType.name.value);
123
+ }
124
+ setOfNames.add(alias ? alias : specType.name.value);
125
+ }
126
+ }
127
+ const importedTypesSet = new Set(availableSpec.types.map(t => t.name.value));
128
+ if (importedTypesSet.size) {
129
+ subgraph.typeDefs.definitions.forEach(def => {
130
+ if ('name' in def && def.name && importedTypesSet.has(def.name.value)) {
131
+ overwrittenFederationDefinitionNames.add(def.name.value);
132
+ }
133
+ });
134
+ }
135
+ return {
136
+ stateBuilder,
137
+ isAvailableFederationType(name) {
138
+ const alternativeNames = typeAlternativeNamesMap.get(name);
139
+ if (alternativeNames) {
140
+ return alternativeNames.has(name);
141
+ }
142
+ return false;
143
+ },
144
+ isAvailableFederationDirective(specDirectiveName, directiveNode) {
145
+ const alternativeNames = directiveAlternativeNamesMap.get(specDirectiveName);
146
+ if (alternativeNames) {
147
+ return alternativeNames.has(typeof directiveNode.name === 'string' ? directiveNode.name : directiveNode.name.value);
148
+ }
149
+ return false;
150
+ },
151
+ satisfiesVersionRange(range) {
152
+ const [sign, ver] = range.split(' ');
153
+ const versionInRange = parseFloat(ver.replace('v', ''));
154
+ const detectedVersion = parseFloat(version.replace('v', ''));
155
+ if (sign === '<') {
156
+ return detectedVersion < versionInRange;
157
+ }
158
+ if (sign === '>') {
159
+ return detectedVersion > versionInRange;
160
+ }
161
+ return detectedVersion >= versionInRange;
162
+ },
163
+ getKnownFederationDirectives() {
164
+ return knownSpec.directives;
165
+ },
166
+ getAvailableFederationDirectives() {
167
+ return availableSpec.directives;
168
+ },
169
+ isLeafType(typeName) {
170
+ return leafTypeNames.has(typeName);
171
+ },
172
+ getSubgraphObjectOrInterfaceTypes() {
173
+ return knownSubgraphEntities;
174
+ },
175
+ getSubgraphDirectiveDefinitions() {
176
+ return knownSubgraphDirectiveDefinitions;
177
+ },
178
+ getAvailableFederationTypeAndDirectiveDefinitions() {
179
+ return [].concat(availableSpec.directives.map(d => {
180
+ const alias = imports.find(i => i.name.replace(/^@/, '') === d.name.value)?.alias;
181
+ if (alias) {
182
+ d.name.value = alias.replace(/^@/, '');
183
+ }
184
+ return d;
185
+ }), availableSpec.types.map(t => {
186
+ const alias = imports.find(i => i.name === t.name.value)?.alias;
187
+ if (alias) {
188
+ t.name.value = alias;
189
+ }
190
+ return t;
191
+ }));
192
+ },
193
+ typeNodeInfo,
194
+ getDocument() {
195
+ return subgraph.typeDefs;
196
+ },
197
+ getSubgraphName() {
198
+ return subgraph.name;
199
+ },
200
+ getSubgraphId() {
201
+ return subgraph.id;
202
+ },
203
+ markAsExternal(coordinate) {
204
+ markedAsExternal.add(coordinate);
205
+ },
206
+ markAsUsed(reason, kind, typeName, fieldName) {
207
+ if (!fieldName.startsWith('__') && !typeName.startsWith('__') && reason === 'fields') {
208
+ switch (kind) {
209
+ case Kind.OBJECT_TYPE_DEFINITION:
210
+ case Kind.OBJECT_TYPE_EXTENSION: {
211
+ stateBuilder.objectType.field.setUsed(typeName, fieldName);
212
+ break;
213
+ }
214
+ case Kind.INTERFACE_TYPE_DEFINITION:
215
+ case Kind.INTERFACE_TYPE_EXTENSION: {
216
+ stateBuilder.interfaceType.field.setUsed(typeName, fieldName);
217
+ break;
218
+ }
219
+ }
220
+ }
221
+ markedAsUsed.add(`${typeName}.${fieldName}`);
222
+ },
223
+ markAsKeyField(coordinate) {
224
+ markedAsKeyField.add(coordinate);
225
+ },
226
+ markAsFederationDefinitionReplacement(name) {
227
+ overwrittenFederationDefinitionNames.add(name);
228
+ },
229
+ collectFederationDefinitionReplacements() {
230
+ return overwrittenFederationDefinitionNames;
231
+ },
232
+ collectUnusedExternal() {
233
+ if (version === 'v1.0') {
234
+ return Array.from(markedAsExternal).filter(c => !markedAsUsed.has(c) && markedAsKeyField.has(c));
235
+ }
236
+ const unused = Array.from(markedAsExternal).filter(c => !markedAsUsed.has(c));
237
+ return unused.filter(coordinate => {
238
+ const [typeName, fieldName] = coordinate.split('.');
239
+ const typeDef = stateBuilder.state.types.get(typeName);
240
+ if (typeDef && typeDef.kind === TypeKind.OBJECT) {
241
+ const fieldDef = typeDef.fields.get(fieldName);
242
+ if (fieldDef) {
243
+ const outputTypeName = stripTypeModifiers(fieldDef.type);
244
+ const outputType = stateBuilder.state.types.get(outputTypeName);
245
+ if (outputType?.kind === TypeKind.OBJECT && outputType.shareable) {
246
+ return false;
247
+ }
248
+ }
249
+ }
250
+ return true;
251
+ });
252
+ },
253
+ reportError(error) {
254
+ reportedErrors.push(error);
255
+ },
256
+ collectReportedErrors() {
257
+ const errors = reportedErrors;
258
+ reportedErrors = [];
259
+ return errors;
260
+ },
261
+ };
262
+ }