-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.proof.ts
More file actions
87 lines (78 loc) · 1.87 KB
/
types.proof.ts
File metadata and controls
87 lines (78 loc) · 1.87 KB
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
import { describe, equal, expect, it } from 'typroof';
import { enumOf, infer, scalar, schema } from './types';
import type { GraphQLEnum, GraphQLScalar } from './types/graphql-types';
let $: {
User: {
id: 'Int!';
username: 'String!';
email: 'String';
createdAt: 'DateTime!';
};
Post: {
id: 'Int!';
status: 'PostStatus!';
title: 'String!';
content: 'String!';
author: 'User!';
};
PostStatus: GraphQLEnum<'DRAFT' | 'PUBLISHED' | 'ARCHIVED'>;
DateTime: GraphQLScalar<string, Date>;
Query: {
users: ['=>', '[User!]!'];
post: [{ id: 'Int!' }, '=>', 'Post'];
};
};
describe('schema', () => {
it('should validate a GraphQL schema', () => {
const _ = schema({
User: {
id: 'Int!',
username: 'String!',
email: 'String',
createdAt: 'DateTime!',
},
Post: {
id: 'Int!',
status: 'PostStatus!',
title: 'String!',
content: 'String!',
author: 'User!',
},
PostStatus: enumOf('DRAFT', 'PUBLISHED', 'ARCHIVED'),
DateTime: scalar<string>()({
parse: (value) => new Date(value),
serialize: (value) => value.toISOString(),
}),
Query: {
users: ['=>', '[User!]!'],
post: [{ id: 'Int!' }, '=>', 'Post'],
},
});
expect(_).to(equal<typeof $>);
$ = _;
});
});
describe('compile', () => {
it('should infer the type of a GraphQL schema', () => {
const $$ = infer($);
type User = typeof $$.User;
expect<User>().to(
equal<{
id: number;
username: string;
email: string | null;
createdAt: Date;
}>(),
);
type Post = typeof $$.Post;
expect<Post>().to(
equal<{
id: number;
status: 'DRAFT' | 'PUBLISHED' | 'ARCHIVED';
title: string;
content: string;
author: User;
}>(),
);
});
});