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 May 31, 2023
1 parent e5ad1de commit 4dbc894
Show file tree
Hide file tree
Showing 26 changed files with 648 additions and 637 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
23 changes: 12 additions & 11 deletions src/execution/__tests__/variables-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,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 @@ -262,7 +262,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Argument "input" has invalid value { c: "foo", e: "bar" }.',
'Argument TestType.fieldWithObjectInput(input:) of type TestInputObject has invalid value { c: "foo", e: "bar" }.',
path: ['fieldWithObjectInput'],
locations: [{ line: 3, column: 41 }],
},
Expand Down Expand Up @@ -678,7 +678,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 @@ -697,7 +697,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 @@ -743,7 +743,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 @@ -791,7 +791,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 @@ -846,7 +846,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 @@ -928,7 +928,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 @@ -977,7 +977,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 @@ -996,7 +996,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 @@ -1042,7 +1042,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 @@ -84,7 +84,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 @@ -95,10 +95,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 @@ -108,10 +107,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 @@ -170,8 +168,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 @@ -191,7 +188,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 @@ -203,8 +200,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 @@ -215,7 +211,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 4dbc894

Please sign in to comment.