Skip to content

Commit 163918f

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 9fc6c0b commit 163918f

21 files changed

+588
-595
lines changed

src/execution/__tests__/nonnull-test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ describe('Execute: handles non-nullable types', () => {
683683
errors: [
684684
{
685685
message:
686-
'Argument "cannotBeNull" of required type "String!" was not provided.',
686+
'Argument "Query.withNonNullArg(cannotBeNull:)" of required type "String!" was not provided.',
687687
locations: [{ line: 3, column: 13 }],
688688
path: ['withNonNullArg'],
689689
},
@@ -710,7 +710,7 @@ describe('Execute: handles non-nullable types', () => {
710710
errors: [
711711
{
712712
message:
713-
'Argument "cannotBeNull" has invalid value: Expected value of non-null type "String!" not to be null.',
713+
'Argument "Query.withNonNullArg(cannotBeNull:)" has invalid value: Expected value of non-null type "String!" not to be null.',
714714
locations: [{ line: 3, column: 42 }],
715715
path: ['withNonNullArg'],
716716
},
@@ -740,7 +740,7 @@ describe('Execute: handles non-nullable types', () => {
740740
errors: [
741741
{
742742
message:
743-
'Argument "cannotBeNull" has invalid value: Expected variable "$testVar" provided to type "String!" to provide a runtime value.',
743+
'Argument "Query.withNonNullArg(cannotBeNull:)" has invalid value: Expected variable "$testVar" provided to type "String!" to provide a runtime value.',
744744
locations: [{ line: 3, column: 42 }],
745745
path: ['withNonNullArg'],
746746
},
@@ -768,7 +768,7 @@ describe('Execute: handles non-nullable types', () => {
768768
errors: [
769769
{
770770
message:
771-
'Argument "cannotBeNull" has invalid value: Expected variable "$testVar" provided to non-null type "String!" not to be null.',
771+
'Argument "Query.withNonNullArg(cannotBeNull:)" has invalid value: Expected variable "$testVar" provided to non-null type "String!" not to be null.',
772772
locations: [{ line: 3, column: 43 }],
773773
path: ['withNonNullArg'],
774774
},

src/execution/__tests__/oneof-test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
8888
message:
8989
// This type of error would be caught at validation-time
9090
// hence the vague error message here.
91-
'Argument "input" has invalid value: Expected variable "$input" provided to type "TestInputObject!" to provide a runtime value.',
91+
'Argument "Query.test(input:)" has invalid value: Expected variable "$input" provided to type "TestInputObject!" to provide a runtime value.',
9292
path: ['test'],
9393
},
9494
],
@@ -229,7 +229,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
229229
// A nullable variable in a oneOf field position would be caught at validation-time
230230
// hence the vague error message here.
231231
message:
232-
'Argument "input" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" not to be null.',
232+
'Argument "Query.test(input:)" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" not to be null.',
233233
locations: [{ line: 3, column: 23 }],
234234
path: ['test'],
235235
},
@@ -257,7 +257,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
257257
// A nullable variable in a oneOf field position would be caught at validation-time
258258
// hence the vague error message here.
259259
message:
260-
'Argument "input" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" to provide a runtime value.',
260+
'Argument "Query.test(input:)" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" to provide a runtime value.',
261261
locations: [{ line: 3, column: 23 }],
262262
path: ['test'],
263263
},
@@ -288,7 +288,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
288288
// A nullable variable in a oneOf field position would be caught at validation-time
289289
// hence the vague error message here.
290290
message:
291-
'Argument "input" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" not to be null.',
291+
'Argument "Query.test(input:)" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" not to be null.',
292292
locations: [{ line: 6, column: 23 }],
293293
path: ['test'],
294294
},
@@ -319,7 +319,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
319319
// A nullable variable in a oneOf field position would be caught at validation-time
320320
// hence the vague error message here.
321321
message:
322-
'Argument "input" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" to provide a runtime value.',
322+
'Argument "Query.test(input:)" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" to provide a runtime value.',
323323
locations: [{ line: 6, column: 23 }],
324324
path: ['test'],
325325
},

src/execution/__tests__/variables-test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ describe('Execute: Handles inputs', () => {
284284
errors: [
285285
{
286286
message:
287-
'Argument "input" has invalid value: Expected value of type "TestInputObject" to be an object, found: ["foo", "bar", "baz"].',
287+
'Argument "TestType.fieldWithObjectInput(input:)" has invalid value: Expected value of type "TestInputObject" to be an object, found: ["foo", "bar", "baz"].',
288288
path: ['fieldWithObjectInput'],
289289
locations: [{ line: 3, column: 41 }],
290290
},
@@ -320,7 +320,7 @@ describe('Execute: Handles inputs', () => {
320320
errors: [
321321
{
322322
message:
323-
'Argument "input" has invalid value at .e: FaultyScalarErrorMessage',
323+
'Argument "TestType.fieldWithObjectInput(input:)" has invalid value at .e: FaultyScalarErrorMessage',
324324
path: ['fieldWithObjectInput'],
325325
locations: [{ line: 3, column: 13 }],
326326
extensions: { code: 'FaultyScalarErrorExtensionCode' },
@@ -477,7 +477,7 @@ describe('Execute: Handles inputs', () => {
477477
errors: [
478478
{
479479
message:
480-
'Variable "$input" has invalid value at .e: Argument "input" has invalid value at .e: FaultyScalarErrorMessage',
480+
'Variable "$input" has invalid value at .e: Argument "TestType.fieldWithObjectInput(input:)" has invalid value at .e: FaultyScalarErrorMessage',
481481
locations: [{ line: 2, column: 16 }],
482482
extensions: { code: 'FaultyScalarErrorExtensionCode' },
483483
},
@@ -802,7 +802,7 @@ describe('Execute: Handles inputs', () => {
802802
errors: [
803803
{
804804
message:
805-
'Argument "input" of required type "String!" was not provided.',
805+
'Argument "TestType.fieldWithNonNullableStringInput(input:)" of required type "String!" was not provided.',
806806
locations: [{ line: 1, column: 3 }],
807807
path: ['fieldWithNonNullableStringInput'],
808808
},
@@ -850,7 +850,7 @@ describe('Execute: Handles inputs', () => {
850850
errors: [
851851
{
852852
message:
853-
'Argument "input" has invalid value: Expected variable "$foo" provided to type "String!" to provide a runtime value.',
853+
'Argument "TestType.fieldWithNonNullableStringInput(input:)" has invalid value: Expected variable "$foo" provided to type "String!" to provide a runtime value.',
854854
locations: [{ line: 3, column: 50 }],
855855
path: ['fieldWithNonNullableStringInput'],
856856
},
@@ -1102,7 +1102,7 @@ describe('Execute: Handles inputs', () => {
11021102
errors: [
11031103
{
11041104
message:
1105-
'Argument "input" has invalid value: String cannot represent a non string value: WRONG_TYPE',
1105+
'Argument "TestType.fieldWithDefaultArgumentValue(input:)" has invalid value: String cannot represent a non string value: WRONG_TYPE',
11061106
locations: [{ line: 3, column: 48 }],
11071107
path: ['fieldWithDefaultArgumentValue'],
11081108
},

src/execution/values.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ import type {
1313
} from '../language/ast.js';
1414
import { Kind } from '../language/kinds.js';
1515

16-
import type { GraphQLArgument, GraphQLField } from '../type/definition.js';
17-
import { isNonNullType, isRequiredArgument } from '../type/definition.js';
16+
import type { GraphQLField } from '../type/definition.js';
17+
import {
18+
GraphQLArgument,
19+
isNonNullType,
20+
isRequiredArgument,
21+
} from '../type/definition.js';
1822
import type { GraphQLDirective } from '../type/directives.js';
1923
import type { GraphQLSchema } from '../type/schema.js';
2024

@@ -222,7 +226,7 @@ export function experimentalGetArgumentValues(
222226
// execution. This is a runtime check to ensure execution does not
223227
// continue with an invalid argument value.
224228
throw new GraphQLError(
225-
`Argument "${argDef.name}" of required type "${argType}" was not provided.`,
229+
`Argument "${argDef instanceof GraphQLArgument ? argDef : argDef.name}" of required type "${argType}" was not provided.`,
226230
{ nodes: node },
227231
);
228232
}
@@ -272,7 +276,7 @@ export function experimentalGetArgumentValues(
272276
valueNode,
273277
argType,
274278
(error, path) => {
275-
error.message = `Argument "${argDef.name}" has invalid value${printPathArray(
279+
error.message = `Argument "${argDef instanceof GraphQLArgument ? argDef : argDef.name}" has invalid value${printPathArray(
276280
path,
277281
)}: ${error.message}`;
278282
throw error;

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
@@ -161,23 +166,19 @@ export type {
161166
GraphQLSchemaExtensions,
162167
GraphQLDirectiveConfig,
163168
GraphQLDirectiveExtensions,
164-
GraphQLArgument,
165169
GraphQLArgumentConfig,
166170
GraphQLArgumentExtensions,
167171
GraphQLEnumTypeConfig,
168172
GraphQLEnumTypeExtensions,
169-
GraphQLEnumValue,
170173
GraphQLEnumValueConfig,
171174
GraphQLEnumValueConfigMap,
172175
GraphQLEnumValueExtensions,
173-
GraphQLField,
174176
GraphQLFieldConfig,
175177
GraphQLFieldConfigArgumentMap,
176178
GraphQLFieldConfigMap,
177179
GraphQLFieldExtensions,
178180
GraphQLFieldMap,
179181
GraphQLFieldResolver,
180-
GraphQLInputField,
181182
GraphQLInputFieldConfig,
182183
GraphQLInputFieldConfigMap,
183184
GraphQLInputFieldExtensions,

0 commit comments

Comments
 (0)