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 | function getRootScope(definitions) {
|
30 | var scope = {};
|
31 | definitions.forEach(function (definition) {
|
32 | scope[definition.name] = {
|
33 | kind: 'Variable',
|
34 | metadata: null,
|
35 | variableName: definition.name,
|
36 | type: definition.type
|
37 | };
|
38 | });
|
39 | return scope;
|
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 | function getFragmentScope(definitions, args, parentScope, spread) {
|
86 | var argMap = new Map();
|
87 | args.forEach(function (arg) {
|
88 | if (arg.value.kind === 'Literal') {
|
89 | argMap.set(arg.name, arg.value);
|
90 | } else if (arg.value.kind === 'Variable') {
|
91 | argMap.set(arg.name, parentScope[arg.value.variableName]);
|
92 | }
|
93 | });
|
94 | var fragmentScope = {};
|
95 |
|
96 | var errors = require("./RelayCompilerError").eachWithErrors(definitions, function (definition) {
|
97 | if (definition.kind === 'RootArgumentDefinition') {
|
98 | if (argMap.has(definition.name)) {
|
99 | var _ref;
|
100 |
|
101 | var argNode = args.find(function (a) {
|
102 | return a.name === definition.name;
|
103 | });
|
104 | throw require("./RelayCompilerError").createUserError("Unexpected argument '".concat(definition.name, "' supplied to fragment '").concat(spread.name, "'. @arguments may only be provided for variables defined in the fragment's @argumentDefinitions."), [(_ref = argNode === null || argNode === void 0 ? void 0 : argNode.loc) !== null && _ref !== void 0 ? _ref : spread.loc]);
|
105 | }
|
106 |
|
107 | fragmentScope[definition.name] = {
|
108 | kind: 'Variable',
|
109 | metadata: null,
|
110 | variableName: definition.name,
|
111 | type: definition.type
|
112 | };
|
113 | } else {
|
114 | var arg = argMap.get(definition.name);
|
115 |
|
116 | if (arg == null || arg.kind === 'Literal' && arg.value == null) {
|
117 |
|
118 |
|
119 | if (definition.defaultValue == null && definition.type instanceof require("graphql").GraphQLNonNull) {
|
120 | var _ref2;
|
121 |
|
122 | var _argNode = args.find(function (a) {
|
123 | return a.name === definition.name;
|
124 | });
|
125 |
|
126 | throw require("./RelayCompilerError").createUserError("No value found for required argument '".concat(definition.name, ": ").concat(String(definition.type), "' on fragment '").concat(spread.name, "'."), [(_ref2 = _argNode === null || _argNode === void 0 ? void 0 : _argNode.loc) !== null && _ref2 !== void 0 ? _ref2 : spread.loc]);
|
127 | }
|
128 |
|
129 | fragmentScope[definition.name] = {
|
130 | kind: 'Literal',
|
131 | value: definition.defaultValue
|
132 | };
|
133 | } else {
|
134 |
|
135 | fragmentScope[definition.name] = arg;
|
136 | }
|
137 | }
|
138 | });
|
139 |
|
140 | if (errors != null && errors.length) {
|
141 | throw require("./RelayCompilerError").createCombinedError(errors);
|
142 | }
|
143 |
|
144 | return fragmentScope;
|
145 | }
|
146 |
|
147 | module.exports = {
|
148 | getFragmentScope: getFragmentScope,
|
149 | getRootScope: getRootScope
|
150 | }; |
\ | No newline at end of file |