-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.ts
100 lines (83 loc) · 2.62 KB
/
client.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
96
97
98
99
100
import { types, client } from './isomorphic-ts-gql';
//////////////////////////////
// Shared Code //
//////////////////////////////
const { scalar: { String }, makeObject, makeSchema, makeEnum, Maybe, List, enumValues } = types;
const HelloWorld2 = makeObject('HelloWorld', () => ({
anotherTwo2: List(String),
anotherFive: [
"",
Maybe(List(MyType)).withArgs({})
],
nestedOb3: NestedObj.withArgs({})
}));
const NestedObj = makeObject('NestedObj', () => ({
str: String.withArgs({})
}));
const MyType = makeEnum('MyType', {
One4: [],
TWO22: [],
THEE3: [],
});
MyType.withDefault(MyType.values.TWO22)
// Describe is very cumbersome, just have an array instead? Downside is then people can't re-use descriptions for all fields with the same type.
// Actually someone could re-use the field description by saving the array as a variable. Another nice idea is that we use ttypescript for both
// using the compiler to emit the schema files, and for picking up the comments and getting them to be represented at runtime.
const Query = makeObject('Query', "", () => ({
/** An instance of ldkm */
test69: [
"My description",
HelloWorld2.withArgs({
/** hello world */
one33: [
"hello world",
Maybe(String).withDefault('default value')
],
/** hi */
arg44: [List(String)]
,
three: Maybe(String).withDefault(''),
four: MyType
})
],
nObj4: [NestedObj],
second: List(Maybe(String)).withArgs({})
}));
const Mutation = makeObject('Mutation', () => ({
testing: String
}))
const Schema = makeSchema({HelloWorld: HelloWorld2, Query, Mutation, MyType});
MyType.values.One4
//////////////////////////////
// Client Code //
//////////////////////////////
const { execute, query, mutation } = client.makeClient(Schema);
const result = execute(query
.test69({arg44: [], one33: "", three: "", four: MyType.values.One4})
.nestedOb3({})
//.str({})
.str({})
.$
.anotherFive({})
.anotherTwo2
.$
.second({})
.nObj4
.str({})
.$
.$);
async function main() {
const go = await result.then(t => t.test69)
}
result.then(t => t.test69.nestedOb3.__typename)
const thingy = enumValues(MyType).One4
const mutres = execute(mutation.$)
type Test<T extends boolean> = {
first: T;
second: T extends true ? true : false;
}
declare function hello<T extends boolean>(world: Test<T>): T;
const thingy2 = hello({
first: false,
second: false
})