Skip to content

Commit

Permalink
Add coordinate field to schema element definitions
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
leebyron committed May 30, 2021
1 parent e688f88 commit 10377f4
Show file tree
Hide file tree
Showing 23 changed files with 446 additions and 509 deletions.
11 changes: 5 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ export { graphql, graphqlSync } from './graphql';
/** Create and operate on GraphQL type definitions and schema. */
export {
/** Definitions */
GraphQLSchema,
GraphQLDirective,
GraphQLSchemaElement,
GraphQLScalarType,
GraphQLObjectType,
GraphQLInterfaceType,
GraphQLUnionType,
GraphQLEnumType,
GraphQLInputObjectType,
GraphQLField,
GraphQLArgument,
GraphQLEnumValue,
GraphQLInputField,
GraphQLList,
GraphQLNonNull,
/** Standard GraphQL Scalars */
Expand Down Expand Up @@ -144,23 +147,19 @@ export type {
GraphQLSchemaExtensions,
GraphQLDirectiveConfig,
GraphQLDirectiveExtensions,
GraphQLArgument,
GraphQLArgumentConfig,
GraphQLArgumentExtensions,
GraphQLEnumTypeConfig,
GraphQLEnumTypeExtensions,
GraphQLEnumValue,
GraphQLEnumValueConfig,
GraphQLEnumValueConfigMap,
GraphQLEnumValueExtensions,
GraphQLField,
GraphQLFieldConfig,
GraphQLFieldConfigArgumentMap,
GraphQLFieldConfigMap,
GraphQLFieldExtensions,
GraphQLFieldMap,
GraphQLFieldResolver,
GraphQLInputField,
GraphQLInputFieldConfig,
GraphQLInputFieldConfigMap,
GraphQLInputFieldExtensions,
Expand Down
16 changes: 12 additions & 4 deletions src/type/__tests__/definition-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ describe('Type System: Objects', () => {
},
};
const testObject1 = new GraphQLObjectType({
name: 'Test1',
name: 'Test',
fields: outputFields,
});
const testObject2 = new GraphQLObjectType({
name: 'Test2',
name: 'Test',
fields: outputFields,
});

Expand All @@ -191,11 +191,11 @@ describe('Type System: Objects', () => {
field2: { type: ScalarType },
};
const testInputObject1 = new GraphQLInputObjectType({
name: 'Test1',
name: 'Test',
fields: inputFields,
});
const testInputObject2 = new GraphQLInputObjectType({
name: 'Test2',
name: 'Test',
fields: inputFields,
});

Expand Down Expand Up @@ -243,6 +243,7 @@ describe('Type System: Objects', () => {
});
expect(objType.getFields()).to.deep.equal({
f: {
coordinate: 'SomeObject.f',
name: 'f',
description: undefined,
type: ScalarType,
Expand Down Expand Up @@ -270,11 +271,13 @@ describe('Type System: Objects', () => {
});
expect(objType.getFields()).to.deep.equal({
f: {
coordinate: 'SomeObject.f',
name: 'f',
description: undefined,
type: ScalarType,
args: [
{
coordinate: 'SomeObject.f(arg:)',
name: 'arg',
description: undefined,
type: ScalarType,
Expand Down Expand Up @@ -624,6 +627,7 @@ describe('Type System: Enums', () => {

expect(EnumTypeWithNullishValue.getValues()).to.deep.equal([
{
coordinate: 'EnumWithNullishValue.NULL',
name: 'NULL',
description: undefined,
value: null,
Expand All @@ -632,6 +636,7 @@ describe('Type System: Enums', () => {
astNode: undefined,
},
{
coordinate: 'EnumWithNullishValue.NAN',
name: 'NAN',
description: undefined,
value: NaN,
Expand All @@ -640,6 +645,7 @@ describe('Type System: Enums', () => {
astNode: undefined,
},
{
coordinate: 'EnumWithNullishValue.NO_CUSTOM_VALUE',
name: 'NO_CUSTOM_VALUE',
description: undefined,
value: 'NO_CUSTOM_VALUE',
Expand Down Expand Up @@ -730,6 +736,7 @@ describe('Type System: Input Objects', () => {
});
expect(inputObjType.getFields()).to.deep.equal({
f: {
coordinate: 'SomeInputObject.f',
name: 'f',
description: undefined,
type: ScalarType,
Expand All @@ -750,6 +757,7 @@ describe('Type System: Input Objects', () => {
});
expect(inputObjType.getFields()).to.deep.equal({
f: {
coordinate: 'SomeInputObject.f',
name: 'f',
description: undefined,
type: ScalarType,
Expand Down
2 changes: 2 additions & 0 deletions src/type/__tests__/directive-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('Type System: Directive', () => {
name: 'Foo',
args: [
{
coordinate: '@Foo(foo:)',
name: 'foo',
description: undefined,
type: GraphQLString,
Expand All @@ -42,6 +43,7 @@ describe('Type System: Directive', () => {
astNode: undefined,
},
{
coordinate: '@Foo(bar:)',
name: 'bar',
description: undefined,
type: GraphQLInt,
Expand Down
2 changes: 2 additions & 0 deletions src/type/__tests__/enumType-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ describe('Type System: Enum Values', () => {
const values = ComplexEnum.getValues();
expect(values).to.have.deep.ordered.members([
{
coordinate: 'Complex.ONE',
name: 'ONE',
description: undefined,
value: Complex1,
Expand All @@ -350,6 +351,7 @@ describe('Type System: Enum Values', () => {
astNode: undefined,
},
{
coordinate: 'Complex.TWO',
name: 'TWO',
description: undefined,
value: Complex2,
Expand Down
2 changes: 1 addition & 1 deletion src/type/__tests__/introspection-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,7 @@ describe('Introspection', () => {
errors: [
{
message:
'Field "__type" argument "name" of type "String!" is required, but it was not provided.',
'Argument <meta>.__type(name:) of type "String!" is required, but it was not provided.',
locations: [{ line: 3, column: 9 }],
},
],
Expand Down
28 changes: 5 additions & 23 deletions src/type/__tests__/predicate-test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';

import type {
GraphQLArgument,
GraphQLInputField,
GraphQLInputType,
} from '../definition';
import type { GraphQLInputType } from '../definition';
import {
GraphQLDirective,
GraphQLSkipDirective,
Expand All @@ -29,8 +25,10 @@ import {
GraphQLScalarType,
GraphQLEnumType,
GraphQLInputObjectType,
GraphQLInputField,
GraphQLInterfaceType,
GraphQLObjectType,
GraphQLArgument,
GraphQLUnionType,
isType,
isScalarType,
Expand Down Expand Up @@ -567,15 +565,7 @@ describe('Type predicates', () => {
type: GraphQLInputType;
defaultValue?: unknown;
}): GraphQLArgument {
return {
name: 'someArg',
type: config.type,
description: undefined,
defaultValue: config.defaultValue,
deprecationReason: null,
extensions: undefined,
astNode: undefined,
};
return new GraphQLArgument('SomeType.someField', 'someArg', config);
}

it('returns true for required arguments', () => {
Expand Down Expand Up @@ -615,15 +605,7 @@ describe('Type predicates', () => {
type: GraphQLInputType;
defaultValue?: unknown;
}): GraphQLInputField {
return {
name: 'someInputField',
type: config.type,
description: undefined,
defaultValue: config.defaultValue,
deprecationReason: null,
extensions: undefined,
astNode: undefined,
};
return new GraphQLInputField('SomeType', 'someInputField', config);
}

it('returns true for required input field', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/type/__tests__/validation-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ describe('Objects must adhere to Interface they implement', () => {
expect(validateSchema(schema)).to.deep.equal([
{
message:
'Object field AnotherObject.field includes required argument requiredArg that is missing from the Interface field AnotherInterface.field.',
'Argument AnotherObject.field(requiredArg:) must not be required type String! if not provided by the Interface field AnotherInterface.field.',
locations: [
{ line: 13, column: 11 },
{ line: 7, column: 9 },
Expand Down Expand Up @@ -2169,11 +2169,11 @@ describe('Interfaces must adhere to Interface they implement', () => {
}
interface ParentInterface {
field(input: String): String
field(input: String!): String
}
interface ChildInterface implements ParentInterface {
field(input: String, anotherInput: String): String
field(input: String!, anotherInput: String): String
}
`);
expect(validateSchema(schema)).to.deep.equal([]);
Expand Down Expand Up @@ -2431,7 +2431,7 @@ describe('Interfaces must adhere to Interface they implement', () => {
expect(validateSchema(schema)).to.deep.equal([
{
message:
'Object field ChildInterface.field includes required argument requiredArg that is missing from the Interface field ParentInterface.field.',
'Argument ChildInterface.field(requiredArg:) must not be required type String! if not provided by the Interface field ParentInterface.field.',
locations: [
{ line: 13, column: 11 },
{ line: 7, column: 9 },
Expand Down
Loading

0 comments on commit 10377f4

Please sign in to comment.