UNPKG

1.24 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 * This transform finds MatchBranch nodes and adds a SplitOperation root
14 * node to the context for each of them.
15 */
16function relaySplitMatchTransform(context) {
17 var splitOperations = new Map();
18
19 var transformedContext = require("./GraphQLIRTransformer").transform(context, {
20 MatchBranch: visitMatchBranch
21 }, function () {
22 return splitOperations;
23 });
24
25 return transformedContext.addAll(Array.from(splitOperations.values()));
26}
27
28function visitMatchBranch(node, state) {
29 var transformedNode = this.traverse(node, state);
30 var splitOperation = {
31 kind: 'SplitOperation',
32 name: require("./getNormalizationOperationName")(transformedNode.name),
33 selections: transformedNode.selections,
34 loc: {
35 kind: 'Derived',
36 source: node.loc
37 },
38 metadata: {
39 derivedFrom: transformedNode.name
40 },
41 type: transformedNode.type
42 };
43 state.set(node.name, splitOperation);
44 return transformedNode;
45}
46
47module.exports = {
48 transform: relaySplitMatchTransform
49};
\No newline at end of file