Skip to content

Commit cfc68cd

Browse files
committed
Address PR feedback
1 parent 84a87ee commit cfc68cd

File tree

6 files changed

+48
-43
lines changed

6 files changed

+48
-43
lines changed

src/__testUtils__/kitchenSinkSDL.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Foo implements Bar & Baz & Two {
2727
five(argument: [String] = ["string", "string"]): String
2828
six(argument: InputType = {key: "value"}): Type
2929
seven(argument: Int = null): Type
30+
eight(argument: OneOfInputType): Type
3031
}
3132
3233
type AnnotatedObject @onObject(arg: "value") {
@@ -116,6 +117,11 @@ input InputType {
116117
answer: Int = 42
117118
}
118119
120+
input OneOfInputType @oneOf {
121+
string: String
122+
int: Int
123+
}
124+
119125
input AnnotatedInput @onInputObject {
120126
annotatedField: Type @onInputFieldDefinition
121127
}

src/execution/__tests__/oneof-test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ const schema = buildSchema(`
2323
a: String
2424
b: Int
2525
}
26-
27-
schema {
28-
query: Query
29-
}
3026
`);
3127

3228
function executeQuery(
@@ -85,6 +81,8 @@ describe('Execute: Handles OneOf Input Objects', () => {
8581
{
8682
locations: [{ column: 23, line: 3 }],
8783
message:
84+
// This type of error would be caught at validation-time
85+
// hence the vague error message here.
8886
'Argument "input" of non-null type "TestInputObject!" must not be null.',
8987
path: ['test'],
9088
},
@@ -154,7 +152,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
154152
{
155153
locations: [{ column: 16, line: 2 }],
156154
message:
157-
'Variable "$input" got invalid value { a: "abc", b: 123 }; Exactly one key must be specified.',
155+
'Variable "$input" got invalid value { a: "abc", b: 123 }; Exactly one key must be specified for OneOf type "TestInputObject".',
158156
},
159157
],
160158
});
@@ -178,7 +176,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
178176
{
179177
locations: [{ column: 16, line: 2 }],
180178
message:
181-
'Variable "$input" got invalid value { a: "abc", b: null }; Exactly one key must be specified.',
179+
'Variable "$input" got invalid value { a: "abc", b: null }; Exactly one key must be specified for OneOf type "TestInputObject".',
182180
},
183181
],
184182
});

