relay-runtime 0.0.0-main-204ce14c → 0.0.0-main-e8bf0b68

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-204ce14c
2
+ * Relay v0.0.0-main-e8bf0b68
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
package/index.js.flow CHANGED
@@ -46,6 +46,7 @@ const RelayModernStore = require('./store/RelayModernStore');
46
46
  const RelayOperationTracker = require('./store/RelayOperationTracker');
47
47
  const RelayRecordSource = require('./store/RelayRecordSource');
48
48
  const RelayStoreUtils = require('./store/RelayStoreUtils');
49
+ const ResolverFragments = require('./store/ResolverFragments');
49
50
  const ViewerPattern = require('./store/ViewerPattern');
50
51
  const requestSubscription = require('./subscription/requestSubscription');
51
52
  const createPayloadFor3DField = require('./util/createPayloadFor3DField');
@@ -352,6 +353,7 @@ module.exports = {
352
353
  getPendingOperationsForFragment: getPendingOperationsForFragment,
353
354
  getValueAtPath: getValueAtPath,
354
355
  __internal: {
356
+ ResolverFragments,
355
357
  OperationTracker: RelayOperationTracker,
356
358
  createRelayContext: createRelayContext,
357
359
  getOperationVariables: RelayConcreteVariables.getOperationVariables,
package/lib/index.js CHANGED
@@ -73,6 +73,8 @@ var RelayRecordSource = require('./store/RelayRecordSource');
73
73
 
74
74
  var RelayStoreUtils = require('./store/RelayStoreUtils');
75
75
 
76
+ var ResolverFragments = require('./store/ResolverFragments');
77
+
76
78
  var ViewerPattern = require('./store/ViewerPattern');
77
79
 
78
80
  var requestSubscription = require('./subscription/requestSubscription');
@@ -230,6 +232,7 @@ module.exports = {
230
232
  getPendingOperationsForFragment: getPendingOperationsForFragment,
231
233
  getValueAtPath: getValueAtPath,
232
234
  __internal: {
235
+ ResolverFragments: ResolverFragments,
233
236
  OperationTracker: RelayOperationTracker,
234
237
  createRelayContext: createRelayContext,
235
238
  getOperationVariables: RelayConcreteVariables.getOperationVariables,
@@ -37,7 +37,7 @@ function readUpdatableQuery_EXPERIMENTAL(query, variables, proxy) {
37
37
  }
38
38
 
39
39
  function updateProxyFromSelections(mutableUpdatableProxy, recordProxy, queryVariables, selections, root) {
40
- var _selection$alias, _selection$alias2;
40
+ var _selection$alias3;
41
41
 
42
42
  var _iterator = (0, _createForOfIteratorHelper2["default"])(selections),
43
43
  _step;
@@ -48,21 +48,23 @@ function updateProxyFromSelections(mutableUpdatableProxy, recordProxy, queryVari
48
48
 
49
49
  switch (selection.kind) {
50
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
- });
51
+ if (selection.plural) {
52
+ Object.defineProperty(mutableUpdatableProxy, (_selection$alias = selection.alias) !== null && _selection$alias !== void 0 ? _selection$alias : selection.name, {
53
+ // $FlowFixMe[incompatible-call] these getters and setters have different types on purpose
54
+ get: createGetterForPluralLinkedField(selection, queryVariables, recordProxy, root),
55
+ set: createSetterForPluralLinkedField(selection, queryVariables, recordProxy, root)
56
+ });
57
+ } else {
58
+ Object.defineProperty(mutableUpdatableProxy, (_selection$alias2 = selection.alias) !== null && _selection$alias2 !== void 0 ? _selection$alias2 : selection.name, {
59
+ get: createGetterForSingularLinkedField(selection, queryVariables, recordProxy, root),
60
+ set: createSetterForSingularLinkedField(selection, queryVariables, recordProxy, root)
61
+ });
62
+ }
63
+
62
64
  break;
63
65
 
64
66
  case 'ScalarField':
65
- var scalarFieldName = (_selection$alias2 = selection.alias) !== null && _selection$alias2 !== void 0 ? _selection$alias2 : selection.name;
67
+ var scalarFieldName = (_selection$alias3 = selection.alias) !== null && _selection$alias3 !== void 0 ? _selection$alias3 : selection.name;
66
68
  Object.defineProperty(mutableUpdatableProxy, scalarFieldName, {
67
69
  get: function get() {
68
70
  var _selection$args;
@@ -106,6 +108,10 @@ function updateProxyFromSelections(mutableUpdatableProxy, recordProxy, queryVari
106
108
  };
107
109
 
108
110
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
111
+ var _selection$alias;
112
+
113
+ var _selection$alias2;
114
+
109
115
  _loop();
110
116
  }
111
117
  } catch (err) {
@@ -122,8 +128,7 @@ function createSetterForPluralLinkedField(selection, queryVariables, recordProxy
122
128
  var variables = getArgumentValues((_selection$args3 = selection.args) !== null && _selection$args3 !== void 0 ? _selection$args3 : [], queryVariables);
123
129
 
124
130
  if (newValue == null) {
125
- // $FlowFixMe[unclear-type] No good way to type these variables
126
- recordProxy.setValue(null, selection.name, variables);
131
+ throw new Error('Do not assign null to plural linked fields; assign an empty array instead.');
127
132
  } else {
128
133
  var recordProxies = newValue.map(function (item) {
129
134
  if (item == null) {
@@ -122,6 +122,9 @@ function fetchQuery(environment, query, variables, options) {
122
122
  if (snapshot.missingRequiredFields != null) {
123
123
  reportMissingRequiredFields(environment, snapshot.missingRequiredFields);
124
124
  }
125
+ /* $FlowFixMe[incompatible-return] we assume readData returns the right
126
+ * data just having written it from network or checked availability. */
127
+
125
128
 
126
129
  return snapshot.data;
127
130
  }
@@ -37,9 +37,9 @@ function withResolverContext(context, cb) {
37
37
  // The declarations ensure that the type of the returned data is:
38
38
  // - non-nullable if the provided ref type is non-nullable
39
39
  // - nullable if the provided ref type is nullable
40
- // - array of non-nullable if the privoided ref type is an array of
40
+ // - array of non-nullable if the provided ref type is an array of
41
41
  // non-nullable refs
42
- // - array of nullable if the privoided ref type is an array of nullable refs
42
+ // - array of nullable if the provided ref type is an array of nullable refs
43
43
 
44
44
 
45
45
  function readFragment(fragmentInput, fragmentKey) {
@@ -55,50 +55,46 @@ function updateProxyFromSelections<TQuery: OperationType>(
55
55
  for (const selection of selections) {
56
56
  switch (selection.kind) {
57
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
- );
58
+ if (selection.plural) {
59
+ Object.defineProperty(
60
+ mutableUpdatableProxy,
61
+ selection.alias ?? selection.name,
62
+ {
63
+ // $FlowFixMe[incompatible-call] these getters and setters have different types on purpose
64
+ get: createGetterForPluralLinkedField(
65
+ selection,
66
+ queryVariables,
67
+ recordProxy,
68
+ root,
69
+ ),
70
+ set: createSetterForPluralLinkedField(
71
+ selection,
72
+ queryVariables,
73
+ recordProxy,
74
+ root,
75
+ ),
76
+ },
77
+ );
78
+ } else {
79
+ Object.defineProperty(
80
+ mutableUpdatableProxy,
81
+ selection.alias ?? selection.name,
82
+ {
83
+ get: createGetterForSingularLinkedField(
84
+ selection,
85
+ queryVariables,
86
+ recordProxy,
87
+ root,
88
+ ),
89
+ set: createSetterForSingularLinkedField(
90
+ selection,
91
+ queryVariables,
92
+ recordProxy,
93
+ root,
94
+ ),
95
+ },
96
+ );
97
+ }
102
98
  break;
103
99
  case 'ScalarField':
104
100
  const scalarFieldName = selection.alias ?? selection.name;
@@ -171,11 +167,12 @@ function createSetterForPluralLinkedField<TQuery: OperationType>(
171
167
  recordProxy: RecordProxy,
172
168
  root: RecordSourceProxy,
173
169
  ) {
174
- return function set(newValue: ?$ReadOnlyArray<{__id: string, ...}>) {
170
+ return function set(newValue: $ReadOnlyArray<{__id: string, ...}>) {
175
171
  const variables = getArgumentValues(selection.args ?? [], queryVariables);
176
172
  if (newValue == null) {
177
- // $FlowFixMe[unclear-type] No good way to type these variables
178
- recordProxy.setValue(null, selection.name, (variables: any));
173
+ throw new Error(
174
+ 'Do not assign null to plural linked fields; assign an empty array instead.',
175
+ );
179
176
  } else {
180
177
  const recordProxies = newValue.map(item => {
181
178
  if (item == null) {
@@ -206,6 +203,7 @@ function createSetterForPluralLinkedField<TQuery: OperationType>(
206
203
  }
207
204
  };
208
205
  }
206
+
209
207
  function createSetterForSingularLinkedField<TQuery: OperationType>(
210
208
  selection: ReaderLinkedField,
211
209
  queryVariables: TQuery['variables'],
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-204ce14c",
4
+ "version": "0.0.0-main-e8bf0b68",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "relay"
@@ -22,9 +22,9 @@ import type {
22
22
  CacheConfig,
23
23
  FetchQueryFetchPolicy,
24
24
  OperationType,
25
- VariablesOf,
25
+ Query,
26
+ Variables,
26
27
  } from '../util/RelayRuntimeTypes';
27
- import type {GraphQLTaggedNode} from './GraphQLTag';
28
28
 
29
29
  const RelayObservable = require('../network/RelayObservable');
30
30
  const {
@@ -112,15 +112,15 @@ const invariant = require('invariant');
112
112
  * ```
113
113
  * NOTE: When using .toPromise(), the request cannot be cancelled.
114
114
  */
115
- function fetchQuery<TQuery: OperationType>(
115
+ function fetchQuery<TVariables: Variables, TData, TRawResponse>(
116
116
  environment: IEnvironment,
117
- query: GraphQLTaggedNode,
118
- variables: VariablesOf<TQuery>,
117
+ query: Query<TVariables, TData, TRawResponse>,
118
+ variables: TVariables,
119
119
  options?: $ReadOnly<{|
120
120
  fetchPolicy?: FetchQueryFetchPolicy,
121
121
  networkCacheConfig?: CacheConfig,
122
122
  |}>,
123
- ): RelayObservable<TQuery['response']> {
123
+ ): RelayObservable<TData> {
124
124
  const queryNode = getRequest(query);
125
125
  invariant(
126
126
  queryNode.params.operationKind === 'query',
@@ -137,10 +137,12 @@ function fetchQuery<TQuery: OperationType>(
137
137
  );
138
138
  const fetchPolicy = options?.fetchPolicy ?? 'network-only';
139
139
 
140
- function readData(snapshot: Snapshot) {
140
+ function readData(snapshot: Snapshot): TData {
141
141
  if (snapshot.missingRequiredFields != null) {
142
142
  reportMissingRequiredFields(environment, snapshot.missingRequiredFields);
143
143
  }
144
+ /* $FlowFixMe[incompatible-return] we assume readData returns the right
145
+ * data just having written it from network or checked availability. */
144
146
  return snapshot.data;
145
147
  }
146
148