1 | import inspect from "../../jsutils/inspect.mjs";
|
2 | import { GraphQLError } from "../../error/GraphQLError.mjs";
|
3 | import { getNamedType, isLeafType } from "../../type/definition.mjs";
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export function ScalarLeafsRule(context) {
|
12 | return {
|
13 | Field: function Field(node) {
|
14 | var type = context.getType();
|
15 | var selectionSet = node.selectionSet;
|
16 |
|
17 | if (type) {
|
18 | if (isLeafType(getNamedType(type))) {
|
19 | if (selectionSet) {
|
20 | var fieldName = node.name.value;
|
21 | var typeStr = inspect(type);
|
22 | context.reportError(new GraphQLError("Field \"".concat(fieldName, "\" must not have a selection since type \"").concat(typeStr, "\" has no subfields."), selectionSet));
|
23 | }
|
24 | } else if (!selectionSet) {
|
25 | var _fieldName = node.name.value;
|
26 |
|
27 | var _typeStr = inspect(type);
|
28 |
|
29 | context.reportError(new GraphQLError("Field \"".concat(_fieldName, "\" of type \"").concat(_typeStr, "\" must have a selection of subfields. Did you mean \"").concat(_fieldName, " { ... }\"?"), node));
|
30 | }
|
31 | }
|
32 | }
|
33 | };
|
34 | }
|