1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
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 | function skipClientFieldTransform(context) {
|
64 | return require("./GraphQLIRTransformer").transform(context, {
|
65 | FragmentSpread: visitFragmentSpread,
|
66 | InlineFragment: visitInlineFragment,
|
67 | LinkedField: visitField,
|
68 | MatchField: visitField,
|
69 | ScalarField: visitField
|
70 | }, function (node) {
|
71 | return buildState(context, node);
|
72 | });
|
73 | }
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | function buildState(context, node) {
|
83 | var schema = context.serverSchema;
|
84 |
|
85 | switch (node.kind) {
|
86 | case 'Fragment':
|
87 | return schema.getType(node.type.name);
|
88 |
|
89 | case 'Root':
|
90 | switch (node.operation) {
|
91 | case 'query':
|
92 | return schema.getQueryType();
|
93 |
|
94 | case 'mutation':
|
95 | return schema.getMutationType();
|
96 |
|
97 | case 'subscription':
|
98 | return schema.getSubscriptionType();
|
99 |
|
100 | default:
|
101 | node.operation;
|
102 | }
|
103 |
|
104 | break;
|
105 |
|
106 | case 'SplitOperation':
|
107 | return schema.getType(node.type.name);
|
108 |
|
109 | default:
|
110 | node;
|
111 | }
|
112 |
|
113 | return null;
|
114 | }
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | function visitField(field, parentType) {
|
123 | if (
|
124 | require("./GraphQLSchemaUtils").canHaveSelections(parentType) && require("./GraphQLSchemaUtils").assertTypeWithFields(parentType).getFields()[field.name] ||
|
125 | field.name === require("graphql").SchemaMetaFieldDef.name || field.name === require("graphql").TypeMetaFieldDef.name || field.name === require("graphql").TypeNameMetaFieldDef.name || field.directives.some(function (_ref) {
|
126 | var name = _ref.name;
|
127 | return name === 'fixme_fat_interface';
|
128 | })) {
|
129 | var rawType = require("./GraphQLSchemaUtils").getRawType(field.type);
|
130 |
|
131 | var type = this.getContext().serverSchema.getType(rawType.name);
|
132 | !type ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'SkipClientFieldTransform: Expected type `%s` to be defined in ' + 'the server schema.', rawType.name) : require("fbjs/lib/invariant")(false) : void 0;
|
133 | return this.traverse(field, type);
|
134 | }
|
135 |
|
136 | return null;
|
137 | }
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 | function visitFragmentSpread(spread, parentType) {
|
147 | var context = this.getContext();
|
148 | var fragment = context.getFragment(spread.name);
|
149 |
|
150 | if (context.serverSchema.getType(fragment.type.name)) {
|
151 | return this.traverse(spread, parentType);
|
152 | }
|
153 |
|
154 | return null;
|
155 | }
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | function visitInlineFragment(fragment, parentType) {
|
164 | var schema = this.getContext().serverSchema;
|
165 | var type = schema.getType(fragment.typeCondition.name);
|
166 |
|
167 | if (type) {
|
168 | return this.traverse(fragment, type);
|
169 | }
|
170 |
|
171 | return null;
|
172 | }
|
173 |
|
174 | module.exports = {
|
175 | transform: skipClientFieldTransform
|
176 | }; |
\ | No newline at end of file |