Skip to content

Commit 10377f4

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 e688f88 commit 10377f4

23 files changed

+446
-509
lines changed

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
],

src/type/__tests__/predicate-test.ts

+5-23
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { expect } from 'chai';
22
import { describe, it } from 'mocha';
33

4-
import type {
5-
GraphQLArgument,
6-
GraphQLInputField,
7-
GraphQLInputType,
8-
} from '../definition';
4+
import type { GraphQLInputType } from '../definition';
95
import {
106
GraphQLDirective,
117
GraphQLSkipDirective,
@@ -29,8 +25,10 @@ import {
2925
GraphQLScalarType,
3026
GraphQLEnumType,
3127
GraphQLInputObjectType,
28+
GraphQLInputField,
3229
GraphQLInterfaceType,
3330
GraphQLObjectType,
31+
GraphQLArgument,
3432
GraphQLUnionType,
3533
isType,
3634
isScalarType,
@@ -567,15 +565,7 @@ describe('Type predicates', () => {
567565
type: GraphQLInputType;
568566
defaultValue?: unknown;
569567
}): GraphQLArgument {
570-
return {
571-
name: 'someArg',
572-
type: config.type,
573-
description: undefined,
574-
defaultValue: config.defaultValue,
575-
deprecationReason: null,
576-
extensions: undefined,
577-
astNode: undefined,
578-
};
568+
return new GraphQLArgument('SomeType.someField', 'someArg', config);
579569
}
580570

581571
it('returns true for required arguments', () => {
@@ -615,15 +605,7 @@ describe('Type predicates', () => {
615605
type: GraphQLInputType;
616606
defaultValue?: unknown;
617607
}): GraphQLInputField {
618-
return {
619-
name: 'someInputField',
620-
type: config.type,
621-
description: undefined,
622-
defaultValue: config.defaultValue,
623-
deprecationReason: null,
624-
extensions: undefined,
625-
astNode: undefined,
626-
};
608+
return new GraphQLInputField('SomeType', 'someInputField', config);
627609
}
628610

629611
it('returns true for required input field', () => {

src/type/__tests__/validation-test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@ describe('Objects must adhere to Interface they implement', () => {
19741974
expect(validateSchema(schema)).to.deep.equal([
19751975
{
19761976
message:
1977-
'Object field AnotherObject.field includes required argument requiredArg that is missing from the Interface field AnotherInterface.field.',
1977+
'Argument AnotherObject.field(requiredArg:) must not be required type String! if not provided by the Interface field AnotherInterface.field.',
19781978
locations: [
19791979
{ line: 13, column: 11 },
19801980
{ line: 7, column: 9 },
@@ -2169,11 +2169,11 @@ describe('Interfaces must adhere to Interface they implement', () => {
21692169
}
21702170
21712171
interface ParentInterface {
2172-
field(input: String): String
2172+
field(input: String!): String
21732173
}
21742174
21752175
interface ChildInterface implements ParentInterface {
2176-
field(input: String, anotherInput: String): String
2176+
field(input: String!, anotherInput: String): String
21772177
}
21782178
`);
21792179
expect(validateSchema(schema)).to.deep.equal([]);
@@ -2431,7 +2431,7 @@ describe('Interfaces must adhere to Interface they implement', () => {
24312431
expect(validateSchema(schema)).to.deep.equal([
24322432
{
24332433
message:
2434-
'Object field ChildInterface.field includes required argument requiredArg that is missing from the Interface field ParentInterface.field.',
2434+
'Argument ChildInterface.field(requiredArg:) must not be required type String! if not provided by the Interface field ParentInterface.field.',
24352435
locations: [
24362436
{ line: 13, column: 11 },
24372437
{ line: 7, column: 9 },

0 commit comments

Comments
 (0)