Skip to content

Commit f7e4d06

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 33c5916 commit f7e4d06

26 files changed

+636
-641
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
@@ -85,7 +85,7 @@ function coerceVariableValues(
8585
const varTypeStr = print(varDefNode.type);
8686
onError(
8787
new GraphQLError(
88-
`Variable "$${varName}" expected value of type "${varTypeStr}" which cannot be used as an input type.`,
88+
`Variable "$${varName}" expected value of type ${varTypeStr} which cannot be used as an input type.`,
8989
{ nodes: varDefNode.type },
9090
),
9191
);
@@ -96,10 +96,9 @@ function coerceVariableValues(
9696
if (varDefNode.defaultValue) {
9797
coercedValues[varName] = valueFromAST(varDefNode.defaultValue, varType);
9898
} else if (isNonNullType(varType)) {
99-
const varTypeStr = inspect(varType);
10099
onError(
101100
new GraphQLError(
102-
`Variable "$${varName}" of required type "${varTypeStr}" was not provided.`,
101+
`Variable "$${varName}" of required type ${varType} was not provided.`,
103102
{ nodes: varDefNode },
104103
),
105104
);
@@ -109,10 +108,9 @@ function coerceVariableValues(
109108

110109
const value = inputs[varName];
111110
if (value === null && isNonNullType(varType)) {
112-
const varTypeStr = inspect(varType);
113111
onError(
114112
new GraphQLError(
115-
`Variable "$${varName}" of non-null type "${varTypeStr}" must not be null.`,
113+
`Variable "$${varName}" of non-null type ${varType} must not be null.`,
116114
{ nodes: varDefNode },
117115
),
118116
);
@@ -171,8 +169,7 @@ export function getArgumentValues(
171169
coercedValues[name] = argDef.defaultValue;
172170
} else if (isNonNullType(argType)) {
173171
throw new GraphQLError(
174-
`Argument "${name}" of required type "${inspect(argType)}" ` +
175-
'was not provided.',
172+
`Argument ${argDef} of required type ${argType} was not provided.`,
176173
{ nodes: node },
177174
);
178175
}
@@ -192,7 +189,7 @@ export function getArgumentValues(
192189
coercedValues[name] = argDef.defaultValue;
193190
} else if (isNonNullType(argType)) {
194191
throw new GraphQLError(
195-
`Argument "${name}" of required type "${inspect(argType)}" ` +
192+
`Argument ${argDef} of required type ${argType} ` +
196193
`was provided the variable "$${variableName}" which was not provided a runtime value.`,
197194
{ nodes: valueNode },
198195
);
@@ -204,8 +201,7 @@ export function getArgumentValues(
204201

205202
if (isNull && isNonNullType(argType)) {
206203
throw new GraphQLError(
207-
`Argument "${name}" of non-null type "${inspect(argType)}" ` +
208-
'must not be null.',
204+
`Argument ${argDef} of non-null type ${argType} must not be null.`,
209205
{ nodes: valueNode },
210206
);
211207
}
@@ -216,7 +212,9 @@ export function getArgumentValues(
216212
// execution. This is a runtime check to ensure execution does not
217213
// continue with an invalid argument value.
218214
throw new GraphQLError(
219-
`Argument "${name}" has invalid value ${print(valueNode)}.`,
215+
`Argument ${argDef} of type ${argType} has invalid value ${print(
216+
valueNode,
217+
)}.`,
220218
{ nodes: valueNode },
221219
);
222220
}

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)