forked from timqian/gql-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
root.handlebars
95 lines (90 loc) · 3.2 KB
/
root.handlebars
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
/* eslint-disable */
// This is autogenerated file, please DO NOT EDIT!!
//
//
import {ApolloClient} from "apollo-client";
import {NormalizedCacheObject} from "apollo-cache-inmemory";
import { ApolloQueryResult } from "apollo-client/core/types";
import { FetchResult } from 'apollo-link';
import {
{{#each queries}}
{{toUpperCase name}}Query,
{{#if hasVariables}}{{toUpperCase name}}QueryVariables,{{/if}}
{{/each}}
{{#each mutations}}
{{toUpperCase name}}Mutation,
{{#if hasVariables}}{{toUpperCase name}}MutationVariables,{{/if}}
{{/each}}
} from "{{pathToTypes}}";
{{#each subscriptions}}
import {
{{name}},
{{#if hasVariables}}{{name}}Variables{{/if}}
} from "./{{name}}";
{{/each}}
{{#if mutations.length }}
import * as mutations from "./mutations";
{{/if}}
{{#if queries.length}}
import * as queries from "./queries";
{{/if}}
{{#if subscriptions.length}}
import * as subscriptions from "./subscriptions";
{{/if}}
export const getOperations = (passedClient: ApolloClient<NormalizedCacheObject>) => ({
mutations: {
{{#each mutations}}
{{name}}: async {{#if hasVariables}}(variables: {{toUpperCase name}}MutationVariables){{else}}(){{/if}} => {
let result: FetchResult<{{toUpperCase name}}Mutation>
const prepareError = new Error("");
const splitLines = prepareError.stack.split("\n").slice(2);
try {
result = await passedClient.mutate<{{toUpperCase name}}Mutation{{#if hasVariables}}, {{toUpperCase name}}MutationVariables{{/if}}>({
mutation: mutations.{{name}}{{#if hasVariables}},
variables{{/if}}
})
} catch (e) {
const smallStack = e.stack.split("\n");
e.stack = [...smallStack, ...splitLines]
.filter((l) => l.indexOf("node_modules") === -1)
.join("\n");
e.message = e.message.split("\n")[0];
throw e;
}
return result.data.{{name}}
},
{{/each}}
},
queries: {
{{#each queries}}
{{name}}: async {{#if hasVariables}}(variables: {{toUpperCase name}}QueryVariables){{else}}(){{/if}} => {
let result: ApolloQueryResult<{{toUpperCase name}}Query>;
const prepareError = new Error("");
const splitLines = prepareError.stack.split("\n").slice(2);
try {
result = await passedClient.query<{{toUpperCase name}}Query{{#if hasVariables}}, {{toUpperCase name}}QueryVariables{{/if}}>({
query: queries.{{name}}{{#if hasVariables}},
variables{{/if}}
})
} catch (e) {
const smallStack = e.stack.split("\n");
e.stack = [...smallStack, ...splitLines]
.filter((l) => l.indexOf("node_modules") === -1)
.join("\n");
e.message = e.message.split("\n")[0];
throw e;
}
return result.data.{{name}}
},
{{/each}}
},
subscriptions: {
{{#each subscriptions}}
{{name}}: {{#if hasVariables}}(variables: {{toUpperCase name}}SubscriptionVariables){{else}}(){{/if}} =>
passedClient.subscribe<{{name}}Subscription{{#if hasVariables}}, {{name}}SubscriptionVariables{{/if}}>({
query: subscriptions.{{name}}{{#if hasVariables}},
variables{{/if}}
}),
{{/each}}
}
});