Skip to content

Commit 39b5de5

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 3945604 commit 39b5de5

26 files changed

+635
-640
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

+11-10
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ describe('Execute: Handles inputs', () => {
204204
errors: [
205205
{
206206
message:
207-
'Argument "input" has invalid value ["foo", "bar", "baz"].',
207+
'Argument TestType.fieldWithObjectInput(input:) of type TestInputObject has invalid value ["foo", "bar", "baz"].',
208208
path: ['fieldWithObjectInput'],
209209
locations: [{ line: 3, column: 41 }],
210210
},
@@ -618,7 +618,7 @@ describe('Execute: Handles inputs', () => {
618618
errors: [
619619
{
620620
message:
621-
'Variable "$value" of required type "String!" was not provided.',
621+
'Variable "$value" of required type String! was not provided.',
622622
locations: [{ line: 2, column: 16 }],
623623
},
624624
],
@@ -637,7 +637,7 @@ describe('Execute: Handles inputs', () => {
637637
errors: [
638638
{
639639
message:
640-
'Variable "$value" of non-null type "String!" must not be null.',
640+
'Variable "$value" of non-null type String! must not be null.',
641641
locations: [{ line: 2, column: 16 }],
642642
},
643643
],
@@ -683,7 +683,7 @@ describe('Execute: Handles inputs', () => {
683683
errors: [
684684
{
685685
message:
686-
'Argument "input" of required type "String!" was not provided.',
686+
'Argument TestType.fieldWithNonNullableStringInput(input:) of required type String! was not provided.',
687687
locations: [{ line: 1, column: 3 }],
688688
path: ['fieldWithNonNullableStringInput'],
689689
},
@@ -731,7 +731,7 @@ describe('Execute: Handles inputs', () => {
731731
errors: [
732732
{
733733
message:
734-
'Argument "input" of required type "String!" was provided the variable "$foo" which was not provided a runtime value.',
734+
'Argument TestType.fieldWithNonNullableStringInput(input:) of required type String! was provided the variable "$foo" which was not provided a runtime value.',
735735
locations: [{ line: 3, column: 50 }],
736736
path: ['fieldWithNonNullableStringInput'],
737737
},
@@ -786,7 +786,7 @@ describe('Execute: Handles inputs', () => {
786786
errors: [
787787
{
788788
message:
789-
'Variable "$input" of non-null type "[String]!" must not be null.',
789+
'Variable "$input" of non-null type [String]! must not be null.',
790790
locations: [{ line: 2, column: 16 }],
791791
},
792792
],
@@ -868,7 +868,7 @@ describe('Execute: Handles inputs', () => {
868868
errors: [
869869
{
870870
message:
871-
'Variable "$input" of non-null type "[String!]!" must not be null.',
871+
'Variable "$input" of non-null type [String!]! must not be null.',
872872
locations: [{ line: 2, column: 16 }],
873873
},
874874
],
@@ -917,7 +917,7 @@ describe('Execute: Handles inputs', () => {
917917
errors: [
918918
{
919919
message:
920-
'Variable "$input" expected value of type "TestType!" which cannot be used as an input type.',
920+
'Variable "$input" expected value of type TestType! which cannot be used as an input type.',
921921
locations: [{ line: 2, column: 24 }],
922922
},
923923
],
@@ -936,7 +936,7 @@ describe('Execute: Handles inputs', () => {
936936
errors: [
937937
{
938938
message:
939-
'Variable "$input" expected value of type "UnknownType!" which cannot be used as an input type.',
939+
'Variable "$input" expected value of type UnknownType! which cannot be used as an input type.',
940940
locations: [{ line: 2, column: 24 }],
941941
},
942942
],
@@ -982,7 +982,8 @@ describe('Execute: Handles inputs', () => {
982982
},
983983
errors: [
984984
{
985-
message: 'Argument "input" has invalid value WRONG_TYPE.',
985+
message:
986+
'Argument TestType.fieldWithDefaultArgumentValue(input:) of type String has invalid value WRONG_TYPE.',
986987
locations: [{ line: 3, column: 48 }],
987988
path: ['fieldWithDefaultArgumentValue'],
988989
},

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)