UNPKG

1.36 kBJavaScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * strict-local
8 * @format
9 */
10'use strict';
11
12/**
13 * A transform that inlines all fragments and removes them.
14 */
15function inlineFragmentsTransform(context) {
16 return require("./GraphQLIRTransformer").transform(context, {
17 Fragment: visitFragment,
18 FragmentSpread: visitFragmentSpread
19 });
20}
21
22function visitFragment(fragment) {
23 return null;
24}
25
26function visitFragmentSpread(fragmentSpread) {
27 !(fragmentSpread.args.length === 0) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'InlineFragmentsTransform: Cannot flatten fragment spread `%s` with ' + 'arguments. Use the `ApplyFragmentArgumentTransform` before flattening', fragmentSpread.name) : require("fbjs/lib/invariant")(false) : void 0;
28 var fragment = this.getContext().getFragment(fragmentSpread.name);
29 var result = {
30 kind: 'InlineFragment',
31 directives: fragmentSpread.directives,
32 loc: {
33 kind: 'Derived',
34 source: fragmentSpread.loc
35 },
36 metadata: fragmentSpread.metadata,
37 selections: fragment.selections,
38 typeCondition: fragment.type
39 };
40 return this.traverse(result);
41}
42
43module.exports = {
44 transform: inlineFragmentsTransform
45};
\No newline at end of file