relay-runtime 0.0.0-main-f0fc1eea → 0.0.0-main-c454f22f

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.
@@ -27,6 +27,7 @@ var RelayConcreteNode = {
27
27
  ACTOR_CHANGE: 'ActorChange',
28
28
  CONDITION: 'Condition',
29
29
  CLIENT_COMPONENT: 'ClientComponent',
30
+ CLIENT_EDGE: 'ClientEdge',
30
31
  CLIENT_EXTENSION: 'ClientExtension',
31
32
  DEFER: 'Defer',
32
33
  CONNECTION: 'Connection',
@@ -12,6 +12,7 @@
12
12
 
13
13
  var RelayFeatureFlags = {
14
14
  DELAY_CLEANUP_OF_PENDING_PRELOAD_QUERIES: false,
15
+ ENABLE_CLIENT_EDGES: false,
15
16
  ENABLE_VARIABLE_CONNECTION_KEY: false,
16
17
  ENABLE_PARTIAL_RENDERING_DEFAULT: true,
17
18
  ENABLE_REACT_FLIGHT_COMPONENT_FIELD: false,
@@ -26,6 +27,7 @@ var RelayFeatureFlags = {
26
27
  ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT: false,
27
28
  ENABLE_QUERY_RENDERER_OFFSCREEN_SUPPORT: false,
28
29
  MAX_DATA_ID_LENGTH: null,
30
+ REFACTOR_SUSPENSE_RESOURCE: true,
29
31
  STRING_INTERN_LEVEL: 0,
30
32
  USE_REACT_CACHE: false
31
33
  };
@@ -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-f0fc1eea",
4
+ "version": "0.0.0-main-c454f22f",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "relay"