UNPKG

2.67 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3function queryFromPojo(obj) {
4 var op = {
5 kind: 'OperationDefinition',
6 operation: 'query',
7 name: {
8 kind: 'Name',
9 value: 'GeneratedClientQuery',
10 },
11 selectionSet: selectionSetFromObj(obj),
12 };
13 var out = {
14 kind: 'Document',
15 definitions: [op],
16 };
17 return out;
18}
19exports.queryFromPojo = queryFromPojo;
20function fragmentFromPojo(obj, typename) {
21 var frag = {
22 kind: 'FragmentDefinition',
23 typeCondition: {
24 kind: 'NamedType',
25 name: {
26 kind: 'Name',
27 value: typename || '__FakeType',
28 },
29 },
30 name: {
31 kind: 'Name',
32 value: 'GeneratedClientQuery',
33 },
34 selectionSet: selectionSetFromObj(obj),
35 };
36 var out = {
37 kind: 'Document',
38 definitions: [frag],
39 };
40 return out;
41}
42exports.fragmentFromPojo = fragmentFromPojo;
43function selectionSetFromObj(obj) {
44 if (typeof obj === 'number' ||
45 typeof obj === 'boolean' ||
46 typeof obj === 'string' ||
47 typeof obj === 'undefined' ||
48 obj === null) {
49 return null;
50 }
51 if (Array.isArray(obj)) {
52 return selectionSetFromObj(obj[0]);
53 }
54 var selections = [];
55 Object.keys(obj).forEach(function (key) {
56 var nestedSelSet = selectionSetFromObj(obj[key]);
57 var field = {
58 kind: 'Field',
59 name: {
60 kind: 'Name',
61 value: key,
62 },
63 selectionSet: nestedSelSet || undefined,
64 };
65 selections.push(field);
66 });
67 var selectionSet = {
68 kind: 'SelectionSet',
69 selections: selections,
70 };
71 return selectionSet;
72}
73exports.justTypenameQuery = {
74 kind: 'Document',
75 definitions: [
76 {
77 kind: 'OperationDefinition',
78 operation: 'query',
79 name: null,
80 variableDefinitions: null,
81 directives: [],
82 selectionSet: {
83 kind: 'SelectionSet',
84 selections: [
85 {
86 kind: 'Field',
87 alias: null,
88 name: {
89 kind: 'Name',
90 value: '__typename',
91 },
92 arguments: [],
93 directives: [],
94 selectionSet: null,
95 },
96 ],
97 },
98 },
99 ],
100};
101//# sourceMappingURL=utils.js.map
\No newline at end of file