src/language/__tests__/schema-printer-test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ describe('Printer: SDL document', () => {
6161
five(argument: [String] = ["string", "string"]): String
6262
six(argument: InputType = { key: "value" }): Type
6363
seven(argument: Int = null): Type
64+
eight(argument: OneOfInputType): Type
6465
}
6566
6667
type AnnotatedObject @onObject(arg: "value") {
@@ -143,6 +144,11 @@ describe('Printer: SDL document', () => {
143144
answer: Int = 42
144145
}
145146
147+
input OneOfInputType @oneOf {
148+
string: String
149+
int: Int
150+
}
151+
146152
input AnnotatedInput @onInputObject {
147153
annotatedField: Type @onInputFieldDefinition
148154
}

src/type/__tests__/introspection-test.ts

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,21 +1555,21 @@ describe('Introspection', () => {
15551555

15561556
const source = `
15571557
{
1558-
a: __type(name: "SomeInputObject") {
1558+
oneOfInputObject: __type(name: "SomeInputObject") {
15591559
isOneOf
15601560
}
1561-
b: __type(name: "AnotherInputObject") {
1561+
inputObject: __type(name: "AnotherInputObject") {
15621562
isOneOf
15631563
}
15641564
}
15651565
`;
15661566

15671567
expect(graphqlSync({ schema, source })).to.deep.equal({
15681568
data: {
1569-
a: {
1569+
oneOfInputObject: {
15701570
isOneOf: true,
15711571
},
1572-
b: {
1572+
inputObject: {
15731573
isOneOf: false,
15741574
},
15751575
},
@@ -1578,59 +1578,49 @@ describe('Introspection', () => {
15781578

15791579
it('returns null for oneOf for other types', () => {
15801580
const schema = buildSchema(`
1581-
type A implements I {
1582-
a: String
1581+
type SomeObject implements SomeInterface {
1582+
fieldA: String
15831583
}
1584-
enum E {
1585-
A
1584+
enum SomeEnum {
1585+
SomeObject
15861586
}
1587-
interface I {
1588-
a: String
1587+
interface SomeInterface {
1588+
fieldA: String
15891589
}
1590-
union U = A
1590+
union SomeUnion = SomeObject
15911591
type Query {
1592-
someField(e: E): U
1593-
anotherField(e: E): I
1592+
someField(enum: SomeEnum): SomeUnion
1593+
anotherField(enum: SomeEnum): SomeInterface
15941594
}
15951595
`);
15961596

15971597
const source = `
15981598
{
1599-
a: __type(name: "A") {
1599+
object: __type(name: "SomeObject") {
16001600
isOneOf
16011601
}
1602-
e: __type(name: "E") {
1602+
enum: __type(name: "SomeEnum") {
16031603
isOneOf
16041604
}
1605-
i: __type(name: "I") {
1605+
interface: __type(name: "SomeInterface") {
16061606
isOneOf
16071607
}
1608-
o: __type(name: "String") {
1608+
scalar: __type(name: "String") {
16091609
isOneOf
16101610
}
1611-
u: __type(name: "U") {
1611+
union: __type(name: "SomeUnion") {
16121612
isOneOf
16131613
}
16141614
}
16151615
`;
16161616

16171617
expect(graphqlSync({ schema, source })).to.deep.equal({
16181618
data: {
1619-
a: {
1620-
isOneOf: null,
1621-
},
1622-
e: {
1623-
isOneOf: null,
1624-
},
1625-
i: {
1626-
isOneOf: null,
1627-
},
1628-
o: {
1629-
isOneOf: null,
1630-
},
1631-
u: {
1632-
isOneOf: null,
1633-
},
1619+
object: { isOneOf: null },
1620+
enum: { isOneOf: null },
1621+
interface: { isOneOf: null },
1622+
scalar: { isOneOf: null },
1623+
union: { isOneOf: null },
16341624
},
16351625
});
16361626
});

src/utilities/__tests__/coerceInputValue-test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ describe('coerceInputValue', () => {
292292
const result = coerceValue({ foo: 123, bar: null }, TestInputObject);
293293
expectErrors(result).to.deep.equal([
294294
{
295-
error: 'Exactly one key must be specified.',
295+
error:
296+
'Exactly one key must be specified for OneOf type "TestInputObject".',
296297
path: [],
297298
value: { foo: 123, bar: null },
298299
},
@@ -335,7 +336,8 @@ describe('coerceInputValue', () => {
335336
value: 'def',
336337
},
337338
{
338-
error: 'Exactly one key must be specified.',
339+
error:
340+
'Exactly one key must be specified for OneOf type "TestInputObject".',
339341
path: [],
340342
value: { foo: 'abc', bar: 'def' },
341343
},
@@ -367,7 +369,8 @@ describe('coerceInputValue', () => {
367369
value: { bart: 123 },
368370
},
369371
{
370-
error: 'Exactly one key must be specified.',
372+
error:
373+
'Exactly one key must be specified for OneOf type "TestInputObject".',
371374
path: [],
372375
value: { bart: 123 },
373376
},

src/utilities/coerceInputValue.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ function coerceInputValueImpl(
149149
onError(
150150
pathToArray(path),
151151
inputValue,
152-
new GraphQLError('Exactly one key must be specified.'),
152+
new GraphQLError(
153+
`Exactly one key must be specified for OneOf type "${type.name}".`,
154+
),
153155
);
154156
}
155157

0 commit comments

Comments
 (0)