Skip to content

Commit a4c7cea

Browse files
committed
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 8fa8a4c commit a4c7cea

26 files changed

+473
-536
lines changed

src/execution/__tests__/nonnull-test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ describe('Execute: handles non-nullable types', () => {
616616
errors: [
617617
{
618618
message:
619-
'Argument "cannotBeNull" of required type "String!" was not provided.',
619+
'Argument Query.withNonNullArg(cannotBeNull:) of required type String! was not provided.',
620620
locations: [{ line: 3, column: 13 }],
621621
path: ['withNonNullArg'],
622622
},
@@ -643,7 +643,7 @@ describe('Execute: handles non-nullable types', () => {
643643
errors: [
644644
{
645645
message:
646-
'Argument "cannotBeNull" of non-null type "String!" must not be null.',
646+
'Argument Query.withNonNullArg(cannotBeNull:) of non-null type String! must not be null.',
647647
locations: [{ line: 3, column: 42 }],
648648
path: ['withNonNullArg'],
649649
},
@@ -673,7 +673,7 @@ describe('Execute: handles non-nullable types', () => {
673673
errors: [
674674
{
675675
message:
676-
'Argument "cannotBeNull" of required type "String!" was provided the variable "$testVar" which was not provided a runtime value.',
676+
'Argument Query.withNonNullArg(cannotBeNull:) of required type String! was provided the variable "$testVar" which was not provided a runtime value.',
677677
locations: [{ line: 3, column: 42 }],
678678
path: ['withNonNullArg'],
679679
},
@@ -701,7 +701,7 @@ describe('Execute: handles non-nullable types', () => {
701701
errors: [
702702
{
703703
message:
704-
'Argument "cannotBeNull" of non-null type "String!" must not be null.',
704+
'Argument Query.withNonNullArg(cannotBeNull:) of non-null type String! must not be null.',
705705
locations: [{ line: 3, column: 43 }],
706706
path: ['withNonNullArg'],
707707
},

src/execution/__tests__/variables-test.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ describe('Execute: Handles inputs', () => {
203203
errors: [
204204
{
205205
message:
206-
'Argument "input" has invalid value ["foo", "bar", "baz"].',
206+
'Argument TestType.fieldWithObjectInput(input:) of type TestInputObject has invalid value ["foo", "bar", "baz"].',
207207
path: ['fieldWithObjectInput'],
208208
locations: [{ line: 3, column: 41 }],
209209
},
@@ -617,7 +617,7 @@ describe('Execute: Handles inputs', () => {
617617
errors: [
618618
{
619619
message:
620-
'Variable "$value" of required type "String!" was not provided.',
620+
'Variable "$value" of required type String! was not provided.',
621621
locations: [{ line: 2, column: 16 }],
622622
},
623623
],
@@ -636,7 +636,7 @@ describe('Execute: Handles inputs', () => {
636636
errors: [
637637
{
638638
message:
639-
'Variable "$value" of non-null type "String!" must not be null.',
639+
'Variable "$value" of non-null type String! must not be null.',
640640
locations: [{ line: 2, column: 16 }],
641641
},
642642
],
@@ -682,7 +682,7 @@ describe('Execute: Handles inputs', () => {
682682
errors: [
683683
{
684684
message:
685-
'Argument "input" of required type "String!" was not provided.',
685+
'Argument TestType.fieldWithNonNullableStringInput(input:) of required type String! was not provided.',
686686
locations: [{ line: 1, column: 3 }],
687687
path: ['fieldWithNonNullableStringInput'],
688688
},
@@ -730,7 +730,7 @@ describe('Execute: Handles inputs', () => {
730730
errors: [
731731
{
732732
message:
733-
'Argument "input" of required type "String!" was provided the variable "$foo" which was not provided a runtime value.',
733+
'Argument TestType.fieldWithNonNullableStringInput(input:) of required type String! was provided the variable "$foo" which was not provided a runtime value.',
734734
locations: [{ line: 3, column: 50 }],
735735
path: ['fieldWithNonNullableStringInput'],
736736
},
@@ -785,7 +785,7 @@ describe('Execute: Handles inputs', () => {
785785
errors: [
786786
{
787787
message:
788-
'Variable "$input" of non-null type "[String]!" must not be null.',
788+
'Variable "$input" of non-null type [String]! must not be null.',
789789
locations: [{ line: 2, column: 16 }],
790790
},
791791
],
@@ -867,7 +867,7 @@ describe('Execute: Handles inputs', () => {
867867
errors: [
868868
{
869869
message:
870-
'Variable "$input" of non-null type "[String!]!" must not be null.',
870+
'Variable "$input" of non-null type [String!]! must not be null.',
871871
locations: [{ line: 2, column: 16 }],
872872
},
873873
],
@@ -916,7 +916,7 @@ describe('Execute: Handles inputs', () => {
916916
errors: [
917917
{
918918
message:
919-
'Variable "$input" expected value of type "TestType!" which cannot be used as an input type.',
919+
'Variable "$input" expected value of type TestType! which cannot be used as an input type.',
920920
locations: [{ line: 2, column: 24 }],
921921
},
922922
],
@@ -935,7 +935,7 @@ describe('Execute: Handles inputs', () => {
935935
errors: [
936936
{
937937
message:
938-
'Variable "$input" expected value of type "UnknownType!" which cannot be used as an input type.',
938+
'Variable "$input" expected value of type UnknownType! which cannot be used as an input type.',
939939
locations: [{ line: 2, column: 24 }],
940940
},
941941
],
@@ -981,7 +981,8 @@ describe('Execute: Handles inputs', () => {
981981
},
982982
errors: [
983983
{
984-
message: 'Argument "input" has invalid value WRONG_TYPE.',
984+
message:
985+
'Argument TestType.fieldWithDefaultArgumentValue(input:) of type String has invalid value WRONG_TYPE.',
985986
locations: [{ line: 3, column: 48 }],
986987
path: ['fieldWithDefaultArgumentValue'],
987988
},

src/execution/values.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function coerceVariableValues(
8787
const varTypeStr = print(varDefNode.type);
8888
onError(
8989
new GraphQLError(
90-
`Variable "$${varName}" expected value of type "${varTypeStr}" which cannot be used as an input type.`,
90+
`Variable "$${varName}" expected value of type ${varTypeStr} which cannot be used as an input type.`,
9191
varDefNode.type,
9292
),
9393
);
@@ -98,10 +98,9 @@ function coerceVariableValues(
9898
if (varDefNode.defaultValue) {
9999
coercedValues[varName] = valueFromAST(varDefNode.defaultValue, varType);
100100
} else if (isNonNullType(varType)) {
101-
const varTypeStr = inspect(varType);
102101
onError(
103102
new GraphQLError(
104-
`Variable "$${varName}" of required type "${varTypeStr}" was not provided.`,
103+
`Variable "$${varName}" of required type ${varType} was not provided.`,
105104
varDefNode,
106105
),
107106
);
@@ -111,10 +110,9 @@ function coerceVariableValues(
111110

112111
const value = inputs[varName];
113112
if (value === null && isNonNullType(varType)) {
114-
const varTypeStr = inspect(varType);
115113
onError(
116114
new GraphQLError(
117-
`Variable "$${varName}" of non-null type "${varTypeStr}" must not be null.`,
115+
`Variable "$${varName}" of non-null type ${varType} must not be null.`,
118116
varDefNode,
119117
),
120118
);
@@ -178,8 +176,7 @@ export function getArgumentValues(
178176
coercedValues[name] = argDef.defaultValue;
179177
} else if (isNonNullType(argType)) {
180178
throw new GraphQLError(
181-
`Argument "${name}" of required type "${inspect(argType)}" ` +
182-
'was not provided.',
179+
`Argument ${argDef} of required type ${argType} was not provided.`,
183180
node,
184181
);
185182
}
@@ -199,7 +196,7 @@ export function getArgumentValues(
199196
coercedValues[name] = argDef.defaultValue;
200197
} else if (isNonNullType(argType)) {
201198
throw new GraphQLError(
202-
`Argument "${name}" of required type "${inspect(argType)}" ` +
199+
`Argument ${argDef} of required type ${argType} ` +
203200
`was provided the variable "$${variableName}" which was not provided a runtime value.`,
204201
valueNode,
205202
);
@@ -211,8 +208,7 @@ export function getArgumentValues(
211208

212209
if (isNull && isNonNullType(argType)) {
213210
throw new GraphQLError(
214-
`Argument "${name}" of non-null type "${inspect(argType)}" ` +
215-
'must not be null.',
211+
`Argument ${argDef} of non-null type ${argType} must not be null.`,
216212
valueNode,
217213
);
218214
}
@@ -223,7 +219,9 @@ export function getArgumentValues(
223219
// execution. This is a runtime check to ensure execution does not
224220
// continue with an invalid argument value.
225221
throw new GraphQLError(
226-
`Argument "${name}" has invalid value ${print(valueNode)}.`,
222+
`Argument ${argDef} of type ${argType} has invalid value ${print(
223+
valueNode,
224+
)}.`,
227225
valueNode,
228226
);
229227
}

src/index.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,17 @@ export { graphql, graphqlSync } from './graphql';
3232
/** Create and operate on GraphQL type definitions and schema. */
3333
export {
3434
/** Definitions */
35-
GraphQLSchema,
36-
GraphQLDirective,
35+
GraphQLSchemaElement,
3736
GraphQLScalarType,
3837
GraphQLObjectType,
3938
GraphQLInterfaceType,
4039
GraphQLUnionType,
4140
GraphQLEnumType,
4241
GraphQLInputObjectType,
42+
GraphQLField,
43+
GraphQLArgument,
44+
GraphQLEnumValue,
45+
GraphQLInputField,
4346
GraphQLList,
4447
GraphQLNonNull,
4548
/** Standard GraphQL Scalars */
@@ -144,23 +147,19 @@ export type {
144147
GraphQLSchemaExtensions,
145148
GraphQLDirectiveConfig,
146149
GraphQLDirectiveExtensions,
147-
GraphQLArgument,
148150
GraphQLArgumentConfig,
149151
GraphQLArgumentExtensions,
150152
GraphQLEnumTypeConfig,
151153
GraphQLEnumTypeExtensions,
152-
GraphQLEnumValue,
153154
GraphQLEnumValueConfig,
154155
GraphQLEnumValueConfigMap,
155156
GraphQLEnumValueExtensions,
156-
GraphQLField,
157157
GraphQLFieldConfig,
158158
GraphQLFieldConfigArgumentMap,
159159
GraphQLFieldConfigMap,
160160
GraphQLFieldExtensions,
161161
GraphQLFieldMap,
162162
GraphQLFieldResolver,
163-
GraphQLInputField,
164163
GraphQLInputFieldConfig,
165164
GraphQLInputFieldConfigMap,
166165
GraphQLInputFieldExtensions,

src/type/__tests__/definition-test.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ describe('Type System: Objects', () => {
165165
},
166166
};
167167
const testObject1 = new GraphQLObjectType({
168-
name: 'Test1',
168+
name: 'Test',
169169
fields: outputFields,
170170
});
171171
const testObject2 = new GraphQLObjectType({
172-
name: 'Test2',
172+
name: 'Test',
173173
fields: outputFields,
174174
});
175175

@@ -191,11 +191,11 @@ describe('Type System: Objects', () => {
191191
field2: { type: ScalarType },
192192
};
193193
const testInputObject1 = new GraphQLInputObjectType({
194-
name: 'Test1',
194+
name: 'Test',
195195
fields: inputFields,
196196
});
197197
const testInputObject2 = new GraphQLInputObjectType({
198-
name: 'Test2',
198+
name: 'Test',
199199
fields: inputFields,
200200
});
201201

@@ -243,6 +243,7 @@ describe('Type System: Objects', () => {
243243
});
244244
expect(objType.getFields()).to.deep.equal({
245245
f: {
246+
coordinate: 'SomeObject.f',
246247
name: 'f',
247248
description: undefined,
248249
type: ScalarType,
@@ -270,11 +271,13 @@ describe('Type System: Objects', () => {
270271
});
271272
expect(objType.getFields()).to.deep.equal({
272273
f: {
274+
coordinate: 'SomeObject.f',
273275
name: 'f',
274276
description: undefined,
275277
type: ScalarType,
276278
args: [
277279
{
280+
coordinate: 'SomeObject.f(arg:)',
278281
name: 'arg',
279282
description: undefined,
280283
type: ScalarType,
@@ -624,6 +627,7 @@ describe('Type System: Enums', () => {
624627

625628
expect(EnumTypeWithNullishValue.getValues()).to.deep.equal([
626629
{
630+
coordinate: 'EnumWithNullishValue.NULL',
627631
name: 'NULL',
628632
description: undefined,
629633
value: null,
@@ -632,6 +636,7 @@ describe('Type System: Enums', () => {
632636
astNode: undefined,
633637
},
634638
{
639+
coordinate: 'EnumWithNullishValue.NAN',
635640
name: 'NAN',
636641
description: undefined,
637642
value: NaN,
@@ -640,6 +645,7 @@ describe('Type System: Enums', () => {
640645
astNode: undefined,
641646
},
642647
{
648+
coordinate: 'EnumWithNullishValue.NO_CUSTOM_VALUE',
643649
name: 'NO_CUSTOM_VALUE',
644650
description: undefined,
645651
value: 'NO_CUSTOM_VALUE',
@@ -730,6 +736,7 @@ describe('Type System: Input Objects', () => {
730736
});
731737
expect(inputObjType.getFields()).to.deep.equal({
732738
f: {
739+
coordinate: 'SomeInputObject.f',
733740
name: 'f',
734741
description: undefined,
735742
type: ScalarType,
@@ -750,6 +757,7 @@ describe('Type System: Input Objects', () => {
750757
});
751758
expect(inputObjType.getFields()).to.deep.equal({
752759
f: {
760+
coordinate: 'SomeInputObject.f',
753761
name: 'f',
754762
description: undefined,
755763
type: ScalarType,

src/type/__tests__/directive-test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe('Type System: Directive', () => {
3333
name: 'Foo',
3434
args: [
3535
{
36+
coordinate: '@Foo(foo:)',
3637
name: 'foo',
3738
description: undefined,
3839
type: GraphQLString,
@@ -42,6 +43,7 @@ describe('Type System: Directive', () => {
4243
astNode: undefined,
4344
},
4445
{
46+
coordinate: '@Foo(bar:)',
4547
name: 'bar',
4648
description: undefined,
4749
type: GraphQLInt,

src/type/__tests__/enumType-test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ describe('Type System: Enum Values', () => {
342342
const values = ComplexEnum.getValues();
343343
expect(values).to.have.deep.ordered.members([
344344
{
345+
coordinate: 'Complex.ONE',
345346
name: 'ONE',
346347
description: undefined,
347348
value: Complex1,
@@ -350,6 +351,7 @@ describe('Type System: Enum Values', () => {
350351
astNode: undefined,
351352
},
352353
{
354+
coordinate: 'Complex.TWO',
353355
name: 'TWO',
354356
description: undefined,
355357
value: Complex2,

src/type/__tests__/introspection-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,7 @@ describe('Introspection', () => {
14801480
errors: [
14811481
{
14821482
message:
1483-
'Field "__type" argument "name" of type "String!" is required, but it was not provided.',
1483+
'Argument <meta>.__type(name:) of type "String!" is required, but it was not provided.',
14841484
locations: [{ line: 3, column: 9 }],
14851485
},
14861486
],

0 commit comments

Comments
 (0)