-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathquestioned-spec-bug-test.ts
95 lines (78 loc) · 2.23 KB
/
questioned-spec-bug-test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { describe, it } from 'mocha';
import { expectJSON } from '../../__testUtils__/expectJSON.js';
import { parse } from '../../language/parser.js';
import type { GraphQLSchema } from '../../type/schema.js';
import { validateSchema } from '../../type/validate.js';
import { validate } from '../../validation/validate.js';
import { buildSchema } from '../../utilities/buildASTSchema.js';
import { execute } from '../execute.js';
async function executeQuery(args: {
schema: GraphQLSchema;
query: string;
rootValue?: unknown;
}) {
const { schema, query, rootValue } = args;
const document = parse(query);
return execute({
schema,
document,
rootValue,
});
}
describe('Execute: default arguments', () => {
it('handles interfaces with fields with default arguments', async () => {
const schema = buildSchema(`
type Query {
someInterface: SomeInterface
}
interface SomeInterface {
echo(value: String! = "default"): String
}
type SomeType implements SomeInterface {
echo(value: String!): String
}
`);
const query = `
{
someInterface {
... on SomeType {
echo
}
echo
}
}
`;
const schemaErrors = validateSchema(schema);
expectJSON(schemaErrors).toDeepEqual([]);
const queryErrors = validate(schema, parse(query));
expectJSON(queryErrors).toDeepEqual([
{
// This fails validation only for the object, but passes for the interface.
message:
'Argument "SomeType.echo(value:)" of type "String!" is required, but it was not provided.',
locations: [{ line: 5, column: 13 }],
},
]);
const rootValue = {
someInterface: {
__typename: 'SomeType',
echo: 'Runtime error raised, not called!',
},
};
expectJSON(await executeQuery({ schema, query, rootValue })).toDeepEqual({
data: {
someInterface: {
echo: null,
},
},
errors: [
{
message:
'Argument "value" of required type "String!" was not provided.',
path: ['someInterface', 'echo'],
locations: [{ line: 5, column: 13 }],
},
],
});
});
});