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 authored and yaacovCR committed Jan 1, 2023
1 parent 3945604 commit cc309b6
Show file tree
Hide file tree
Showing 26 changed files with 636 additions and 640 deletions.
8 changes: 4 additions & 4 deletions src/execution/__tests__/nonnull-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ describe('Execute: handles non-nullable types', () => {
errors: [
{
message:
'Argument "cannotBeNull" of required type "String!" was not provided.',
'Argument Query.withNonNullArg(cannotBeNull:) of required type String! was not provided.',
locations: [{ line: 3, column: 13 }],
path: ['withNonNullArg'],
},
Expand All @@ -647,7 +647,7 @@ describe('Execute: handles non-nullable types', () => {
errors: [
{
message:
'Argument "cannotBeNull" of non-null type "String!" must not be null.',
'Argument Query.withNonNullArg(cannotBeNull:) of non-null type String! must not be null.',
locations: [{ line: 3, column: 42 }],
path: ['withNonNullArg'],
},
Expand Down Expand Up @@ -677,7 +677,7 @@ describe('Execute: handles non-nullable types', () => {
errors: [
{
message:
'Argument "cannotBeNull" of required type "String!" was provided the variable "$testVar" which was not provided a runtime value.',
'Argument Query.withNonNullArg(cannotBeNull:) of required type String! was provided the variable "$testVar" which was not provided a runtime value.',
locations: [{ line: 3, column: 42 }],
path: ['withNonNullArg'],
},
Expand Down Expand Up @@ -705,7 +705,7 @@ describe('Execute: handles non-nullable types', () => {
errors: [
{
message:
'Argument "cannotBeNull" of non-null type "String!" must not be null.',
'Argument Query.withNonNullArg(cannotBeNull:) of non-null type String! must not be null.',
locations: [{ line: 3, column: 43 }],
path: ['withNonNullArg'],
},
Expand Down
21 changes: 11 additions & 10 deletions src/execution/__tests__/variables-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Argument "input" has invalid value ["foo", "bar", "baz"].',
'Argument TestType.fieldWithObjectInput(input:) of type TestInputObject has invalid value ["foo", "bar", "baz"].',
path: ['fieldWithObjectInput'],
locations: [{ line: 3, column: 41 }],
},
Expand Down Expand Up @@ -618,7 +618,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Variable "$value" of required type "String!" was not provided.',
'Variable "$value" of required type String! was not provided.',
locations: [{ line: 2, column: 16 }],
},
],
Expand All @@ -637,7 +637,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Variable "$value" of non-null type "String!" must not be null.',
'Variable "$value" of non-null type String! must not be null.',
locations: [{ line: 2, column: 16 }],
},
],
Expand Down Expand Up @@ -683,7 +683,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Argument "input" of required type "String!" was not provided.',
'Argument TestType.fieldWithNonNullableStringInput(input:) of required type String! was not provided.',
locations: [{ line: 1, column: 3 }],
path: ['fieldWithNonNullableStringInput'],
},
Expand Down Expand Up @@ -731,7 +731,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Argument "input" of required type "String!" was provided the variable "$foo" which was not provided a runtime value.',
'Argument TestType.fieldWithNonNullableStringInput(input:) of required type String! was provided the variable "$foo" which was not provided a runtime value.',
locations: [{ line: 3, column: 50 }],
path: ['fieldWithNonNullableStringInput'],
},
Expand Down Expand Up @@ -786,7 +786,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Variable "$input" of non-null type "[String]!" must not be null.',
'Variable "$input" of non-null type [String]! must not be null.',
locations: [{ line: 2, column: 16 }],
},
],
Expand Down Expand Up @@ -868,7 +868,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Variable "$input" of non-null type "[String!]!" must not be null.',
'Variable "$input" of non-null type [String!]! must not be null.',
locations: [{ line: 2, column: 16 }],
},
],
Expand Down Expand Up @@ -917,7 +917,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Variable "$input" expected value of type "TestType!" which cannot be used as an input type.',
'Variable "$input" expected value of type TestType! which cannot be used as an input type.',
locations: [{ line: 2, column: 24 }],
},
],
Expand All @@ -936,7 +936,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Variable "$input" expected value of type "UnknownType!" which cannot be used as an input type.',
'Variable "$input" expected value of type UnknownType! which cannot be used as an input type.',
locations: [{ line: 2, column: 24 }],
},
],
Expand Down Expand Up @@ -982,7 +982,8 @@ describe('Execute: Handles inputs', () => {
},
errors: [
{
message: 'Argument "input" has invalid value WRONG_TYPE.',
message:
'Argument TestType.fieldWithDefaultArgumentValue(input:) of type String has invalid value WRONG_TYPE.',
locations: [{ line: 3, column: 48 }],
path: ['fieldWithDefaultArgumentValue'],
},
Expand Down
20 changes: 9 additions & 11 deletions src/execution/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function coerceVariableValues(
const varTypeStr = print(varDefNode.type);
onError(
new GraphQLError(
`Variable "$${varName}" expected value of type "${varTypeStr}" which cannot be used as an input type.`,
`Variable "$${varName}" expected value of type ${varTypeStr} which cannot be used as an input type.`,
{ nodes: varDefNode.type },
),
);
Expand All @@ -96,10 +96,9 @@ function coerceVariableValues(
if (varDefNode.defaultValue) {
coercedValues[varName] = valueFromAST(varDefNode.defaultValue, varType);
} else if (isNonNullType(varType)) {
const varTypeStr = inspect(varType);
onError(
new GraphQLError(
`Variable "$${varName}" of required type "${varTypeStr}" was not provided.`,
`Variable "$${varName}" of required type ${varType} was not provided.`,
{ nodes: varDefNode },
),
);
Expand All @@ -109,10 +108,9 @@ function coerceVariableValues(

const value = inputs[varName];
if (value === null && isNonNullType(varType)) {
const varTypeStr = inspect(varType);
onError(
new GraphQLError(
`Variable "$${varName}" of non-null type "${varTypeStr}" must not be null.`,
`Variable "$${varName}" of non-null type ${varType} must not be null.`,
{ nodes: varDefNode },
),
);
Expand Down Expand Up @@ -171,8 +169,7 @@ export function getArgumentValues(
coercedValues[name] = argDef.defaultValue;
} else if (isNonNullType(argType)) {
throw new GraphQLError(
`Argument "${name}" of required type "${inspect(argType)}" ` +
'was not provided.',
`Argument ${argDef} of required type ${argType} was not provided.`,
{ nodes: node },
);
}
Expand All @@ -192,7 +189,7 @@ export function getArgumentValues(
coercedValues[name] = argDef.defaultValue;
} else if (isNonNullType(argType)) {
throw new GraphQLError(
`Argument "${name}" of required type "${inspect(argType)}" ` +
`Argument ${argDef} of required type ${argType} ` +
`was provided the variable "$${variableName}" which was not provided a runtime value.`,
{ nodes: valueNode },
);
Expand All @@ -204,8 +201,7 @@ export function getArgumentValues(

if (isNull && isNonNullType(argType)) {
throw new GraphQLError(
`Argument "${name}" of non-null type "${inspect(argType)}" ` +
'must not be null.',
`Argument ${argDef} of non-null type ${argType} must not be null.`,
{ nodes: valueNode },
);
}
Expand All @@ -216,7 +212,9 @@ export function getArgumentValues(
// execution. This is a runtime check to ensure execution does not
// continue with an invalid argument value.
throw new GraphQLError(
`Argument "${name}" has invalid value ${print(valueNode)}.`,
`Argument ${argDef} of type ${argType} has invalid value ${print(
valueNode,
)}.`,
{ nodes: valueNode },
);
}
Expand Down
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,17 @@ export {
// Definitions
GraphQLSchema,
GraphQLDirective,
GraphQLSchemaElement,
GraphQLScalarType,
GraphQLObjectType,
GraphQLInterfaceType,
GraphQLUnionType,
GraphQLEnumType,
GraphQLInputObjectType,
GraphQLField,
GraphQLArgument,
GraphQLEnumValue,
GraphQLInputField,
GraphQLList,
GraphQLNonNull,
// Standard GraphQL Scalars
Expand Down Expand Up @@ -160,23 +165,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
Loading

0 comments on commit cc309b6

Please sign in to comment.