Skip to content

Commit d0dd902

Browse files
leebyronyaacovCR
authored andcommitted
Add coordinate field to schema element definitions
* Changes `GraphQLSchemaElement` interface into a base class which defines a `.coordinate` property and `toString`/`toJSON` methods. * Uses the base class to types, fields, arguments, input fields, enum values, and directives. * Uses this in validation error printing string templates. * Exports the now finalized GraphQLSchemaElement, GraphQLField, GraphQLArgument, GraphQLInputField, GraphQLEnumValue classes. This differs from the original #3145 in that GraphQLField, GraphQLArgument, GraphQLInputField, GraphQLEnumValue constructors take the parent type/field as arguments instead of the parent coordinate. This obviates the need to validate the parent coordinate.
1 parent 1f70a93 commit d0dd902

File tree

8 files changed

+116
-144
lines changed

8 files changed

+116
-144
lines changed

src/index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,23 @@ export type { GraphQLArgs } from './graphql.js';
3434
export { graphql, graphqlSync } from './graphql.js';
3535

3636
// Create and operate on GraphQL type definitions and schema.
37-
export type {
38-
GraphQLField,
39-
GraphQLArgument,
40-
GraphQLEnumValue,
41-
GraphQLInputField,
42-
} from './type/index.js';
4337
export {
4438
resolveObjMapThunk,
4539
resolveReadonlyArrayThunk,
4640
// Definitions
4741
GraphQLSchema,
4842
GraphQLDirective,
43+
GraphQLSchemaElement,
4944
GraphQLScalarType,
5045
GraphQLObjectType,
5146
GraphQLInterfaceType,
5247
GraphQLUnionType,
5348
GraphQLEnumType,
5449
GraphQLInputObjectType,
50+
GraphQLField,
51+
GraphQLArgument,
52+
GraphQLEnumValue,
53+
GraphQLInputField,
5554
GraphQLList,
5655
GraphQLNonNull,
5756
// Standard GraphQL Scalars

src/type/__tests__/definition-test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ describe('Type System: Objects', () => {
329329
}),
330330
});
331331
expect(objType.getFields().f).to.deep.include({
332+
coordinate: 'SomeObject.f',
332333
parentType: objType,
333334
name: 'f',
334335
description: undefined,
@@ -358,6 +359,7 @@ describe('Type System: Objects', () => {
358359
const f = objType.getFields().f;
359360

360361
expect(f).to.deep.include({
362+
coordinate: 'SomeObject.f',
361363
parentType: objType,
362364
name: 'f',
363365
description: undefined,
@@ -372,6 +374,7 @@ describe('Type System: Objects', () => {
372374
expect(f.args).to.have.lengthOf(1);
373375

374376
expect(f.args[0]).to.deep.include({
377+
coordinate: 'SomeObject.f(arg:)',
375378
parent: f,
376379
name: 'arg',
377380
description: undefined,
@@ -736,6 +739,8 @@ describe('Type System: Enums', () => {
736739
expect(values).to.have.lengthOf(3);
737740

738741
expect(values[0]).to.deep.include({
742+
coordinate: 'EnumWithNullishValue.NULL',
743+
parentEnum: EnumTypeWithNullishValue,
739744
name: 'NULL',
740745
description: undefined,
741746
value: null,
@@ -745,6 +750,8 @@ describe('Type System: Enums', () => {
745750
});
746751

747752
expect(values[1]).to.deep.include({
753+
coordinate: 'EnumWithNullishValue.NAN',
754+
parentEnum: EnumTypeWithNullishValue,
748755
name: 'NAN',
749756
description: undefined,
750757
value: NaN,
@@ -754,6 +761,8 @@ describe('Type System: Enums', () => {
754761
});
755762

756763
expect(values[2]).to.deep.include({
764+
coordinate: 'EnumWithNullishValue.NO_CUSTOM_VALUE',
765+
parentEnum: EnumTypeWithNullishValue,
757766
name: 'NO_CUSTOM_VALUE',
758767
description: undefined,
759768
value: 'NO_CUSTOM_VALUE',
@@ -856,6 +865,7 @@ describe('Type System: Input Objects', () => {
856865
},
857866
});
858867
expect(inputObjType.getFields().f).to.deep.include({
868+
coordinate: 'SomeInputObject.f',
859869
parentType: inputObjType,
860870
name: 'f',
861871
description: undefined,
@@ -876,6 +886,7 @@ describe('Type System: Input Objects', () => {
876886
}),
877887
});
878888
expect(inputObjType.getFields().f).to.deep.include({
889+
coordinate: 'SomeInputObject.f',
879890
parentType: inputObjType,
880891
name: 'f',
881892
description: undefined,

src/type/__tests__/directive-test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe('Type System: Directive', () => {
4040
expect(directive.args).to.have.lengthOf(2);
4141

4242
expect(directive.args[0]).to.deep.include({
43+
coordinate: '@Foo(foo:)',
4344
parent: directive,
4445
name: 'foo',
4546
description: undefined,
@@ -52,6 +53,7 @@ describe('Type System: Directive', () => {
5253
});
5354

5455
expect(directive.args[1]).to.deep.include({
56+
coordinate: '@Foo(bar:)',
5557
parent: directive,
5658
name: 'bar',
5759
description: undefined,

src/type/__tests__/enumType-test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ describe('Type System: Enum Values', () => {
398398

399399
expect(values[0]).to.deep.include({
400400
parentEnum: ComplexEnum,
401+
coordinate: 'Complex.ONE',
401402
name: 'ONE',
402403
description: undefined,
403404
value: Complex1,
@@ -408,6 +409,7 @@ describe('Type System: Enum Values', () => {
408409

409410
expect(values[1]).to.deep.include({
410411
parentEnum: ComplexEnum,
412+
coordinate: 'Complex.TWO',
411413
name: 'TWO',
412414
description: undefined,
413415
value: Complex2,

0 commit comments

Comments
 (0)