@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,866 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SatisfiabilityRule = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const helpers_js_1 = require("../../../subgraph/helpers.js");
6
+ const state_js_1 = require("../../../subgraph/state.js");
7
+ const dependency_graph_js_1 = require("../../../utils/dependency-graph.js");
8
+ const helpers_js_2 = require("../../../utils/helpers.js");
9
+ const state_js_2 = require("../../../utils/state.js");
10
+ function canGraphMoveToGraph(supergraphState, objectTypeState, sourceGraphId, targetGraphId) {
11
+ const sourceGraphKeys = objectTypeState.byGraph.get(sourceGraphId).keys;
12
+ const targetGraphKeys = objectTypeState.byGraph.get(targetGraphId).keys;
13
+ if (sourceGraphKeys.length === 0 && targetGraphKeys.length === 0) {
14
+ return false;
15
+ }
16
+ const fieldsOfSourceGraph = Array.from(objectTypeState.fields.values()).filter(f => f.byGraph.get(sourceGraphId));
17
+ const nonExternalFieldsOfSourceGraph = fieldsOfSourceGraph.filter(f => f.byGraph.get(sourceGraphId).external === false);
18
+ if (sourceGraphKeys.length === 0) {
19
+ return targetGraphKeys
20
+ .filter(k => k.resolvable === true)
21
+ .some(k => {
22
+ const targetKeyFields = resolveFieldsFromFieldSet(k.fields, objectTypeState.name, targetGraphId, supergraphState);
23
+ return Array.from(targetKeyFields.coordinates).every(fieldPath => {
24
+ const [typeName, fieldName] = fieldPath.split('.');
25
+ if (typeName === objectTypeState.name) {
26
+ const fieldState = objectTypeState.fields.get(fieldName);
27
+ if (!fieldState) {
28
+ throw new Error(`Field "${fieldPath}" not found in object type "${typeName}"`);
29
+ }
30
+ const fieldStateByGraph = fieldState.byGraph.get(targetGraphId);
31
+ if (!fieldStateByGraph) {
32
+ throw new Error(`Field "${fieldPath}" not found in object type "${typeName}" in graph "${targetGraphId}"`);
33
+ }
34
+ return fieldStateByGraph.external === false;
35
+ }
36
+ const currentTypeState = supergraphState.objectTypes.get(typeName) ??
37
+ supergraphState.interfaceTypes.get(typeName);
38
+ if (!currentTypeState) {
39
+ throw new Error(`Type "${typeName}" not found`);
40
+ }
41
+ const fieldState = currentTypeState.fields.get(fieldName);
42
+ if (!fieldState) {
43
+ throw new Error(`Field "${fieldPath}" not found in object type "${typeName}"`);
44
+ }
45
+ const fieldStateByGraph = fieldState.byGraph.get(targetGraphId);
46
+ if (!fieldStateByGraph) {
47
+ throw new Error(`Field "${fieldPath}" not found in object type "${typeName}" in graph "${targetGraphId}"`);
48
+ }
49
+ if ('external' in fieldStateByGraph) {
50
+ return fieldStateByGraph.external === false;
51
+ }
52
+ return true;
53
+ });
54
+ });
55
+ }
56
+ return sourceGraphKeys.some(sourceGraphKey => {
57
+ const sourceKeyFields = resolveFieldsFromFieldSet(sourceGraphKey.fields, objectTypeState.name, sourceGraphId, supergraphState);
58
+ return (targetGraphKeys
59
+ .filter(k => k.resolvable === true)
60
+ .some(k => {
61
+ const targetKeyFields = resolveFieldsFromFieldSet(k.fields, objectTypeState.name, targetGraphId, supergraphState);
62
+ for (const fieldPath of targetKeyFields.paths) {
63
+ if (!sourceKeyFields.paths.has(fieldPath)) {
64
+ return false;
65
+ }
66
+ }
67
+ return true;
68
+ }));
69
+ });
70
+ }
71
+ function canGraphResolveFieldDirectly(objectTypeSuperState, fieldSuperState, graphId, supergraphState) {
72
+ const objectTypeInGraph = objectTypeSuperState.byGraph.get(graphId);
73
+ if (!objectTypeInGraph) {
74
+ throw new Error(`Object type "${objectTypeSuperState.name}" not found in graph "${graphId}"`);
75
+ }
76
+ const fieldInGraph = fieldSuperState.byGraph.get(graphId);
77
+ if (!fieldInGraph) {
78
+ return false;
79
+ }
80
+ if ((fieldInGraph.shareable === true ||
81
+ objectTypeSuperState.byGraph.get(graphId).shareable === true) &&
82
+ supergraphState.graphs.get(graphId).version !== 'v1.0') {
83
+ return true;
84
+ }
85
+ if (fieldInGraph.external === true) {
86
+ if (fieldInGraph.usedAsKey === true) {
87
+ const graphHasAtLeastOneResolvableField = Array.from(objectTypeSuperState.fields.values()).some(f => {
88
+ if (f.name === fieldSuperState.name) {
89
+ return false;
90
+ }
91
+ const fInGraph = f.byGraph.get(graphId);
92
+ if (!fInGraph) {
93
+ return false;
94
+ }
95
+ if (fInGraph.external === true) {
96
+ return false;
97
+ }
98
+ if (fInGraph.inaccessible === true) {
99
+ return false;
100
+ }
101
+ if (typeof fInGraph.override === 'string') {
102
+ return false;
103
+ }
104
+ return true;
105
+ });
106
+ if (graphHasAtLeastOneResolvableField) {
107
+ return true;
108
+ }
109
+ }
110
+ return false;
111
+ }
112
+ return true;
113
+ }
114
+ function canGraphResolveField(objectTypeSuperState, fieldSuperState, graphId, supergraphState, movabilityGraph) {
115
+ const objectTypeInGraph = objectTypeSuperState.byGraph.get(graphId);
116
+ if (!objectTypeInGraph) {
117
+ throw new Error(`Object type "${objectTypeSuperState.name}" not found in graph "${graphId}"`);
118
+ }
119
+ const fieldInGraph = fieldSuperState.byGraph.get(graphId);
120
+ if (fieldInGraph &&
121
+ fieldInGraph.external === false &&
122
+ canGraphResolveFieldDirectly(objectTypeSuperState, fieldSuperState, graphId, supergraphState)) {
123
+ return true;
124
+ }
125
+ const graphsWithField = Array.from(fieldSuperState.byGraph).filter(([g, _]) => {
126
+ if (g === graphId) {
127
+ return false;
128
+ }
129
+ const fieldInGraph = fieldSuperState.byGraph.get(g);
130
+ if (!fieldInGraph || fieldInGraph.external === true) {
131
+ return false;
132
+ }
133
+ return true;
134
+ });
135
+ const canMoveToGraphWithField = graphsWithField.some(([g, _]) => {
136
+ return canGraphMoveToGraphBasedOnMovabilityGraph(movabilityGraph, graphId, g);
137
+ });
138
+ return canMoveToGraphWithField;
139
+ }
140
+ function canGraphMoveToGraphBasedOnMovabilityGraph(movabilityGraph, sourceId, destinationId, visited = new Set()) {
141
+ const key = `${sourceId} => ${destinationId}`;
142
+ if (visited.has(key)) {
143
+ return false;
144
+ }
145
+ else {
146
+ visited.add(key);
147
+ }
148
+ const deps = movabilityGraph.directDependenciesOf(sourceId);
149
+ if (deps.includes(destinationId)) {
150
+ return true;
151
+ }
152
+ return deps.some(depId => canGraphMoveToGraphBasedOnMovabilityGraph(movabilityGraph, depId, destinationId, visited));
153
+ }
154
+ function findLeafs(movabilityGraph, sourceId, destinationId, leafs, visited = new Set()) {
155
+ const key = `${sourceId} => ${destinationId}`;
156
+ if (leafs === undefined) {
157
+ leafs = new Set();
158
+ }
159
+ const deps = movabilityGraph.directDependenciesOf(sourceId);
160
+ if (visited.has(key)) {
161
+ return Array.from(leafs);
162
+ }
163
+ else {
164
+ visited.add(key);
165
+ }
166
+ for (const depId of deps) {
167
+ if (!canGraphMoveToGraphBasedOnMovabilityGraph(movabilityGraph, depId, destinationId)) {
168
+ leafs.add(depId);
169
+ findLeafs(movabilityGraph, depId, destinationId, leafs, visited);
170
+ }
171
+ }
172
+ return Array.from(leafs);
173
+ }
174
+ function SatisfiabilityRule(context, supergraphState) {
175
+ const typeDependencies = buildOutputTypesDependencies(supergraphState);
176
+ let currentMovabilityGraphType;
177
+ let movabilityGraph;
178
+ return {
179
+ ObjectType(objectState) {
180
+ currentMovabilityGraphType = objectState.name;
181
+ movabilityGraph = new dependency_graph_js_1.DepGraph({
182
+ circular: true,
183
+ });
184
+ const graphIds = Array.from(objectState.byGraph.keys());
185
+ for (const sourceGraphId of objectState.byGraph.keys()) {
186
+ movabilityGraph.addNode(sourceGraphId);
187
+ }
188
+ for (const sourceGraphId of objectState.byGraph.keys()) {
189
+ const otherGraphIds = graphIds.filter(g => g !== sourceGraphId);
190
+ for (const destGraphId of otherGraphIds) {
191
+ if (canGraphMoveToGraph(supergraphState, objectState, sourceGraphId, destGraphId)) {
192
+ movabilityGraph.addDependency(sourceGraphId, destGraphId);
193
+ }
194
+ }
195
+ }
196
+ },
197
+ ObjectTypeField(objectState, fieldState) {
198
+ if (currentMovabilityGraphType !== objectState.name) {
199
+ throw new Error('ObjectTypeField runs before ObjectType! This should not happen.');
200
+ }
201
+ if (objectState.name === 'Query' ||
202
+ objectState.name === 'Mutation' ||
203
+ objectState.name === 'Subscription') {
204
+ return;
205
+ }
206
+ if (objectState.byGraph.size === 1) {
207
+ return;
208
+ }
209
+ const dependenciesOfObjectType = typeDependencies.dependentsOf(objectState.name);
210
+ const isReachableByRootType = {
211
+ query: dependenciesOfObjectType.includes('Query'),
212
+ mutation: dependenciesOfObjectType.includes('Mutation'),
213
+ subscription: dependenciesOfObjectType.includes('Subscription'),
214
+ };
215
+ const isReachable = isReachableByRootType.query ||
216
+ isReachableByRootType.mutation ||
217
+ isReachableByRootType.subscription;
218
+ if (!isReachable) {
219
+ return;
220
+ }
221
+ const objectStateGraphPairs = Array.from(objectState.byGraph);
222
+ const fieldStateGraphPairs = Array.from(fieldState.byGraph);
223
+ if (objectStateGraphPairs.some(([_, objectTypeStateInGraph]) => objectTypeStateInGraph.inaccessible === true) ||
224
+ fieldStateGraphPairs.some(([_, fieldStateInGraph]) => fieldStateInGraph.inaccessible === true)) {
225
+ return;
226
+ }
227
+ const isFieldShareableInAllSubgraphs = Array.from(fieldState.byGraph).every(([graphId, fieldStateInGraph]) => {
228
+ const fieldShareable = fieldStateInGraph.shareable &&
229
+ context.subgraphStates.get(graphId).version !== 'v1.0';
230
+ const typeShareable = objectState.byGraph.get(graphId).shareable === true;
231
+ return fieldShareable || typeShareable;
232
+ });
233
+ if (isFieldShareableInAllSubgraphs) {
234
+ return;
235
+ }
236
+ if (fieldState.byGraph.size === objectState.byGraph.size &&
237
+ fieldStateGraphPairs.every(([_, f]) => f.usedAsKey === true && f.external === false && !f.override)) {
238
+ return;
239
+ }
240
+ const keysInAllGraphs = objectStateGraphPairs.every(([_, o]) => o.keys.length > 0);
241
+ const uniqueKeyFieldsSet = new Set(objectStateGraphPairs
242
+ .map(([_, o]) => o.keys.map(k => k.fields))
243
+ .flat(1));
244
+ if (keysInAllGraphs && uniqueKeyFieldsSet.size === 1) {
245
+ return;
246
+ }
247
+ const aggregatedErrorByRootType = {
248
+ Query: {
249
+ query: null,
250
+ reasons: [],
251
+ },
252
+ Mutation: {
253
+ query: null,
254
+ reasons: [],
255
+ },
256
+ Subscription: {
257
+ query: null,
258
+ reasons: [],
259
+ },
260
+ };
261
+ if (uniqueKeyFieldsSet.size > 0) {
262
+ for (const graphId of objectState.byGraph.keys()) {
263
+ if (canGraphResolveField(objectState, fieldState, graphId, supergraphState, movabilityGraph)) {
264
+ continue;
265
+ }
266
+ const fieldStateInGraph = fieldState.byGraph.get(graphId);
267
+ if (fieldStateInGraph?.external === true) {
268
+ const objectStateInGraph = objectState.byGraph.get(graphId);
269
+ if (objectStateInGraph.extension === true) {
270
+ continue;
271
+ }
272
+ if (fieldStateInGraph.required) {
273
+ continue;
274
+ }
275
+ if (fieldStateInGraph.provided) {
276
+ continue;
277
+ }
278
+ }
279
+ const subgraphState = context.subgraphStates.get(graphId);
280
+ const schemaDefinitionOfGraph = subgraphState.schema;
281
+ const rootTypes = [
282
+ schemaDefinitionOfGraph.queryType
283
+ ? [
284
+ 'Query',
285
+ subgraphState.types.get(schemaDefinitionOfGraph.queryType),
286
+ ]
287
+ : undefined,
288
+ schemaDefinitionOfGraph.mutationType
289
+ ? [
290
+ 'Mutation',
291
+ subgraphState.types.get(schemaDefinitionOfGraph.mutationType),
292
+ ]
293
+ : undefined,
294
+ schemaDefinitionOfGraph.subscriptionType
295
+ ? [
296
+ 'Subscription',
297
+ subgraphState.types.get(schemaDefinitionOfGraph.subscriptionType),
298
+ ]
299
+ : undefined,
300
+ ].filter(helpers_js_2.isDefined);
301
+ if (rootTypes.length === 0) {
302
+ continue;
303
+ }
304
+ const otherGraphIds = objectStateGraphPairs
305
+ .filter(([g, _]) => g !== graphId)
306
+ .map(([g, _]) => g);
307
+ const graphsWithField = fieldStateGraphPairs
308
+ .filter(([g, _]) => canGraphResolveFieldDirectly(objectState, fieldState, g, supergraphState))
309
+ .map(([g, _]) => g);
310
+ const leafs = graphsWithField.map(g => findLeafs(movabilityGraph, graphId, g)).flat(1);
311
+ if (leafs.length === 0 && movabilityGraph.directDependenciesOf(graphId).length > 0) {
312
+ continue;
313
+ }
314
+ for (const [normalizedName, rootType] of rootTypes) {
315
+ const query = printExampleQuery(supergraphState, normalizedName, Array.from(rootType.fields.keys()), objectState.name, fieldState.name, dependenciesOfObjectType);
316
+ const reasons = [];
317
+ const canBeIndirectlyResolved = leafs.length > 0;
318
+ const cannotMoveToList = (sourceGraphId) => canBeIndirectlyResolved
319
+ ? graphsWithField
320
+ .map(gid => {
321
+ const keys = objectState.byGraph.get(gid).keys.map(k => k.fields);
322
+ if (keys.length > 0) {
323
+ return objectState.byGraph
324
+ .get(gid)
325
+ .keys.map(k => k.fields)
326
+ .map(fields => `cannot move to subgraph "${context.graphIdToName(gid)}" using @key(fields: "${fields}") of "${objectState.name}", the key field(s) cannot be resolved from subgraph "${context.graphIdToName(sourceGraphId)}".`);
327
+ }
328
+ return `cannot move to subgraph "${context.graphIdToName(gid)}", which has field "${objectState.name}.${fieldState.name}", because type "${objectState.name}" has no @key defined in subgraph "${context.graphIdToName(gid)}".`;
329
+ })
330
+ .flat(1)
331
+ : otherGraphIds
332
+ .filter(g => !movabilityGraph.directDependenciesOf(graphId).includes(g))
333
+ .map(gid => {
334
+ const keys = objectState.byGraph.get(gid).keys.map(k => k.fields);
335
+ if (keys.length > 0) {
336
+ return objectState.byGraph
337
+ .get(gid)
338
+ .keys.map(k => k.fields)
339
+ .map(fields => `cannot move to subgraph "${context.graphIdToName(gid)}" using @key(fields: "${fields}") of "${objectState.name}", the key field(s) cannot be resolved from subgraph "${context.graphIdToName(sourceGraphId)}".`);
340
+ }
341
+ return `cannot move to subgraph "${context.graphIdToName(gid)}", which has field "${objectState.name}.${fieldState.name}", because type "${objectState.name}" has no @key defined in subgraph "${context.graphIdToName(gid)}".`;
342
+ })
343
+ .flat(1);
344
+ const fromSubgraphs = [graphId].concat(leafs);
345
+ if (!fieldStateInGraph) {
346
+ fromSubgraphs.forEach(gid => {
347
+ reasons.push([
348
+ gid,
349
+ [`cannot find field "${objectState.name}.${fieldState.name}".`].concat(cannotMoveToList(gid)),
350
+ ]);
351
+ });
352
+ }
353
+ else if (fieldStateInGraph.external) {
354
+ fromSubgraphs.forEach(gid => {
355
+ reasons.push([
356
+ gid,
357
+ [
358
+ `field "${objectState.name}.${fieldState.name}" is not resolvable because marked @external.`,
359
+ ].concat(cannotMoveToList(gid)),
360
+ ]);
361
+ });
362
+ }
363
+ else {
364
+ console.log('can NOT resolve field', fieldState.name, 'in graph', graphId, 'reason: unknown');
365
+ }
366
+ if (!query || reasons.length === 0) {
367
+ continue;
368
+ }
369
+ context.reportError(new graphql_1.GraphQLError([
370
+ 'The following supergraph API query:',
371
+ query,
372
+ 'cannot be satisfied by the subgraphs because:',
373
+ ...reasons.map(([gid, reasons]) => {
374
+ return (`- from subgraph "${context.graphIdToName(gid)}":\n` +
375
+ reasons.map(r => ` - ${r}`).join('\n'));
376
+ }),
377
+ ].join('\n'), {
378
+ extensions: {
379
+ code: 'SATISFIABILITY_ERROR',
380
+ },
381
+ }));
382
+ }
383
+ }
384
+ }
385
+ else {
386
+ const graphsWithoutField = objectStateGraphPairs.filter(([graphId]) => !fieldState.byGraph.has(graphId));
387
+ const graphsWithField = fieldStateGraphPairs.map(([graphId]) => graphId);
388
+ for (const [graphId] of graphsWithoutField) {
389
+ const subgraphState = context.subgraphStates.get(graphId);
390
+ const isShareableWithOtherGraphs = Array.from(subgraphState.types.values())
391
+ .filter(t => dependenciesOfObjectType.includes(t.name))
392
+ .every(t => {
393
+ if (t.kind === state_js_1.TypeKind.OBJECT) {
394
+ if (t.shareable &&
395
+ subgraphState.version !== 'v1.0') {
396
+ return true;
397
+ }
398
+ const fields = Array.from(t.fields.values());
399
+ if (fields
400
+ .filter(f => (0, state_js_2.stripTypeModifiers)(f.type) === objectState.name)
401
+ .every(f => f.shareable === true &&
402
+ subgraphState.version !== 'v1.0')) {
403
+ return true;
404
+ }
405
+ }
406
+ return false;
407
+ });
408
+ if (isShareableWithOtherGraphs) {
409
+ continue;
410
+ }
411
+ const graphHasAtLeastOneResolvableField = Array.from(objectState.fields.values()).some(f => {
412
+ const fieldInGraph = f.byGraph.get(graphId);
413
+ if (!fieldInGraph) {
414
+ return false;
415
+ }
416
+ if (fieldInGraph.inaccessible === true) {
417
+ return false;
418
+ }
419
+ return true;
420
+ });
421
+ if (!graphHasAtLeastOneResolvableField) {
422
+ continue;
423
+ }
424
+ const schemaDefinitionOfGraph = subgraphState.schema;
425
+ const rootTypes = [
426
+ schemaDefinitionOfGraph.queryType
427
+ ? [
428
+ 'Query',
429
+ subgraphState.types.get(schemaDefinitionOfGraph.queryType),
430
+ ]
431
+ : undefined,
432
+ schemaDefinitionOfGraph.mutationType
433
+ ? [
434
+ 'Mutation',
435
+ subgraphState.types.get(schemaDefinitionOfGraph.mutationType),
436
+ ]
437
+ : undefined,
438
+ schemaDefinitionOfGraph.subscriptionType
439
+ ? [
440
+ 'Subscription',
441
+ subgraphState.types.get(schemaDefinitionOfGraph.subscriptionType),
442
+ ]
443
+ : undefined,
444
+ ].filter(helpers_js_2.isDefined);
445
+ if (rootTypes.length === 0) {
446
+ continue;
447
+ }
448
+ for (const [normalizedName, rootType] of rootTypes) {
449
+ const rootTypeFields = Array.from(rootType.fields.keys()).filter(f => f !== '_entities' && f !== '_service');
450
+ if (rootTypeFields.length === 0) {
451
+ continue;
452
+ }
453
+ const supergraphRootType = supergraphState.objectTypes.get(normalizedName);
454
+ const rootFieldsReferencingObjectType = Array.from(supergraphRootType.fields.values()).filter(f => {
455
+ const fieldOutputTypeName = (0, state_js_2.stripTypeModifiers)(f.type);
456
+ return (fieldOutputTypeName === objectState.name ||
457
+ dependenciesOfObjectType.includes(fieldOutputTypeName));
458
+ });
459
+ if (rootFieldsReferencingObjectType.length === 0) {
460
+ continue;
461
+ }
462
+ const graphIdsImplementingObjectType = Array.from(objectState.byGraph.keys());
463
+ if (rootFieldsReferencingObjectType.every(field => graphIdsImplementingObjectType.every(g => field.byGraph.has(g)))) {
464
+ continue;
465
+ }
466
+ const areRootFieldsShared = graphsWithField.every(g => {
467
+ const localVersion = context.subgraphStates.get(g).version;
468
+ if (localVersion !== 'v1.0') {
469
+ return false;
470
+ }
471
+ const localSubgraph = context.subgraphStates.get(g);
472
+ const localSchemaDefinition = localSubgraph.schema;
473
+ const localRootTypeName = normalizedName === 'Query'
474
+ ? localSchemaDefinition.queryType
475
+ : normalizedName === 'Mutation'
476
+ ? localSchemaDefinition.mutationType
477
+ : normalizedName === 'Subscription'
478
+ ? localSchemaDefinition.subscriptionType
479
+ : undefined;
480
+ if (!localRootTypeName) {
481
+ return true;
482
+ }
483
+ const localRootType = localSubgraph.types.get(localRootTypeName);
484
+ const localRootFields = Array.from(localRootType.fields.keys());
485
+ return rootFieldsReferencingObjectType.every(f => localRootFields.includes(f.name));
486
+ });
487
+ if (areRootFieldsShared) {
488
+ continue;
489
+ }
490
+ if (!aggregatedErrorByRootType[normalizedName].query) {
491
+ aggregatedErrorByRootType[normalizedName].query = printExampleQuery(supergraphState, normalizedName, rootTypeFields, objectState.name, fieldState.name, dependenciesOfObjectType);
492
+ }
493
+ const firstFieldImplementingGraph = graphsWithField[0];
494
+ const graphNameOwningField = context.graphIdToName(firstFieldImplementingGraph);
495
+ aggregatedErrorByRootType[normalizedName].reasons.push([
496
+ graphId,
497
+ [
498
+ `cannot find field "${objectState.name}.${fieldState.name}".`,
499
+ `cannot move to subgraph "${graphNameOwningField}", which has field "${objectState.name}.${fieldState.name}", because type "${objectState.name}" has no @key defined in subgraph "${graphNameOwningField}".`,
500
+ ],
501
+ ]);
502
+ }
503
+ }
504
+ }
505
+ for (const rootTypeName in aggregatedErrorByRootType) {
506
+ const details = aggregatedErrorByRootType[rootTypeName];
507
+ if (!details.query || details.reasons.length === 0) {
508
+ continue;
509
+ }
510
+ context.reportError(new graphql_1.GraphQLError([
511
+ 'The following supergraph API query:',
512
+ details.query,
513
+ 'cannot be satisfied by the subgraphs because:',
514
+ ...details.reasons.map(([graphId, reasons]) => {
515
+ return (`- from subgraph "${context.graphIdToName(graphId)}":\n` +
516
+ reasons.map(r => ` - ${r}`).join('\n'));
517
+ }),
518
+ ].join('\n'), {
519
+ extensions: {
520
+ code: 'SATISFIABILITY_ERROR',
521
+ },
522
+ }));
523
+ }
524
+ },
525
+ };
526
+ }
527
+ exports.SatisfiabilityRule = SatisfiabilityRule;
528
+ function buildOutputTypesDependencies(supergraphState) {
529
+ const graph = new dependency_graph_js_1.DepGraph({
530
+ circular: true,
531
+ });
532
+ for (const [typeName, typeState] of supergraphState.objectTypes) {
533
+ if (typeName === '_Service') {
534
+ continue;
535
+ }
536
+ graph.addNode(typeName);
537
+ for (const [_, fieldState] of typeState.fields) {
538
+ const referencedTypeName = (0, state_js_2.stripTypeModifiers)(fieldState.type);
539
+ if (!graph.hasNode(referencedTypeName)) {
540
+ graph.addNode(referencedTypeName);
541
+ }
542
+ graph.addDependency(typeName, referencedTypeName);
543
+ }
544
+ }
545
+ for (const [typeName, typeState] of supergraphState.unionTypes) {
546
+ if (typeName === '_Entity') {
547
+ continue;
548
+ }
549
+ graph.addNode(typeName);
550
+ for (const memberType of typeState.members) {
551
+ const referencedTypeName = memberType;
552
+ if (!graph.hasNode(referencedTypeName)) {
553
+ graph.addNode(referencedTypeName);
554
+ }
555
+ graph.addDependency(typeName, referencedTypeName);
556
+ }
557
+ }
558
+ return graph;
559
+ }
560
+ function printExampleQuery(supergraphState, rootTypeName, rootTypeFieldsToStartWith, leafTypeName, leafFieldName, typesInBetweenRootAndLeaf = []) {
561
+ const rootType = supergraphState.objectTypes.get(rootTypeName);
562
+ function visitType(typeState, descendants, visitedTypes) {
563
+ if (visitedTypes.includes(typeState.name)) {
564
+ return null;
565
+ }
566
+ if ('members' in typeState) {
567
+ for (const member of typeState.members) {
568
+ const result = member === leafTypeName
569
+ ? visitLeafType(supergraphState.objectTypes.get(member), descendants.concat([
570
+ {
571
+ kind: graphql_1.Kind.INLINE_FRAGMENT,
572
+ typeCondition: {
573
+ kind: graphql_1.Kind.NAMED_TYPE,
574
+ name: {
575
+ kind: graphql_1.Kind.NAME,
576
+ value: member,
577
+ },
578
+ },
579
+ selectionSet: {
580
+ kind: graphql_1.Kind.SELECTION_SET,
581
+ selections: [],
582
+ },
583
+ },
584
+ ]))
585
+ : visitType(supergraphState.objectTypes.get(member), descendants.concat([
586
+ {
587
+ kind: graphql_1.Kind.INLINE_FRAGMENT,
588
+ typeCondition: {
589
+ kind: graphql_1.Kind.NAMED_TYPE,
590
+ name: {
591
+ kind: graphql_1.Kind.NAME,
592
+ value: member,
593
+ },
594
+ },
595
+ selectionSet: {
596
+ kind: graphql_1.Kind.SELECTION_SET,
597
+ selections: [],
598
+ },
599
+ },
600
+ ]), visitedTypes.concat(typeState.name));
601
+ if (result) {
602
+ return result;
603
+ }
604
+ }
605
+ return null;
606
+ }
607
+ for (const [fieldName, fieldState] of Array.from(typeState.fields.entries()).reverse()) {
608
+ if (typeState.name === rootTypeName && !rootTypeFieldsToStartWith.includes(fieldName)) {
609
+ continue;
610
+ }
611
+ const fieldOutputTypeName = (0, state_js_2.stripTypeModifiers)(fieldState.type);
612
+ if (fieldOutputTypeName === leafTypeName) {
613
+ return visitLeafType(supergraphState.objectTypes.get(fieldOutputTypeName), descendants.concat([
614
+ {
615
+ kind: graphql_1.Kind.FIELD,
616
+ name: {
617
+ kind: graphql_1.Kind.NAME,
618
+ value: fieldName,
619
+ },
620
+ arguments: Array.from(fieldState.args).map(([argName, argState]) => ({
621
+ kind: graphql_1.Kind.ARGUMENT,
622
+ name: {
623
+ kind: graphql_1.Kind.NAME,
624
+ value: argName,
625
+ },
626
+ value: createEmptyValueNode(argState.type, supergraphState),
627
+ })),
628
+ },
629
+ ]));
630
+ }
631
+ else if (typesInBetweenRootAndLeaf.includes(fieldOutputTypeName) &&
632
+ !visitedTypes.includes(fieldOutputTypeName)) {
633
+ const referencedType = supergraphState.objectTypes.get(fieldOutputTypeName) ??
634
+ supergraphState.unionTypes.get(fieldOutputTypeName);
635
+ return visitType(referencedType, descendants.concat([
636
+ {
637
+ kind: graphql_1.Kind.FIELD,
638
+ name: {
639
+ kind: graphql_1.Kind.NAME,
640
+ value: fieldName,
641
+ },
642
+ arguments: Array.from(fieldState.args).map(([argName, argState]) => ({
643
+ kind: graphql_1.Kind.ARGUMENT,
644
+ name: {
645
+ kind: graphql_1.Kind.NAME,
646
+ value: argName,
647
+ },
648
+ value: createEmptyValueNode(argState.type, supergraphState),
649
+ })),
650
+ },
651
+ ]), visitedTypes.concat(typeState.name));
652
+ }
653
+ }
654
+ return null;
655
+ }
656
+ function visitLeafType(objectTypeState, descendants) {
657
+ for (const [fieldName, fieldState] of objectTypeState.fields) {
658
+ if (fieldName !== leafFieldName) {
659
+ continue;
660
+ }
661
+ const fieldOutputTypeName = (0, state_js_2.stripTypeModifiers)(fieldState.type);
662
+ const isObjectSpreadCapable = supergraphState.objectTypes.has(fieldOutputTypeName) ||
663
+ supergraphState.interfaceTypes.has(fieldOutputTypeName) ||
664
+ supergraphState.unionTypes.has(fieldOutputTypeName);
665
+ return descendants.concat([
666
+ {
667
+ kind: graphql_1.Kind.FIELD,
668
+ name: {
669
+ kind: graphql_1.Kind.NAME,
670
+ value: fieldName,
671
+ },
672
+ arguments: Array.from(fieldState.args).map(([argName, argState]) => ({
673
+ kind: graphql_1.Kind.ARGUMENT,
674
+ name: {
675
+ kind: graphql_1.Kind.NAME,
676
+ value: argName,
677
+ },
678
+ value: createEmptyValueNode(argState.type, supergraphState),
679
+ })),
680
+ selectionSet: isObjectSpreadCapable
681
+ ?
682
+ {
683
+ kind: graphql_1.Kind.SELECTION_SET,
684
+ selections: [
685
+ {
686
+ kind: graphql_1.Kind.FRAGMENT_SPREAD,
687
+ name: {
688
+ kind: graphql_1.Kind.NAME,
689
+ value: '',
690
+ },
691
+ },
692
+ ],
693
+ }
694
+ : undefined,
695
+ },
696
+ ]);
697
+ }
698
+ return null;
699
+ }
700
+ const tree = visitType(rootType, [], []);
701
+ let currentField = null;
702
+ if (!tree) {
703
+ return null;
704
+ }
705
+ tree.reverse();
706
+ for (const field of tree) {
707
+ if (!currentField) {
708
+ currentField = {
709
+ ...field,
710
+ };
711
+ }
712
+ else {
713
+ currentField = {
714
+ ...field,
715
+ selectionSet: {
716
+ kind: graphql_1.Kind.SELECTION_SET,
717
+ selections: [currentField],
718
+ },
719
+ };
720
+ }
721
+ }
722
+ const query = {
723
+ kind: graphql_1.Kind.DOCUMENT,
724
+ definitions: [
725
+ {
726
+ kind: graphql_1.Kind.OPERATION_DEFINITION,
727
+ operation: rootTypeName === 'Query'
728
+ ? graphql_1.OperationTypeNode.QUERY
729
+ : rootTypeName === 'Mutation'
730
+ ? graphql_1.OperationTypeNode.MUTATION
731
+ : graphql_1.OperationTypeNode.SUBSCRIPTION,
732
+ selectionSet: {
733
+ kind: graphql_1.Kind.SELECTION_SET,
734
+ selections: [currentField],
735
+ },
736
+ },
737
+ ],
738
+ };
739
+ return (0, graphql_1.print)(query);
740
+ }
741
+ function createEmptyValueNode(fullType, supergraphState) {
742
+ if ((0, state_js_2.isList)(fullType)) {
743
+ return {
744
+ kind: graphql_1.Kind.LIST,
745
+ values: [],
746
+ };
747
+ }
748
+ if ((0, state_js_2.isNonNull)(fullType)) {
749
+ const innerType = (0, state_js_2.stripNonNull)(fullType);
750
+ return createEmptyValueNode(innerType, supergraphState);
751
+ }
752
+ if (supergraphState.enumTypes.has(fullType)) {
753
+ const enumState = supergraphState.enumTypes.get(fullType);
754
+ return {
755
+ kind: graphql_1.Kind.ENUM,
756
+ value: Array.from(enumState.values.keys())[0],
757
+ };
758
+ }
759
+ if (supergraphState.scalarTypes.has(fullType)) {
760
+ return {
761
+ kind: graphql_1.Kind.STRING,
762
+ value: 'A string value',
763
+ };
764
+ }
765
+ if (supergraphState.inputObjectTypes.has(fullType)) {
766
+ const inputObjectTypeState = supergraphState.inputObjectTypes.get(fullType);
767
+ return {
768
+ kind: graphql_1.Kind.OBJECT,
769
+ fields: Array.from(inputObjectTypeState.fields)
770
+ .filter(([_, fieldState]) => (0, state_js_2.isNonNull)(fieldState.type))
771
+ .map(([fieldName, fieldState]) => ({
772
+ kind: graphql_1.Kind.OBJECT_FIELD,
773
+ name: {
774
+ kind: graphql_1.Kind.NAME,
775
+ value: fieldName,
776
+ },
777
+ value: createEmptyValueNode(fieldState.type, supergraphState),
778
+ })),
779
+ };
780
+ }
781
+ const specifiedScalar = graphql_1.specifiedScalarTypes.find(s => s.name === fullType);
782
+ if (!specifiedScalar) {
783
+ throw new Error(`Type "${fullType}" is not defined.`);
784
+ }
785
+ if (specifiedScalar.name === 'String') {
786
+ return {
787
+ kind: graphql_1.Kind.STRING,
788
+ value: 'A string value',
789
+ };
790
+ }
791
+ if (specifiedScalar.name === 'Int' || specifiedScalar.name === 'Float') {
792
+ return {
793
+ kind: graphql_1.Kind.INT,
794
+ value: '0',
795
+ };
796
+ }
797
+ if (specifiedScalar.name === 'Boolean') {
798
+ return {
799
+ kind: graphql_1.Kind.BOOLEAN,
800
+ value: true,
801
+ };
802
+ }
803
+ if (specifiedScalar.name === 'ID') {
804
+ return {
805
+ kind: graphql_1.Kind.STRING,
806
+ value: '<any id>',
807
+ };
808
+ }
809
+ throw new Error(`Type "${fullType}" is not supported.`);
810
+ }
811
+ function resolveFieldsFromFieldSet(fields, typeName, graphId, supergraphState) {
812
+ const paths = new Set();
813
+ const coordinates = new Set();
814
+ const selectionSet = (0, helpers_js_1.parseFields)(fields);
815
+ if (!selectionSet) {
816
+ return {
817
+ coordinates,
818
+ paths,
819
+ };
820
+ }
821
+ findFieldPathsFromSelectionSet(paths, coordinates, typeName, selectionSet, typeName, graphId, supergraphState);
822
+ return {
823
+ coordinates,
824
+ paths,
825
+ };
826
+ }
827
+ function findFieldPathsFromSelectionSet(fieldPaths, coordinates, typeName, selectionSet, currentPath, graphId, supergraphState) {
828
+ for (const selection of selectionSet.selections) {
829
+ if (selection.kind === graphql_1.Kind.FIELD) {
830
+ const innerPath = `${currentPath}.${selection.name.value}`;
831
+ fieldPaths.add(innerPath);
832
+ if (Array.isArray(typeName)) {
833
+ for (const t of typeName) {
834
+ coordinates.add(`${t}.${selection.name.value}`);
835
+ }
836
+ }
837
+ else {
838
+ coordinates.add(`${typeName}.${selection.name.value}`);
839
+ }
840
+ if (selection.selectionSet) {
841
+ const types = (Array.isArray(typeName) ? typeName : [typeName]).map(tName => {
842
+ const outputType = supergraphState.objectTypes.get(tName) ?? supergraphState.interfaceTypes.get(tName);
843
+ if (!outputType) {
844
+ throw new Error(`Type "${tName}" is not defined.`);
845
+ }
846
+ return outputType;
847
+ });
848
+ const typesWithField = types.filter(t => t.fields.has(selection.name.value));
849
+ if (typesWithField.length === 0) {
850
+ throw new Error(`Type "${typeName.toString()}" does not have field "${selection.name.value}".`);
851
+ }
852
+ const outputTypes = typesWithField.map(t => (0, state_js_2.stripTypeModifiers)(t.fields.get(selection.name.value).type));
853
+ findFieldPathsFromSelectionSet(fieldPaths, coordinates, outputTypes, selection.selectionSet, innerPath, graphId, supergraphState);
854
+ }
855
+ }
856
+ else if (selection.kind === graphql_1.Kind.INLINE_FRAGMENT) {
857
+ if (!selection.typeCondition) {
858
+ throw new Error(`Inline fragment without type condition is not supported.`);
859
+ }
860
+ findFieldPathsFromSelectionSet(fieldPaths, coordinates, selection.typeCondition.name.value, selection.selectionSet, `${currentPath}.(${selection.typeCondition.name.value})`, graphId, supergraphState);
861
+ }
862
+ else {
863
+ throw new Error(`Fragment spread is not supported.`);
864
+ }
865
+ }
866
+ }