relay-runtime 0.0.0-main-d7cde3ab → 0.0.0-main-c3ad9027

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v0.0.0-main-d7cde3ab
2
+ * Relay v0.0.0-main-c3ad9027
3
3
  *
4
4
  * Copyright (c) Facebook, Inc. and its affiliates.
5
5
  *
package/index.js.flow CHANGED
@@ -179,8 +179,8 @@ export type {
179
179
  NormalizationSplitOperation,
180
180
  NormalizationStream,
181
181
  NormalizationTypeDiscriminator,
182
+ NormalizationOperation,
182
183
  } from './util/NormalizationNode';
183
- export type {NormalizationOperation} from './util/NormalizationNode';
184
184
  export type {
185
185
  ReaderArgument,
186
186
  ReaderArgumentDefinition,
@@ -20,6 +20,9 @@ var _require2 = require('../store/RelayStoreUtils'),
20
20
  ROOT_ID = _require2.ROOT_ID,
21
21
  ROOT_TYPE = _require2.ROOT_TYPE;
22
22
 
23
+ var _require3 = require('./readUpdatableQuery_EXPERIMENTAL'),
24
+ _readUpdatableQuery_EXPERIMENTAL = _require3.readUpdatableQuery_EXPERIMENTAL;
25
+
23
26
  var RelayRecordProxy = require('./RelayRecordProxy');
24
27
 
25
28
  var invariant = require('invariant');
@@ -132,6 +135,10 @@ var RelayRecordSourceProxy = /*#__PURE__*/function () {
132
135
  return this._idsMarkedForInvalidation;
133
136
  };
134
137
 
138
+ _proto.readUpdatableQuery_EXPERIMENTAL = function readUpdatableQuery_EXPERIMENTAL(query, variables) {
139
+ return _readUpdatableQuery_EXPERIMENTAL(query, variables, this);
140
+ };
141
+
135
142
  return RelayRecordSourceProxy;
136
143
  }();
137
144
 
@@ -14,6 +14,9 @@ var _require = require('../store/RelayStoreUtils'),
14
14
  ROOT_TYPE = _require.ROOT_TYPE,
15
15
  getStorageKey = _require.getStorageKey;
16
16
 
17
+ var _require2 = require('./readUpdatableQuery_EXPERIMENTAL'),
18
+ _readUpdatableQuery_EXPERIMENTAL = _require2.readUpdatableQuery_EXPERIMENTAL;
19
+
17
20
  var invariant = require('invariant');
18
21
  /**
19
22
  * @internal
@@ -92,6 +95,10 @@ var RelayRecordSourceSelectorProxy = /*#__PURE__*/function () {
92
95
  this.__recordSource.invalidateStore();
93
96
  };
94
97
 
98
+ _proto.readUpdatableQuery_EXPERIMENTAL = function readUpdatableQuery_EXPERIMENTAL(query, variables) {
99
+ return _readUpdatableQuery_EXPERIMENTAL(query, variables, this);
100
+ };
101
+
95
102
  return RelayRecordSourceSelectorProxy;
96
103
  }();
97
104
 
