-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcheckGraphQLSchema.test.mjs
69 lines (63 loc) · 1.58 KB
/
checkGraphQLSchema.test.mjs
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
// @ts-check
import { doesNotThrow, throws } from "node:assert";
import {
GraphQLError,
GraphQLObjectType,
GraphQLSchema,
GraphQLString,
} from "graphql";
import checkGraphQLSchema from "./checkGraphQLSchema.mjs";
import GraphQLAggregateError from "./GraphQLAggregateError.mjs";
/**
* Adds `checkGraphQLSchema` tests.
* @param {import("test-director").default} tests Test director.
*/
export default (tests) => {
tests.add("`checkGraphQLSchema` with a valid GraphQL schema.", () => {
doesNotThrow(() =>
checkGraphQLSchema(
new GraphQLSchema({
query: new GraphQLObjectType({
name: "Query",
fields: {
test: {
type: GraphQLString,
},
},
}),
}),
"Test"
)
);
});
tests.add("`checkGraphQLSchema` with a non GraphQL schema.", () => {
throws(
() =>
checkGraphQLSchema(
// @ts-expect-error Testing invalid.
false,
"Test"
),
{
name: "InternalServerError",
message: "Test GraphQL schema must be a `GraphQLSchema` instance.",
status: 500,
expose: false,
}
);
});
tests.add(
"`checkGraphQLSchema` with GraphQL schema validation errors.",
() => {
throws(
() => checkGraphQLSchema(new GraphQLSchema({}), "Test"),
new GraphQLAggregateError(
[new GraphQLError("Query root type must be provided.")],
"Test has GraphQL schema validation errors.",
500,
false
)
);
}
);
};