1 | import { GraphQLError } from "../../error/GraphQLError.mjs";
|
2 | import { print } from "../../language/printer.mjs";
|
3 | import { isCompositeType } from "../../type/definition.mjs";
|
4 | import { typeFromAST } from "../../utilities/typeFromAST.mjs";
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | export function FragmentsOnCompositeTypesRule(context) {
|
14 | return {
|
15 | InlineFragment: function InlineFragment(node) {
|
16 | var typeCondition = node.typeCondition;
|
17 |
|
18 | if (typeCondition) {
|
19 | var type = typeFromAST(context.getSchema(), typeCondition);
|
20 |
|
21 | if (type && !isCompositeType(type)) {
|
22 | var typeStr = print(typeCondition);
|
23 | context.reportError(new GraphQLError("Fragment cannot condition on non composite type \"".concat(typeStr, "\"."), typeCondition));
|
24 | }
|
25 | }
|
26 | },
|
27 | FragmentDefinition: function FragmentDefinition(node) {
|
28 | var type = typeFromAST(context.getSchema(), node.typeCondition);
|
29 |
|
30 | if (type && !isCompositeType(type)) {
|
31 | var typeStr = print(node.typeCondition);
|
32 | context.reportError(new GraphQLError("Fragment \"".concat(node.name.value, "\" cannot condition on non composite type \"").concat(typeStr, "\"."), node.typeCondition));
|
33 | }
|
34 | }
|
35 | };
|
36 | }
|