@@ -0,0 +1,238 @@
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
+ *
8
+ * @emails oncall+relay
9
+ * @format
10
+ */
11
+ // flowlint ambiguous-object-type:error
12
+ 'use strict';
13
+
14
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
15
+
16
+ var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
17
+
18
+ var _require = require('../query/GraphQLTag'),
19
+ getRequest = _require.getRequest;
20
+
21
+ var _require2 = require('../store/RelayStoreUtils'),
22
+ getArgumentValues = _require2.getArgumentValues;
23
+
24
+ var nonUpdatableKeys = ['id', '__id', '__typename'];
25
+
26
+ function readUpdatableQuery_EXPERIMENTAL(query, variables, proxy) {
27
+ // TODO assert that the concrete request is an updatable query
28
+ var request = getRequest(query);
29
+ var updatableProxy = {};
30
+ updateProxyFromSelections(updatableProxy, proxy.getRoot(), variables, request.fragment.selections, proxy);
31
+
32
+ if (process.env.NODE_ENV !== "production") {
33
+ Object.freeze(updatableProxy);
34
+ }
35
+
36
+ return updatableProxy;
37
+ }
38
+
39
+ function updateProxyFromSelections(mutableUpdatableProxy, recordProxy, queryVariables, selections, root) {
40
+ var _selection$alias, _selection$alias2;
41
+
42
+ var _iterator = (0, _createForOfIteratorHelper2["default"])(selections),
43
+ _step;
44
+
45
+ try {
46
+ var _loop = function _loop() {
47
+ var selection = _step.value;
48
+
49
+ switch (selection.kind) {
50
+ case 'LinkedField':
51
+ // Linked fields are assignable if they contain fragment spreads or
52
+ // read-only otherwise.
53
+ var isAssignable = selection.selections.some(function (item) {
54
+ return item.kind === 'FragmentSpread';
55
+ });
56
+ var set = !isAssignable ? undefined : selection.plural ? createSetterForPluralLinkedField(selection, queryVariables, recordProxy, root) : createSetterForSingularLinkedField(selection, queryVariables, recordProxy, root);
57
+ var get = selection.plural ? createGetterForPluralLinkedField(selection, queryVariables, recordProxy, root) : createGetterForSingularLinkedField(selection, queryVariables, recordProxy, root);
58
+ Object.defineProperty(mutableUpdatableProxy, (_selection$alias = selection.alias) !== null && _selection$alias !== void 0 ? _selection$alias : selection.name, {
59
+ get: get,
60
+ set: set
61
+ });
62
+ break;
63
+
64
+ case 'ScalarField':
65
+ var scalarFieldName = (_selection$alias2 = selection.alias) !== null && _selection$alias2 !== void 0 ? _selection$alias2 : selection.name;
66
+ Object.defineProperty(mutableUpdatableProxy, scalarFieldName, {
67
+ get: function get() {
68
+ var _selection$args;
69
+
70
+ var variables = getArgumentValues((_selection$args = selection.args) !== null && _selection$args !== void 0 ? _selection$args : [], queryVariables); // Flow incorrect assumes that the return value for the get method must match
71
+ // the set parameter.
72
+
73
+ return recordProxy.getValue(selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
74
+ variables // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
75
+ );
76
+ },
77
+ set: nonUpdatableKeys.includes(selection.name) ? undefined : // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
78
+ function (newValue) {
79
+ var _selection$args2;
80
+
81
+ var variables = getArgumentValues((_selection$args2 = selection.args) !== null && _selection$args2 !== void 0 ? _selection$args2 : [], queryVariables);
82
+ recordProxy.setValue(newValue, selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
83
+ variables);
84
+ }
85
+ });
86
+ break;
87
+
88
+ case 'InlineFragment':
89
+ if (recordProxy.getType() === selection.type) {
90
+ updateProxyFromSelections(mutableUpdatableProxy, recordProxy, queryVariables, selection.selections, root);
91
+ }
92
+
93
+ break;
94
+
95
+ case 'FragmentSpread':
96
+ // Explicitly ignore
97
+ break;
98
+
99
+ default:
100
+ throw new Error('Encountered an unexpected ReaderSelection variant in RelayRecordSourceProxy. This indicates a bug in Relay.');
101
+ }
102
+ };
103
+
104
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
105
+ _loop();
106
+ }
107
+ } catch (err) {
108
+ _iterator.e(err);
109
+ } finally {
110
+ _iterator.f();
111
+ }
112
+ }
113
+
114
+ function createSetterForPluralLinkedField(selection, queryVariables, recordProxy, root) {
115
+ return function set(newValue) {
116
+ var _selection$args3;
117
+
118
+ var variables = getArgumentValues((_selection$args3 = selection.args) !== null && _selection$args3 !== void 0 ? _selection$args3 : [], queryVariables);
119
+
120
+ if (newValue == null) {
121
+ // $FlowFixMe[unclear-type] No good way to type these variables
122
+ recordProxy.setValue(null, selection.name, variables);
123
+ } else {
124
+ var recordProxies = newValue.map(function (item) {
125
+ if (item == null) {
126
+ throw new Error('When assigning an array of items, none of the items should be null or undefined.');
127
+ }
128
+
129
+ var __id = item.__id;
130
+
131
+ if (__id == null) {
132
+ throw new Error('The __id field must be present on each item passed to the setter. This indicates a bug in Relay.');
133
+ }
134
+
135
+ var newValueRecord = root.get(__id);
136
+
137
+ if (newValueRecord == null) {
138
+ throw new Error("Did not find item with data id ".concat(__id, " in the store."));
139
+ }
140
+
141
+ return newValueRecord;
142
+ });
143
+ recordProxy.setLinkedRecords(recordProxies, selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
144
+ variables);
145
+ }
146
+ };
147
+ }
148
+
149
+ function createSetterForSingularLinkedField(selection, queryVariables, recordProxy, root) {
150
+ return function set(newValue) {
151
+ var _selection$args4;
152
+
153
+ var variables = getArgumentValues((_selection$args4 = selection.args) !== null && _selection$args4 !== void 0 ? _selection$args4 : [], queryVariables);
154
+
155
+ if (newValue == null) {
156
+ // $FlowFixMe[unclear-type] No good way to type these variables
157
+ recordProxy.setValue(null, selection.name, variables);
158
+ } else {
159
+ var __id = newValue.__id;
160
+
161
+ if (__id == null) {
162
+ throw new Error('The __id field must be present on the argument. This indicates a bug in Relay.');
163
+ }
164
+
165
+ var newValueRecord = root.get(__id);
166
+
167
+ if (newValueRecord == null) {
168
+ throw new Error("Did not find item with data id ".concat(__id, " in the store."));
169
+ }
170
+
171
+ recordProxy.setLinkedRecord(newValueRecord, selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
172
+ variables);
173
+ }
174
+ };
175
+ }
176
+
177
+ function createGetterForPluralLinkedField(selection, queryVariables, recordProxy, root) {
178
+ return function () {
179
+ var _selection$args5;
180
+
181
+ var variables = getArgumentValues((_selection$args5 = selection.args) !== null && _selection$args5 !== void 0 ? _selection$args5 : [], queryVariables);
182
+ var linkedRecords = recordProxy.getLinkedRecords(selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
183
+ variables);
184
+
185
+ if (linkedRecords != null) {
186
+ return linkedRecords.map(function (linkedRecord) {
187
+ if (linkedRecord != null) {
188
+ var updatableProxy = {};
189
+ updateProxyFromSelections(updatableProxy, linkedRecord, queryVariables, selection.selections, root);
190
+
191
+ if (process.env.NODE_ENV !== "production") {
192
+ Object.freeze(updatableProxy);
193
+ } // Flow incorrect assumes that the return value for the get method must match
194
+ // the set parameter.
195
+ // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
196
+
197
+
198
+ return updatableProxy;
199
+ } else {
200
+ return linkedRecord;
201
+ } // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
202
+
203
+ });
204
+ } else {
205
+ return linkedRecords;
206
+ }
207
+ };
208
+ }
209
+
210
+ function createGetterForSingularLinkedField(selection, queryVariables, recordProxy, root) {
211
+ return function () {
212
+ var _selection$args6;
213
+
214
+ var variables = getArgumentValues((_selection$args6 = selection.args) !== null && _selection$args6 !== void 0 ? _selection$args6 : [], queryVariables);
215
+ var linkedRecord = recordProxy.getLinkedRecord(selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
216
+ variables);
217
+
218
+ if (linkedRecord != null) {
219
+ var updatableProxy = {};
220
+ updateProxyFromSelections(updatableProxy, linkedRecord, queryVariables, selection.selections, root);
221
+
222
+ if (process.env.NODE_ENV !== "production") {
223
+ Object.freeze(updatableProxy);
224
+ } // Flow incorrect assumes that the return value for the get method must match
225
+ // the set parameter.
226
+ // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
227
+
228
+
229
+ return updatableProxy;
230
+ } else {
231
+ return linkedRecord;
232
+ }
233
+ };
234
+ }
235
+
236
+ module.exports = {
237
+ readUpdatableQuery_EXPERIMENTAL: readUpdatableQuery_EXPERIMENTAL
238
+ };
@@ -13,6 +13,7 @@
13
13
  'use strict';
