Skip to content

Commit 3df173b

Browse files
leebyronyaacovCR
authored andcommitted
Add coordinate field to schema element definitions
* Defines a `GraphQLSchemaElement` base class which defines a `.coordinate` property and `toString`/`toJSON` methods. * Adds base class to types, fields, arguments, input fields, enum values, and directives. * Uses this in validation error printing string templates.
1 parent 75b9bd1 commit 3df173b

26 files changed

+648
-637
lines changed

src/execution/__tests__/nonnull-test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ describe('Execute: handles non-nullable types', () => {
620620
errors: [
621621
{
622622
message:
623-
'Argument "cannotBeNull" of required type "String!" was not provided.',
623+
'Argument Query.withNonNullArg(cannotBeNull:) of required type String! was not provided.',
624624
locations: [{ line: 3, column: 13 }],
625625
path: ['withNonNullArg'],
626626
},
@@ -647,7 +647,7 @@ describe('Execute: handles non-nullable types', () => {
647647
errors: [
648648
{
649649
message:
650-
'Argument "cannotBeNull" of non-null type "String!" must not be null.',
650+
'Argument Query.withNonNullArg(cannotBeNull:) of non-null type String! must not be null.',
651651
locations: [{ line: 3, column: 42 }],
652652
path: ['withNonNullArg'],
653653
},
@@ -677,7 +677,7 @@ describe('Execute: handles non-nullable types', () => {
677677
errors: [
678678
{
679679
message:
680-
'Argument "cannotBeNull" of required type "String!" was provided the variable "$testVar" which was not provided a runtime value.',
680+
'Argument Query.withNonNullArg(cannotBeNull:) of required type String! was provided the variable "$testVar" which was not provided a runtime value.',
681681
locations: [{ line: 3, column: 42 }],
682682
path: ['withNonNullArg'],
683683
},
@@ -705,7 +705,7 @@ describe('Execute: handles non-nullable types', () => {
705705
errors: [
706706
{
707707
message:
708-
'Argument "cannotBeNull" of non-null type "String!" must not be null.',
708+
'Argument Query.withNonNullArg(cannotBeNull:) of non-null type String! must not be null.',
709709
locations: [{ line: 3, column: 43 }],
710710
path: ['withNonNullArg'],
711711
},

src/execution/__tests__/variables-test.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ describe('Execute: Handles inputs', () => {
226226
errors: [
227227
{
228228
message:
229-
'Argument "input" has invalid value ["foo", "bar", "baz"].',
229+
'Argument TestType.fieldWithObjectInput(input:) of type TestInputObject has invalid value ["foo", "bar", "baz"].',
230230
path: ['fieldWithObjectInput'],
231231
locations: [{ line: 3, column: 41 }],
232232
},
@@ -262,7 +262,7 @@ describe('Execute: Handles inputs', () => {
262262
errors: [
263263
{
264264
message:
265-
'Argument "input" has invalid value { c: "foo", e: "bar" }.',
265+
'Argument TestType.fieldWithObjectInput(input:) of type TestInputObject has invalid value { c: "foo", e: "bar" }.',
266266
path: ['fieldWithObjectInput'],
267267
locations: [{ line: 3, column: 41 }],
268268
},
@@ -678,7 +678,7 @@ describe('Execute: Handles inputs', () => {
678678
errors: [
679679
{
680680
message:
681-
'Variable "$value" of required type "String!" was not provided.',
681+
'Variable "$value" of required type String! was not provided.',
682682
locations: [{ line: 2, column: 16 }],
683683
},
684684
],
@@ -697,7 +697,7 @@ describe('Execute: Handles inputs', () => {
697697
errors: [
698698
{
699699
message:
700-
'Variable "$value" of non-null type "String!" must not be null.',
700+
'Variable "$value" of non-null type String! must not be null.',
701701
locations: [{ line: 2, column: 16 }],
702702
},
703703
],
@@ -743,7 +743,7 @@ describe('Execute: Handles inputs', () => {
743743
errors: [
744744
{
745745
message:
746-
'Argument "input" of required type "String!" was not provided.',
746+
'Argument TestType.fieldWithNonNullableStringInput(input:) of required type String! was not provided.',
747747
locations: [{ line: 1, column: 3 }],
748748
path: ['fieldWithNonNullableStringInput'],
749749
},
@@ -791,7 +791,7 @@ describe('Execute: Handles inputs', () => {
791791
errors: [
792792
{
793793
message:
794-
'Argument "input" of required type "String!" was provided the variable "$foo" which was not provided a runtime value.',
794+
'Argument TestType.fieldWithNonNullableStringInput(input:) of required type String! was provided the variable "$foo" which was not provided a runtime value.',
795795
locations: [{ line: 3, column: 50 }],
796796
path: ['fieldWithNonNullableStringInput'],
797797
},
@@ -846,7 +846,7 @@ describe('Execute: Handles inputs', () => {
846846
errors: [
847847
{
848848
message:
849-
'Variable "$input" of non-null type "[String]!" must not be null.',
849+
'Variable "$input" of non-null type [String]! must not be null.',
850850
locations: [{ line: 2, column: 16 }],
851851
},
852852
],
@@ -928,7 +928,7 @@ describe('Execute: Handles inputs', () => {
928928
errors: [
929929
{
930930
message:
931-
'Variable "$input" of non-null type "[String!]!" must not be null.',
931+
'Variable "$input" of non-null type [String!]! must not be null.',
932932
locations: [{ line: 2, column: 16 }],
933933
},
934934
],
@@ -977,7 +977,7 @@ describe('Execute: Handles inputs', () => {
977977
errors: [
978978
{
979979
message:
980-
'Variable "$input" expected value of type "TestType!" which cannot be used as an input type.',
980+
'Variable "$input" expected value of type TestType! which cannot be used as an input type.',
981981
locations: [{ line: 2, column: 24 }],
982982
},
983983
],
@@ -996,7 +996,7 @@ describe('Execute: Handles inputs', () => {
996996
errors: [
997997
{
998998
message:
999-
'Variable "$input" expected value of type "UnknownType!" which cannot be used as an input type.',
999+
'Variable "$input" expected value of type UnknownType! which cannot be used as an input type.',
10001000
locations: [{ line: 2, column: 24 }],
10011001
},
10021002
],
@@ -1042,7 +1042,8 @@ describe('Execute: Handles inputs', () => {
10421042
},
10431043
errors: [
10441044
{
1045-
message: 'Argument "input" has invalid value WRONG_TYPE.',
1045+
message:
1046+
'Argument TestType.fieldWithDefaultArgumentValue(input:) of type String has invalid value WRONG_TYPE.',
10461047
locations: [{ line: 3, column: 48 }],
10471048
path: ['fieldWithDefaultArgumentValue'],
10481049
},

src/execution/values.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function coerceVariableValues(
8484
const varTypeStr = print(varDefNode.type);
8585
onError(
8686
new GraphQLError(
87-
`Variable "$${varName}" expected value of type "${varTypeStr}" which cannot be used as an input type.`,
87+
`Variable "$${varName}" expected value of type ${varTypeStr} which cannot be used as an input type.`,
8888
{ nodes: varDefNode.type },
8989
),
9090
);
@@ -95,10 +95,9 @@ function coerceVariableValues(
9595
if (varDefNode.defaultValue) {
9696
coercedValues[varName] = valueFromAST(varDefNode.defaultValue, varType);
9797
} else if (isNonNullType(varType)) {
98-
const varTypeStr = inspect(varType);
9998
onError(
10099
new GraphQLError(
101-
`Variable "$${varName}" of required type "${varTypeStr}" was not provided.`,
100+
`Variable "$${varName}" of required type ${varType} was not provided.`,
102101
{ nodes: varDefNode },
103102
),
104103
);
@@ -108,10 +107,9 @@ function coerceVariableValues(
108107

109108
const value = inputs[varName];
110109
if (value === null && isNonNullType(varType)) {
111-
const varTypeStr = inspect(varType);
112110
onError(
113111
new GraphQLError(
114-
`Variable "$${varName}" of non-null type "${varTypeStr}" must not be null.`,
112+
`Variable "$${varName}" of non-null type ${varType} must not be null.`,
115113
{ nodes: varDefNode },
116114
),
117115
);
@@ -170,8 +168,7 @@ export function getArgumentValues(
170168
coercedValues[name] = argDef.defaultValue;
171169
} else if (isNonNullType(argType)) {
172170
throw new GraphQLError(
173-
`Argument "${name}" of required type "${inspect(argType)}" ` +
174-
'was not provided.',
171+
`Argument ${argDef} of required type ${argType} was not provided.`,
175172
{ nodes: node },
176173
);
177174
}
@@ -191,7 +188,7 @@ export function getArgumentValues(
191188
coercedValues[name] = argDef.defaultValue;
192189
} else if (isNonNullType(argType)) {
193190
throw new GraphQLError(
194-
`Argument "${name}" of required type "${inspect(argType)}" ` +
191+
`Argument ${argDef} of required type ${argType} ` +
195192
`was provided the variable "$${variableName}" which was not provided a runtime value.`,
196193
{ nodes: valueNode },
197194
);
@@ -203,8 +200,7 @@ export function getArgumentValues(
203200

204201
if (isNull && isNonNullType(argType)) {
205202
throw new GraphQLError(
206-
`Argument "${name}" of non-null type "${inspect(argType)}" ` +
207-
'must not be null.',
203+
`Argument ${argDef} of non-null type ${argType} must not be null.`,
208204
{ nodes: valueNode },
209205
);
210206
}
@@ -215,7 +211,9 @@ export function getArgumentValues(
215211
// execution. This is a runtime check to ensure execution does not
216212
// continue with an invalid argument value.
217213
throw new GraphQLError(
218-
`Argument "${name}" has invalid value ${print(valueNode)}.`,
214+
`Argument ${argDef} of type ${argType} has invalid value ${print(
215+
valueNode,
216+
)}.`,
219217
{ nodes: valueNode },
220218
);
221219
}

src/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@ export {
4040
// Definitions
4141
GraphQLSchema,
4242
GraphQLDirective,
43+
GraphQLSchemaElement,
4344
GraphQLScalarType,
4445
GraphQLObjectType,
4546
GraphQLInterfaceType,
4647
GraphQLUnionType,
4748
GraphQLEnumType,
4849
GraphQLInputObjectType,
50+
GraphQLField,
51+
GraphQLArgument,
52+
GraphQLEnumValue,
53+
GraphQLInputField,
4954
GraphQLList,
5055
GraphQLNonNull,
5156
// Standard GraphQL Scalars
@@ -160,23 +165,19 @@ export type {
160165
GraphQLSchemaExtensions,
161166
GraphQLDirectiveConfig,
162167
GraphQLDirectiveExtensions,
163-
GraphQLArgument,
164168
GraphQLArgumentConfig,
165169
GraphQLArgumentExtensions,
166170
GraphQLEnumTypeConfig,
167171
GraphQLEnumTypeExtensions,
168-
GraphQLEnumValue,
169172
GraphQLEnumValueConfig,
170173
GraphQLEnumValueConfigMap,
171174
GraphQLEnumValueExtensions,
172-
GraphQLField,
173175
GraphQLFieldConfig,
174176
GraphQLFieldConfigArgumentMap,
175177
GraphQLFieldConfigMap,
176178
GraphQLFieldExtensions,
177179
GraphQLFieldMap,
178180
GraphQLFieldResolver,
179-
GraphQLInputField,
180181
GraphQLInputFieldConfig,
181182
GraphQLInputFieldConfigMap,
182183
GraphQLInputFieldExtensions,

0 commit comments

Comments
 (0)