relay-runtime 0.0.0-main-dcf2098c → 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-dcf2098c
2
+ * Relay v0.0.0-main-e8bf0b68
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
@@ -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) {
@@ -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-dcf2098c",
4
+ "version": "0.0.0-main-e8bf0b68",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "relay"