Skip to content

Commit 2d060bc

Browse files
introduce GraphQLField, GraphQLInputField, GraphQLArgument, and GraphQLEnumValue (graphql#4288)
this extracts logic from graphql#3044 and graphql#3145 (later rebased as graphql#3807 and [the full schema coordinate RFC](graphql/graphql-spec#794) This is a BREAKING CHANGE because these schema elements are now longer plain objects and function differently in various scenarios, for example with `String(<schemaElement>` `JSON.stringifu(<schemaElement>` and `.toString()` and `.toJSON()` --------- Co-authored-by: Jovi De Croock <[email protected]>
1 parent dd6712e commit 2d060bc

22 files changed

+766
-539
lines changed

src/execution/__tests__/nonnull-test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ describe('Execute: handles non-nullable types', () => {
683683
errors: [
684684
{
685685
message:
686-
'Argument "cannotBeNull" of required type "String!" was not provided.',
686+
'Argument "Query.withNonNullArg(cannotBeNull:)" of required type "String!" was not provided.',
687687
locations: [{ line: 3, column: 13 }],
688688
path: ['withNonNullArg'],
689689
},
@@ -710,7 +710,7 @@ describe('Execute: handles non-nullable types', () => {
710710
errors: [
711711
{
712712
message:
713-
'Argument "cannotBeNull" has invalid value: Expected value of non-null type "String!" not to be null.',
713+
'Argument "Query.withNonNullArg(cannotBeNull:)" has invalid value: Expected value of non-null type "String!" not to be null.',
714714
locations: [{ line: 3, column: 42 }],
715715
path: ['withNonNullArg'],
716716
},
@@ -740,7 +740,7 @@ describe('Execute: handles non-nullable types', () => {
740740
errors: [
741741
{
742742
message:
743-
'Argument "cannotBeNull" has invalid value: Expected variable "$testVar" provided to type "String!" to provide a runtime value.',
743+
'Argument "Query.withNonNullArg(cannotBeNull:)" has invalid value: Expected variable "$testVar" provided to type "String!" to provide a runtime value.',
744744
locations: [{ line: 3, column: 42 }],
745745
path: ['withNonNullArg'],
746746
},
@@ -768,7 +768,7 @@ describe('Execute: handles non-nullable types', () => {
768768
errors: [
769769
{
770770
message:
771-
'Argument "cannotBeNull" has invalid value: Expected variable "$testVar" provided to non-null type "String!" not to be null.',
771+
'Argument "Query.withNonNullArg(cannotBeNull:)" has invalid value: Expected variable "$testVar" provided to non-null type "String!" not to be null.',
772772
locations: [{ line: 3, column: 43 }],
773773
path: ['withNonNullArg'],
774774
},

src/execution/__tests__/oneof-test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
8888
message:
8989
// This type of error would be caught at validation-time
9090
// hence the vague error message here.
91-
'Argument "input" has invalid value: Expected variable "$input" provided to type "TestInputObject!" to provide a runtime value.',
91+
'Argument "Query.test(input:)" has invalid value: Expected variable "$input" provided to type "TestInputObject!" to provide a runtime value.',
9292
path: ['test'],
9393
},
9494
],
@@ -229,7 +229,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
229229
// A nullable variable in a oneOf field position would be caught at validation-time
230230
// hence the vague error message here.
231231
message:
232-
'Argument "input" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" not to be null.',
232+
'Argument "Query.test(input:)" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" not to be null.',
233233
locations: [{ line: 3, column: 23 }],
234234
path: ['test'],
235235
},
@@ -257,7 +257,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
257257
// A nullable variable in a oneOf field position would be caught at validation-time
258258
// hence the vague error message here.
259259
message:
260-
'Argument "input" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" to provide a runtime value.',
260+
'Argument "Query.test(input:)" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" to provide a runtime value.',
261261
locations: [{ line: 3, column: 23 }],
262262
path: ['test'],
263263
},
@@ -288,7 +288,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
288288
// A nullable variable in a oneOf field position would be caught at validation-time
289289
// hence the vague error message here.
290290
message:
291-
'Argument "input" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" not to be null.',
291+
'Argument "Query.test(input:)" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" not to be null.',
292292
locations: [{ line: 6, column: 23 }],
293293
path: ['test'],
294294
},
@@ -319,7 +319,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
319319
// A nullable variable in a oneOf field position would be caught at validation-time
320320
// hence the vague error message here.
321321
message:
322-
'Argument "input" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" to provide a runtime value.',
322+
'Argument "Query.test(input:)" has invalid value: Expected variable "$a" provided to field "a" for OneOf Input Object type "TestInputObject" to provide a runtime value.',
323323
locations: [{ line: 6, column: 23 }],
324324
path: ['test'],
325325
},

src/execution/__tests__/variables-test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ describe('Execute: Handles inputs', () => {
284284
errors: [
285285
{
286286
message:
287-
'Argument "input" has invalid value: Expected value of type "TestInputObject" to be an object, found: ["foo", "bar", "baz"].',
287+
'Argument "TestType.fieldWithObjectInput(input:)" has invalid value: Expected value of type "TestInputObject" to be an object, found: ["foo", "bar", "baz"].',
288288
path: ['fieldWithObjectInput'],
289289
locations: [{ line: 3, column: 41 }],
290290
},
@@ -321,7 +321,7 @@ describe('Execute: Handles inputs', () => {
321321
errors: [
322322
{
323323
message:
324-
'Argument "input" has invalid value at .e: FaultyScalarErrorMessage',
324+
'Argument "TestType.fieldWithObjectInput(input:)" has invalid value at .e: FaultyScalarErrorMessage',
325325
path: ['fieldWithObjectInput'],
326326
locations: [{ line: 3, column: 11 }],
327327
extensions: { code: 'FaultyScalarErrorMessageExtensionCode' },
@@ -477,7 +477,7 @@ describe('Execute: Handles inputs', () => {
477477
errors: [
478478
{
479479
message:
480-
'Variable "$input" has invalid value at .e: Argument "input" has invalid value at .e: FaultyScalarErrorMessage',
480+
'Variable "$input" has invalid value at .e: Argument "TestType.fieldWithObjectInput(input:)" has invalid value at .e: FaultyScalarErrorMessage',
481481
locations: [{ line: 2, column: 16 }],
482482
extensions: { code: 'FaultyScalarErrorMessageExtensionCode' },
483483
},
@@ -802,7 +802,7 @@ describe('Execute: Handles inputs', () => {
802802
errors: [
803803
{
804804
message:
805-
'Argument "input" of required type "String!" was not provided.',
805+
'Argument "TestType.fieldWithNonNullableStringInput(input:)" of required type "String!" was not provided.',
806806
locations: [{ line: 1, column: 3 }],
807807
path: ['fieldWithNonNullableStringInput'],
808808
},
@@ -850,7 +850,7 @@ describe('Execute: Handles inputs', () => {
850850
errors: [
851851
{
852852
message:
853-
'Argument "input" has invalid value: Expected variable "$foo" provided to type "String!" to provide a runtime value.',
853+
'Argument "TestType.fieldWithNonNullableStringInput(input:)" has invalid value: Expected variable "$foo" provided to type "String!" to provide a runtime value.',
854854
locations: [{ line: 3, column: 50 }],
855855
path: ['fieldWithNonNullableStringInput'],
856856
},
@@ -1102,7 +1102,7 @@ describe('Execute: Handles inputs', () => {
11021102
errors: [
11031103
{
11041104
message:
1105-
'Argument "input" has invalid value: String cannot represent a non string value: WRONG_TYPE',
1105+
'Argument "TestType.fieldWithDefaultArgumentValue(input:)" has invalid value: String cannot represent a non string value: WRONG_TYPE',
11061106
locations: [{ line: 3, column: 48 }],
11071107
path: ['fieldWithDefaultArgumentValue'],
11081108
},

src/execution/values.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import type {
1414
import { Kind } from '../language/kinds.js';
1515

1616
import type { GraphQLArgument, GraphQLField } from '../type/definition.js';
17-
import { isNonNullType, isRequiredArgument } from '../type/definition.js';
17+
import {
18+
isArgument,
19+
isNonNullType,
20+
isRequiredArgument,
21+
} from '../type/definition.js';
1822
import type { GraphQLDirective } from '../type/directives.js';
1923
import type { GraphQLSchema } from '../type/schema.js';
2024

@@ -222,7 +226,8 @@ export function experimentalGetArgumentValues(
222226
// execution. This is a runtime check to ensure execution does not
223227
// continue with an invalid argument value.
224228
throw new GraphQLError(
225-
`Argument "${argDef.name}" of required type "${argType}" was not provided.`,
229+
// TODO: clean up the naming of isRequiredArgument(), isArgument(), and argDef if/when experimental fragment variables are merged
230+
`Argument "${isArgument(argDef) ? argDef : argDef.name}" of required type "${argType}" was not provided.`,
226231
{ nodes: node },
227232
);
228233
}
@@ -272,7 +277,8 @@ export function experimentalGetArgumentValues(
272277
valueNode,
273278
argType,
274279
(error, path) => {
275-
error.message = `Argument "${argDef.name}" has invalid value${printPathArray(
280+
// TODO: clean up the naming of isRequiredArgument(), isArgument(), and argDef if/when experimental fragment variables are merged
281+
error.message = `Argument "${isArgument(argDef) ? argDef : argDef.name}" has invalid value${printPathArray(
276282
path,
277283
)}: ${error.message}`;
278284
throw error;

src/index.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ 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';
3743
export {
3844
resolveObjMapThunk,
3945
resolveReadonlyArrayThunk,
@@ -89,10 +95,14 @@ export {
8995
isType,
9096
isScalarType,
9197
isObjectType,
98+
isField,
99+
isArgument,
92100
isInterfaceType,
93101
isUnionType,
94102
isEnumType,
103+
isEnumValue,
95104
isInputObjectType,
105+
isInputField,
96106
isListType,
97107
isNonNullType,
98108
isInputType,
@@ -114,10 +124,14 @@ export {
114124
assertType,
115125
assertScalarType,
116126
assertObjectType,
127+
assertField,
128+
assertArgument,
117129
assertInterfaceType,
118130
assertUnionType,
119131
assertEnumType,
132+
assertEnumValue,
120133
assertInputObjectType,
134+
assertInputField,
121135
assertListType,
122136
assertNonNullType,
123137
assertInputType,
@@ -159,23 +173,19 @@ export type {
159173
GraphQLSchemaExtensions,
160174
GraphQLDirectiveConfig,
161175
GraphQLDirectiveExtensions,
162-
GraphQLArgument,
163176
GraphQLArgumentConfig,
164177
GraphQLArgumentExtensions,
165178
GraphQLEnumTypeConfig,
166179
GraphQLEnumTypeExtensions,
167-
GraphQLEnumValue,
168180
GraphQLEnumValueConfig,
169181
GraphQLEnumValueConfigMap,
170182
GraphQLEnumValueExtensions,
171-
GraphQLField,
172183
GraphQLFieldConfig,
173184
GraphQLFieldConfigArgumentMap,
174185
GraphQLFieldConfigMap,
175186
GraphQLFieldExtensions,
176187
GraphQLFieldMap,
177188
GraphQLFieldResolver,
178-
GraphQLInputField,
179189
GraphQLInputFieldConfig,
180190
GraphQLInputFieldConfigMap,
181191
GraphQLInputFieldExtensions,

0 commit comments

Comments
 (0)