14
14
 
15
15
  import type {HandlerProvider} from '../handlers/RelayDefaultHandlerProvider';
16
+ import type {GraphQLTaggedNode} from '../query/GraphQLTag';
16
17
  import type {GetDataID} from '../store/RelayResponseNormalizer';
17
18
  import type {
18
19
  DataIDSet,
@@ -21,12 +22,15 @@ import type {
21
22
  RecordSource,
22
23
  RecordSourceProxy,
23
24
  } from '../store/RelayStoreTypes';
24
- import type {DataID} from '../util/RelayRuntimeTypes';
25
+ import type {DataID, OperationType} from '../util/RelayRuntimeTypes';
25
26
  import type RelayRecordSourceMutator from './RelayRecordSourceMutator';
26
27
 
27
28
  const RelayModernRecord = require('../store/RelayModernRecord');
28
29
  const {EXISTENT, NONEXISTENT} = require('../store/RelayRecordState');
29
30
  const {ROOT_ID, ROOT_TYPE} = require('../store/RelayStoreUtils');
31
+ const {
32
+ readUpdatableQuery_EXPERIMENTAL,
33
+ } = require('./readUpdatableQuery_EXPERIMENTAL');
30
34
  const RelayRecordProxy = require('./RelayRecordProxy');
31
35
  const invariant = require('invariant');
32
36
 
@@ -158,6 +162,13 @@ class RelayRecordSourceProxy implements RecordSourceProxy {
158
162
  getIDsMarkedForInvalidation(): DataIDSet {
159
163
  return this._idsMarkedForInvalidation;
160
164
  }
165
+
166
+ readUpdatableQuery_EXPERIMENTAL<TQuery: OperationType>(
167
+ query: GraphQLTaggedNode,
168
+ variables: TQuery['variables'],
169
+ ): TQuery['response'] {
170
+ return readUpdatableQuery_EXPERIMENTAL(query, variables, this);
171
+ }
161
172
  }
162
173
 
163
174
  module.exports = RelayRecordSourceProxy;
@@ -12,6 +12,7 @@
12
12
 
13
13
  'use strict';
14
14
 
15
+ import type {GraphQLTaggedNode} from '../query/GraphQLTag';
15
16
  import type {
16
17
  RecordProxy,
17
18
  RecordSourceProxy,
@@ -19,10 +20,13 @@ import type {
19
20
  SingularReaderSelector,
20
21
  } from '../store/RelayStoreTypes';
21
22
  import type {ReaderLinkedField} from '../util/ReaderNode';
22
- import type {DataID} from '../util/RelayRuntimeTypes';
23
+ import type {DataID, OperationType} from '../util/RelayRuntimeTypes';
23
24
  import type RelayRecordSourceMutator from './RelayRecordSourceMutator';
24
25
 
25
26
  const {ROOT_TYPE, getStorageKey} = require('../store/RelayStoreUtils');
27
+ const {
28
+ readUpdatableQuery_EXPERIMENTAL,
29
+ } = require('./readUpdatableQuery_EXPERIMENTAL');
26
30
  const invariant = require('invariant');
27
31
 
28
32
  /**
@@ -118,6 +122,13 @@ class RelayRecordSourceSelectorProxy implements RecordSourceSelectorProxy {
118
122
  invalidateStore(): void {
119
123
  this.__recordSource.invalidateStore();
120
124
  }
125
+
126
+ readUpdatableQuery_EXPERIMENTAL<TQuery: OperationType>(
127
+ query: GraphQLTaggedNode,
128
+ variables: TQuery['variables'],
129
+ ): TQuery['response'] {
130
+ return readUpdatableQuery_EXPERIMENTAL(query, variables, this);
131
+ }
121
132
  }
122
133
 
123
134
  module.exports = RelayRecordSourceSelectorProxy;
@@ -0,0 +1,309 @@
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
+ * @flow strict-local
8
+ * @emails oncall+relay
9
+ * @format
10
+ */
11
+
12
+ // flowlint ambiguous-object-type:error
13
+
14
+ 'use strict';
15
+
16
+ import type {GraphQLTaggedNode} from '../query/GraphQLTag';
17
+ import type {RecordProxy, RecordSourceProxy} from '../store/RelayStoreTypes';
18
+ import type {ReaderLinkedField, ReaderSelection} from '../util/ReaderNode';
19
+ import type {OperationType} from '../util/RelayRuntimeTypes';
20
+
21
+ const {getRequest} = require('../query/GraphQLTag');
22
+ const {getArgumentValues} = require('../store/RelayStoreUtils');
23
+
24
+ const nonUpdatableKeys = ['id', '__id', '__typename'];
25
+
26
+ function readUpdatableQuery_EXPERIMENTAL<TQuery: OperationType>(
27
+ query: GraphQLTaggedNode,
28
+ variables: TQuery['variables'],
29
+ proxy: RecordSourceProxy,
30
+ ): TQuery['response'] {
31
+ // TODO assert that the concrete request is an updatable query
32
+ const request = getRequest(query);
33
+
34
+ const updatableProxy = {};
35
+ updateProxyFromSelections(
36
+ updatableProxy,
37
+ proxy.getRoot(),
38
+ variables,
39
+ request.fragment.selections,
40
+ proxy,
41
+ );
42
+ if (__DEV__) {
43
+ Object.freeze(updatableProxy);
44
+ }
45
+ return updatableProxy;
46
+ }
47
+
48
+ function updateProxyFromSelections<TQuery: OperationType>(
49
+ mutableUpdatableProxy: TQuery['response'],
50
+ recordProxy: RecordProxy,
51
+ queryVariables: TQuery['variables'],
52
+ selections: $ReadOnlyArray<ReaderSelection>,
53
+ root: RecordSourceProxy,
54
+ ) {
55
+ for (const selection of selections) {
56
+ switch (selection.kind) {
57
+ case 'LinkedField':
58
+ // Linked fields are assignable if they contain fragment spreads or
59
+ // read-only otherwise.
60
+ const isAssignable = selection.selections.some(
61
+ item => item.kind === 'FragmentSpread',
62
+ );
63
+
64
+ const set = !isAssignable
65
+ ? undefined
66
+ : selection.plural
67
+ ? createSetterForPluralLinkedField(
68
+ selection,
69
+ queryVariables,
70
+ recordProxy,
71
+ root,
72
+ )
73
+ : createSetterForSingularLinkedField(
74
+ selection,
75
+ queryVariables,
76
+ recordProxy,
77
+ root,
78
+ );
79
+
80
+ const get = selection.plural
81
+ ? createGetterForPluralLinkedField(
82
+ selection,
83
+ queryVariables,
84
+ recordProxy,
85
+ root,
86
+ )
87
+ : createGetterForSingularLinkedField(
88
+ selection,
89
+ queryVariables,
90
+ recordProxy,
91
+ root,
92
+ );
93
+
94
+ Object.defineProperty(
95
+ mutableUpdatableProxy,
96
+ selection.alias ?? selection.name,
97
+ {
98
+ get,
99
+ set,
100
+ },
101
+ );
102
+ break;
103
+ case 'ScalarField':
104
+ const scalarFieldName = selection.alias ?? selection.name;
105
+ Object.defineProperty(mutableUpdatableProxy, scalarFieldName, {
106
+ get: function () {
107
+ const variables = getArgumentValues(
108
+ selection.args ?? [],
109
+ queryVariables,
110
+ );
111
+ // Flow incorrect assumes that the return value for the get method must match
112
+ // the set parameter.
113
+ return (recordProxy.getValue(
114
+ selection.name,
115
+ // $FlowFixMe[unclear-type] No good way to type these variables
116
+ (variables: any),
117
+ // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
118
+ ): any);
119
+ },
120
+ set: nonUpdatableKeys.includes(selection.name)
121
+ ? undefined
122
+ : // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
123
+ function (newValue: ?any) {
124
+ const variables = getArgumentValues(
125
+ selection.args ?? [],
126
+ queryVariables,
127
+ );
128
+ recordProxy.setValue(
129
+ newValue,
130
+ selection.name,
131
+ // $FlowFixMe[unclear-type] No good way to type these variables
132
+ (variables: any),
133
+ );
134
+ },
135
+ });
136
+ break;
137
+ case 'InlineFragment':
138
+ if (recordProxy.getType() === selection.type) {
139
+ updateProxyFromSelections(
140
+ mutableUpdatableProxy,
141
+ recordProxy,
142
+ queryVariables,
143
+ selection.selections,
144
+ root,
145
+ );
146
+ }
147
+ break;
148
+ case 'FragmentSpread':
149
+ // Explicitly ignore
150
+ break;
151
+ default:
152
+ throw new Error(
153
+ 'Encountered an unexpected ReaderSelection variant in RelayRecordSourceProxy. This indicates a bug in Relay.',
154
+ );
155
+ }
156
+ }
157
+ }
158
+
159
+ function createSetterForPluralLinkedField<TQuery: OperationType>(
160
+ selection: ReaderLinkedField,
161
+ queryVariables: TQuery['variables'],
162
+ recordProxy: RecordProxy,
163
+ root: RecordSourceProxy,
164
+ ) {
165
+ return function set(newValue: ?$ReadOnlyArray<{__id: string, ...}>) {
166
+ const variables = getArgumentValues(selection.args ?? [], queryVariables);
167
+ if (newValue == null) {
168
+ // $FlowFixMe[unclear-type] No good way to type these variables
169
+ recordProxy.setValue(null, selection.name, (variables: any));
170
+ } else {
171
+ const recordProxies = newValue.map(item => {
172
+ if (item == null) {
173
+ throw new Error(
174
+ 'When assigning an array of items, none of the items should be null or undefined.',
175
+ );
176
+ }
177
+ const {__id} = item;
178
+ if (__id == null) {
179
+ throw new Error(
180
+ 'The __id field must be present on each item passed to the setter. This indicates a bug in Relay.',
181
+ );
182
+ }
183
+ const newValueRecord = root.get(__id);
184
+ if (newValueRecord == null) {
185
+ throw new Error(
186
+ `Did not find item with data id ${__id} in the store.`,
187
+ );
188
+ }
189
+ return newValueRecord;
190
+ });
191
+ recordProxy.setLinkedRecords(
192
+ recordProxies,
193
+ selection.name,
194
+ // $FlowFixMe[unclear-type] No good way to type these variables
195
+ (variables: any),
196
+ );
197
+ }
198
+ };
199
+ }
200
+ function createSetterForSingularLinkedField<TQuery: OperationType>(
201
+ selection: ReaderLinkedField,
202
+ queryVariables: TQuery['variables'],
203
+ recordProxy: RecordProxy,
204
+ root: RecordSourceProxy,
205
+ ) {
206
+ return function set(newValue: ?{__id: string, ...}) {
207
+ const variables = getArgumentValues(selection.args ?? [], queryVariables);
208
+ if (newValue == null) {
209
+ // $FlowFixMe[unclear-type] No good way to type these variables
210
+ recordProxy.setValue(null, selection.name, (variables: any));
211
+ } else {
212
+ const {__id} = newValue;
213
+ if (__id == null) {
214
+ throw new Error(
215
+ 'The __id field must be present on the argument. This indicates a bug in Relay.',
216
+ );
217
+ }
218
+ const newValueRecord = root.get(__id);
219
+ if (newValueRecord == null) {
220
+ throw new Error(`Did not find item with data id ${__id} in the store.`);
221
+ }
222
+ recordProxy.setLinkedRecord(
223
+ newValueRecord,
224
+ selection.name,
225
+ // $FlowFixMe[unclear-type] No good way to type these variables
226
+ (variables: any),
227
+ );
228
+ }
229
+ };
230
+ }
231
+
232
+ function createGetterForPluralLinkedField<TQuery: OperationType>(
233
+ selection: ReaderLinkedField,
234
+ queryVariables: TQuery['variables'],
235
+ recordProxy: RecordProxy,
236
+ root: RecordSourceProxy,
237
+ ) {
238
+ return function () {
239
+ const variables = getArgumentValues(selection.args ?? [], queryVariables);
240
+ const linkedRecords = recordProxy.getLinkedRecords(
241
+ selection.name,
242
+ // $FlowFixMe[unclear-type] No good way to type these variables
243
+ (variables: any),
244
+ );
245
+ if (linkedRecords != null) {
246
+ return (linkedRecords.map(linkedRecord => {
247
+ if (linkedRecord != null) {
248
+ const updatableProxy = {};
249
+ updateProxyFromSelections(
250
+ updatableProxy,
251
+ linkedRecord,
252
+ queryVariables,
253
+ selection.selections,
254
+ root,
255
+ );
256
+ if (__DEV__) {
257
+ Object.freeze(updatableProxy);
258
+ }
259
+ // Flow incorrect assumes that the return value for the get method must match
260
+ // the set parameter.
261
+ // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
262
+ return (updatableProxy: any);
263
+ } else {
264
+ return linkedRecord;
265
+ }
266
+ // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
267
+ }): any);
268
+ } else {
269
+ return linkedRecords;
270
+ }
271
+ };
272
+ }
273
+
274
+ function createGetterForSingularLinkedField<TQuery: OperationType>(
275
+ selection: ReaderLinkedField,
276
+ queryVariables: TQuery['variables'],
277
+ recordProxy: RecordProxy,
278
+ root: RecordSourceProxy,
279
+ ) {
280
+ return function () {
281
+ const variables = getArgumentValues(selection.args ?? [], queryVariables);
282
+ const linkedRecord = recordProxy.getLinkedRecord(
283
+ selection.name,
284
+ // $FlowFixMe[unclear-type] No good way to type these variables
285
+ (variables: any),
286
+ );
287
+ if (linkedRecord != null) {
288
+ const updatableProxy = {};
289
+ updateProxyFromSelections(
290
+ updatableProxy,
291
+ linkedRecord,
292
+ queryVariables,
293
+ selection.selections,
294
+ root,
295
+ );
296
+ if (__DEV__) {
297
+ Object.freeze(updatableProxy);
298
+ }
299
+ // Flow incorrect assumes that the return value for the get method must match
300
+ // the set parameter.
301
+ // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
302
+ return (updatableProxy: any);
303
+ } else {
304
+ return linkedRecord;
305
+ }
306
+ };
307
+ }
308
+
309
+ module.exports = {readUpdatableQuery_EXPERIMENTAL};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "relay-runtime",
3
3
  "description": "A core runtime for building GraphQL-driven applications.",
4
- "version": "0.0.0-main-d7cde3ab",
4
+ "version": "0.0.0-main-c3ad9027",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "relay"