relay-runtime 20.1.1 → 21.0.0
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/experimental.js +1 -1
- package/experimental.js.flow +8 -8
- package/handlers/connection/ConnectionHandler.js.flow +5 -5
- package/handlers/connection/ConnectionInterface.js.flow +1 -1
- package/index.js +1 -1
- package/index.js.flow +125 -62
- package/lib/experimental.js +3 -3
- package/lib/index.js +105 -57
- package/lib/multi-actor-environment/ActorIdentifier.js +2 -2
- package/lib/multi-actor-environment/MultiActorEnvironment.js +3 -1
- package/lib/mutations/commitMutation.js +8 -8
- package/lib/mutations/validateMutation.js +4 -4
- package/lib/query/GraphQLTag.js +3 -3
- package/lib/query/fetchQuery.js +15 -3
- package/lib/store/DataChecker.js +38 -4
- package/lib/store/NormalizationEngine.js +373 -0
- package/lib/store/OperationExecutor.js +172 -113
- package/lib/store/RelayConcreteVariables.js +1 -1
- package/lib/store/RelayErrorTrie.js +2 -2
- package/lib/store/RelayExperimentalGraphResponseTransform.js +8 -8
- package/lib/store/RelayModernEnvironment.js +26 -19
- package/lib/store/RelayModernRecord.js +18 -8
- package/lib/store/RelayModernSelector.js +9 -9
- package/lib/store/RelayModernStore.js +152 -43
- package/lib/store/RelayPublishQueue.js +1 -1
- package/lib/store/RelayReader.js +76 -38
- package/lib/store/RelayRecordSource.js +6 -0
- package/lib/store/RelayReferenceMarker.js +2 -1
- package/lib/store/RelayResponseNormalizer.js +88 -55
- package/lib/store/RelayStoreSubscriptions.js +34 -10
- package/lib/store/RelayStoreUtils.js +8 -1
- package/lib/store/ResolverFragments.js +2 -2
- package/lib/store/live-resolvers/LiveResolverCache.js +25 -9
- package/lib/store/observeFragmentExperimental.js +17 -1
- package/lib/store/observeQueryExperimental.js +2 -2
- package/lib/subscription/requestSubscription.js +3 -3
- package/lib/util/RelayError.js +3 -0
- package/lib/util/RelayFeatureFlags.js +6 -2
- package/lib/util/RelayReplaySubject.js +4 -4
- package/lib/util/handlePotentialSnapshotErrors.js +2 -2
- package/lib/util/stableCopy.js +2 -2
- package/llm-docs/api-reference/entrypoint-apis/entrypoint-container.mdx +38 -0
- package/llm-docs/api-reference/entrypoint-apis/load-entrypoint.mdx +77 -0
- package/llm-docs/api-reference/entrypoint-apis/use-entrypoint-loader.mdx +99 -0
- package/llm-docs/api-reference/graphql/graphql-directives.mdx +378 -0
- package/llm-docs/api-reference/hooks/_use-lazy-load-query-extra.mdx +16 -0
- package/llm-docs/api-reference/hooks/load-query.mdx +84 -0
- package/llm-docs/api-reference/hooks/relay-environment-provider.mdx +78 -0
- package/llm-docs/api-reference/hooks/use-client-query.mdx +65 -0
- package/llm-docs/api-reference/hooks/use-fragment.mdx +69 -0
- package/llm-docs/api-reference/hooks/use-lazy-load-query.mdx +62 -0
- package/llm-docs/api-reference/hooks/use-mutation.mdx +94 -0
- package/llm-docs/api-reference/hooks/use-pagination-fragment.mdx +166 -0
- package/llm-docs/api-reference/hooks/use-prefetchable-forward-pagination-fragment.mdx +134 -0
- package/llm-docs/api-reference/hooks/use-preloaded-query.mdx +84 -0
- package/llm-docs/api-reference/hooks/use-query-loader.mdx +95 -0
- package/llm-docs/api-reference/hooks/use-refetchable-fragment.mdx +122 -0
- package/llm-docs/api-reference/hooks/use-relay-environment.mdx +37 -0
- package/llm-docs/api-reference/hooks/use-subscription.mdx +66 -0
- package/llm-docs/api-reference/relay-resolvers/docblock-format.mdx +321 -0
- package/llm-docs/api-reference/relay-resolvers/runtime-functions.mdx +94 -0
- package/llm-docs/api-reference/relay-runtime/commit-mutation.mdx +65 -0
- package/llm-docs/api-reference/relay-runtime/fetch-query.mdx +113 -0
- package/llm-docs/api-reference/relay-runtime/field-logger.mdx +170 -0
- package/llm-docs/api-reference/relay-runtime/observe-fragment.mdx +92 -0
- package/llm-docs/api-reference/relay-runtime/relay-environment.mdx +53 -0
- package/llm-docs/api-reference/relay-runtime/request-subscription.mdx +54 -0
- package/llm-docs/api-reference/relay-runtime/runtime-configuration.mdx +52 -0
- package/llm-docs/api-reference/relay-runtime/store.mdx +734 -0
- package/llm-docs/api-reference/relay-runtime/wait-for-fragment-data.mdx +89 -0
- package/llm-docs/api-reference/types/CacheConfig.mdx +8 -0
- package/llm-docs/api-reference/types/Disposable.mdx +4 -0
- package/llm-docs/api-reference/types/GraphQLSubscriptionConfig.mdx +17 -0
- package/llm-docs/api-reference/types/MutationConfig.mdx +31 -0
- package/llm-docs/api-reference/types/SelectorStoreUpdater.mdx +6 -0
- package/llm-docs/api-reference/types/UploadableMap.mdx +3 -0
- package/llm-docs/community/learning-resources.mdx +64 -0
- package/llm-docs/debugging/declarative-mutation-directives.mdx +34 -0
- package/llm-docs/debugging/disallowed-id-types-error.mdx +43 -0
- package/llm-docs/debugging/inconsistent-typename-error.mdx +47 -0
- package/llm-docs/debugging/relay-devtools.mdx +73 -0
- package/llm-docs/debugging/why-null.mdx +116 -0
- package/llm-docs/editor-support.mdx +55 -0
- package/llm-docs/error-reference/unknown-field.mdx +36 -0
- package/llm-docs/getting-started/babel-plugin.mdx +31 -0
- package/llm-docs/getting-started/compiler-config.mdx +25 -0
- package/llm-docs/getting-started/compiler.mdx +82 -0
- package/llm-docs/getting-started/lint-rules.mdx +87 -0
- package/llm-docs/getting-started/production.mdx +30 -0
- package/llm-docs/getting-started/quick-start.mdx +213 -0
- package/llm-docs/glossary/glossary.mdx +1040 -0
- package/llm-docs/guided-tour/list-data/advanced-pagination.mdx +157 -0
- package/llm-docs/guided-tour/list-data/connections.mdx +81 -0
- package/llm-docs/guided-tour/list-data/pagination.mdx +193 -0
- package/llm-docs/guided-tour/list-data/rendering-connections.mdx +112 -0
- package/llm-docs/guided-tour/list-data/streaming-pagination.mdx +87 -0
- package/llm-docs/guided-tour/managing-data-outside-react/retaining-queries.mdx +51 -0
- package/llm-docs/guided-tour/refetching/refetching-queries-with-different-data.mdx +337 -0
- package/llm-docs/guided-tour/refetching/refreshing-queries.mdx +350 -0
- package/llm-docs/guided-tour/rendering/environment.mdx +59 -0
- package/llm-docs/guided-tour/rendering/error-states.mdx +295 -0
- package/llm-docs/guided-tour/rendering/fragments.mdx +354 -0
- package/llm-docs/guided-tour/rendering/loading-states.mdx +245 -0
- package/llm-docs/guided-tour/rendering/queries.mdx +261 -0
- package/llm-docs/guided-tour/rendering/variables.mdx +233 -0
- package/llm-docs/guided-tour/reusing-cached-data/fetch-policies.mdx +56 -0
- package/llm-docs/guided-tour/reusing-cached-data/filling-in-missing-data.mdx +102 -0
- package/llm-docs/guided-tour/reusing-cached-data/introduction.mdx +22 -0
- package/llm-docs/guided-tour/reusing-cached-data/presence-of-data.mdx +93 -0
- package/llm-docs/guided-tour/reusing-cached-data/rendering-partially-cached-data.mdx +175 -0
- package/llm-docs/guided-tour/reusing-cached-data/staleness-of-data.mdx +116 -0
- package/llm-docs/guided-tour/updating-data/client-only-data.mdx +115 -0
- package/llm-docs/guided-tour/updating-data/graphql-mutations.mdx +334 -0
- package/llm-docs/guided-tour/updating-data/graphql-subscriptions.mdx +279 -0
- package/llm-docs/guided-tour/updating-data/imperatively-modifying-linked-fields.mdx +511 -0
- package/llm-docs/guided-tour/updating-data/imperatively-modifying-store-data-legacy.mdx +142 -0
- package/llm-docs/guided-tour/updating-data/imperatively-modifying-store-data.mdx +275 -0
- package/llm-docs/guided-tour/updating-data/introduction.mdx +25 -0
- package/llm-docs/guided-tour/updating-data/local-data-updates.mdx +71 -0
- package/llm-docs/guided-tour/updating-data/typesafe-updaters-faq.mdx +83 -0
- package/llm-docs/guided-tour/updating-data/updating-connections.mdx +592 -0
- package/llm-docs/guides/alias-directive.mdx +160 -0
- package/llm-docs/guides/catch-directive.mdx +167 -0
- package/llm-docs/guides/client-schema-extensions.mdx +208 -0
- package/llm-docs/guides/codemods.mdx +66 -0
- package/llm-docs/guides/data-driven-dependencies/client-3d.mdx +255 -0
- package/llm-docs/guides/data-driven-dependencies/configuration.mdx +127 -0
- package/llm-docs/guides/data-driven-dependencies/introduction.mdx +39 -0
- package/llm-docs/guides/data-driven-dependencies/server-3d.mdx +664 -0
- package/llm-docs/guides/document-comparison.mdx +106 -0
- package/llm-docs/guides/graphql-server-specification.mdx +453 -0
- package/llm-docs/guides/network-layer.mdx +69 -0
- package/llm-docs/guides/persisted-queries.mdx +328 -0
- package/llm-docs/guides/relay-resolvers/context.mdx +99 -0
- package/llm-docs/guides/relay-resolvers/defining-fields.mdx +151 -0
- package/llm-docs/guides/relay-resolvers/defining-types.mdx +164 -0
- package/llm-docs/guides/relay-resolvers/deprecated.mdx +27 -0
- package/llm-docs/guides/relay-resolvers/derived-fields.mdx +127 -0
- package/llm-docs/guides/relay-resolvers/descriptions.mdx +44 -0
- package/llm-docs/guides/relay-resolvers/enabling.mdx +41 -0
- package/llm-docs/guides/relay-resolvers/errors.mdx +64 -0
- package/llm-docs/guides/relay-resolvers/field-arguments.mdx +63 -0
- package/llm-docs/guides/relay-resolvers/introduction.mdx +62 -0
- package/llm-docs/guides/relay-resolvers/limitations.mdx +30 -0
- package/llm-docs/guides/relay-resolvers/live-fields.mdx +164 -0
- package/llm-docs/guides/relay-resolvers/return-types.mdx +161 -0
- package/llm-docs/guides/relay-resolvers/suspense.mdx +41 -0
- package/llm-docs/guides/required-directive.mdx +240 -0
- package/llm-docs/guides/semantic-nullability.mdx +93 -0
- package/llm-docs/guides/testing-relay-components.mdx +642 -0
- package/llm-docs/guides/testing-relay-with-preloaded-queries.mdx +160 -0
- package/llm-docs/guides/throw-on-field-error-directive.mdx +58 -0
- package/llm-docs/guides/type-emission.mdx +414 -0
- package/llm-docs/home.mdx +32 -0
- package/llm-docs/principles-and-architecture/architecture-overview.mdx +24 -0
- package/llm-docs/principles-and-architecture/compiler-architecture.mdx +106 -0
- package/llm-docs/principles-and-architecture/runtime-architecture.mdx +249 -0
- package/llm-docs/principles-and-architecture/thinking-in-graphql.mdx +309 -0
- package/llm-docs/principles-and-architecture/thinking-in-relay.mdx +104 -0
- package/llm-docs/principles-and-architecture/videos.mdx +50 -0
- package/llm-docs/tutorial/arrays-lists.mdx +126 -0
- package/llm-docs/tutorial/fragments-1.mdx +487 -0
- package/llm-docs/tutorial/graphql.mdx +172 -0
- package/llm-docs/tutorial/interfaces-polymorphism.mdx +161 -0
- package/llm-docs/tutorial/intro.mdx +58 -0
- package/llm-docs/tutorial/mutations-updates.mdx +624 -0
- package/llm-docs/tutorial/organizing-mutations-queries-and-subscriptions.mdx +13 -0
- package/llm-docs/tutorial/queries-1.mdx +267 -0
- package/llm-docs/tutorial/queries-2.mdx +389 -0
- package/llm-docs/tutorial/refetchable-fragments.mdx +352 -0
- package/multi-actor-environment/ActorIdentifier.js.flow +2 -2
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +7 -7
- package/multi-actor-environment/ActorUtils.js.flow +1 -1
- package/multi-actor-environment/MultiActorEnvironment.js.flow +12 -8
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +3 -3
- package/mutations/RelayDeclarativeMutationConfig.js.flow +9 -9
- package/mutations/RelayRecordProxy.js.flow +8 -11
- package/mutations/RelayRecordSourceMutator.js.flow +4 -4
- package/mutations/RelayRecordSourceProxy.js.flow +4 -4
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +6 -6
- package/mutations/applyOptimisticMutation.js.flow +2 -2
- package/mutations/commitMutation.js.flow +20 -16
- package/mutations/createUpdatableProxy.js.flow +19 -19
- package/mutations/readUpdatableFragment.js.flow +3 -3
- package/mutations/readUpdatableQuery.js.flow +3 -3
- package/mutations/validateMutation.js.flow +7 -7
- package/network/RelayNetworkTypes.js.flow +4 -4
- package/network/RelayObservable.js.flow +16 -14
- package/network/RelayQueryResponseCache.js.flow +3 -3
- package/network/wrapNetworkWithLogObserver.js.flow +1 -1
- package/package.json +2 -1
- package/query/GraphQLTag.js.flow +22 -10
- package/query/fetchQuery.js.flow +23 -10
- package/query/fetchQuery_DEPRECATED.js.flow +1 -1
- package/store/DataChecker.js.flow +43 -9
- package/store/NormalizationEngine.js.flow +779 -0
- package/store/OperationExecutor.js.flow +173 -70
- package/store/RelayConcreteVariables.js.flow +5 -5
- package/store/RelayErrorTrie.js.flow +12 -12
- package/store/RelayExperimentalGraphResponseHandler.js.flow +3 -3
- package/store/RelayExperimentalGraphResponseTransform.js.flow +10 -10
- package/store/RelayModernEnvironment.js.flow +41 -26
- package/store/RelayModernFragmentSpecResolver.js.flow +1 -1
- package/store/RelayModernOperationDescriptor.js.flow +1 -1
- package/store/RelayModernRecord.js.flow +44 -20
- package/store/RelayModernSelector.js.flow +21 -21
- package/store/RelayModernStore.js.flow +219 -58
- package/store/RelayOperationTracker.js.flow +2 -2
- package/store/RelayOptimisticRecordSource.js.flow +2 -2
- package/store/RelayPublishQueue.js.flow +21 -12
- package/store/RelayReader.js.flow +129 -57
- package/store/RelayRecordSource.js.flow +10 -0
- package/store/RelayRecordState.js.flow +1 -1
- package/store/RelayReferenceMarker.js.flow +5 -4
- package/store/RelayResponseNormalizer.js.flow +125 -57
- package/store/RelayStoreSubscriptions.js.flow +52 -8
- package/store/RelayStoreTypes.js.flow +153 -64
- package/store/RelayStoreUtils.js.flow +15 -7
- package/store/ResolverCache.js.flow +2 -2
- package/store/ResolverFragments.js.flow +12 -12
- package/store/StoreInspector.js.flow +6 -7
- package/store/cloneRelayHandleSourceField.js.flow +1 -1
- package/store/cloneRelayScalarHandleSourceField.js.flow +1 -1
- package/store/createRelayContext.js.flow +1 -1
- package/store/createRelayLoggingContext.js.flow +4 -4
- package/store/defaultGetDataID.js.flow +2 -2
- package/store/isRelayModernEnvironment.js.flow +4 -2
- package/store/live-resolvers/LiveResolverCache.js.flow +55 -20
- package/store/live-resolvers/LiveResolverSuspenseSentinel.js.flow +3 -3
- package/store/live-resolvers/getOutputTypeRecordIDs.js.flow +1 -1
- package/store/live-resolvers/isLiveStateValue.js.flow +2 -2
- package/store/live-resolvers/resolverDataInjector.js.flow +8 -5
- package/store/observeFragmentExperimental.js.flow +49 -20
- package/store/observeQueryExperimental.js.flow +5 -5
- package/store/readInlineData.js.flow +4 -4
- package/store/waitForFragmentExperimental.js.flow +3 -3
- package/subscription/requestSubscription.js.flow +7 -7
- package/util/NormalizationNode.js.flow +34 -32
- package/util/ReaderNode.js.flow +32 -30
- package/util/RelayConcreteNode.js.flow +5 -5
- package/util/RelayError.js.flow +4 -1
- package/util/RelayFeatureFlags.js.flow +21 -1
- package/util/RelayProfiler.js.flow +1 -1
- package/util/RelayReplaySubject.js.flow +3 -3
- package/util/RelayRuntimeTypes.js.flow +11 -11
- package/util/createPayloadFor3DField.js.flow +9 -5
- package/util/deepFreeze.js.flow +2 -2
- package/util/getFragmentIdentifier.js.flow +1 -1
- package/util/getPaginationMetadata.js.flow +1 -1
- package/util/getPaginationVariables.js.flow +1 -1
- package/util/getPendingOperationsForFragment.js.flow +2 -2
- package/util/getRefetchMetadata.js.flow +6 -5
- package/util/getValueAtPath.js.flow +3 -3
- package/util/handlePotentialSnapshotErrors.js.flow +5 -5
- package/util/isEmptyObject.js.flow +1 -1
- package/util/isPromise.js.flow +2 -2
- package/util/isScalarAndEqual.js.flow +1 -1
- package/util/recycleNodesInto.js.flow +2 -2
- package/util/registerEnvironmentWithDevTools.js.flow +1 -1
- package/util/shallowFreeze.js.flow +1 -1
- package/util/stableCopy.js.flow +5 -5
- package/util/withProvidedVariables.js.flow +14 -10
|
@@ -61,16 +61,16 @@ class RelayRecordProxy implements RecordProxy {
|
|
|
61
61
|
return type;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
getValue(name: string, args?: ?Arguments):
|
|
64
|
+
getValue(name: string, args?: ?Arguments): unknown {
|
|
65
65
|
const storageKey = getStableStorageKey(name, args);
|
|
66
66
|
return this._mutator.getValue(this._dataID, storageKey);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
setValue(
|
|
70
|
-
value:
|
|
70
|
+
value: unknown,
|
|
71
71
|
name: string,
|
|
72
72
|
args?: ?Arguments,
|
|
73
|
-
errors?:
|
|
73
|
+
errors?: ?ReadonlyArray<TRelayFieldError>,
|
|
74
74
|
): RecordProxy {
|
|
75
75
|
invariant(
|
|
76
76
|
isValidLeafValue(value),
|
|
@@ -82,10 +82,7 @@ class RelayRecordProxy implements RecordProxy {
|
|
|
82
82
|
return this.setValue__UNSAFE(value, name, args, errors);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
getErrors(
|
|
86
|
-
name: string,
|
|
87
|
-
args?: ?Arguments,
|
|
88
|
-
): ?$ReadOnlyArray<TRelayFieldError> {
|
|
85
|
+
getErrors(name: string, args?: ?Arguments): ?ReadonlyArray<TRelayFieldError> {
|
|
89
86
|
const storageKey = getStableStorageKey(name, args);
|
|
90
87
|
return this._mutator.getErrors(this._dataID, storageKey);
|
|
91
88
|
}
|
|
@@ -94,10 +91,10 @@ class RelayRecordProxy implements RecordProxy {
|
|
|
94
91
|
// We already validated that the value has the correct type
|
|
95
92
|
// so it should be safe to store complex structures as scalar values (custom scalars)
|
|
96
93
|
setValue__UNSAFE(
|
|
97
|
-
value:
|
|
94
|
+
value: unknown,
|
|
98
95
|
name: string,
|
|
99
96
|
args?: ?Arguments,
|
|
100
|
-
errors?:
|
|
97
|
+
errors?: ?ReadonlyArray<TRelayFieldError>,
|
|
101
98
|
): RecordProxy {
|
|
102
99
|
const storageKey = getStableStorageKey(name, args);
|
|
103
100
|
this._mutator.setValue(this._dataID, storageKey, value);
|
|
@@ -166,7 +163,7 @@ class RelayRecordProxy implements RecordProxy {
|
|
|
166
163
|
}
|
|
167
164
|
|
|
168
165
|
setLinkedRecords(
|
|
169
|
-
records:
|
|
166
|
+
records: ReadonlyArray<?RecordProxy>,
|
|
170
167
|
name: string,
|
|
171
168
|
args?: ?Arguments,
|
|
172
169
|
): RecordProxy {
|
|
@@ -186,7 +183,7 @@ class RelayRecordProxy implements RecordProxy {
|
|
|
186
183
|
}
|
|
187
184
|
}
|
|
188
185
|
|
|
189
|
-
function isValidLeafValue(value:
|
|
186
|
+
function isValidLeafValue(value: unknown): boolean {
|
|
190
187
|
return (
|
|
191
188
|
value == null ||
|
|
192
189
|
typeof value !== 'object' ||
|
|
@@ -161,7 +161,7 @@ class RelayRecordSourceMutator {
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
getValue(dataID: DataID, storageKey: string):
|
|
164
|
+
getValue(dataID: DataID, storageKey: string): unknown {
|
|
165
165
|
for (let ii = 0; ii < this.__sources.length; ii++) {
|
|
166
166
|
const record = this.__sources[ii].get(dataID);
|
|
167
167
|
if (record) {
|
|
@@ -175,7 +175,7 @@ class RelayRecordSourceMutator {
|
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
setValue(dataID: DataID, storageKey: string, value:
|
|
178
|
+
setValue(dataID: DataID, storageKey: string, value: unknown): void {
|
|
179
179
|
const sinkRecord = this._getSinkRecord(dataID);
|
|
180
180
|
RelayModernRecord.setValue(sinkRecord, storageKey, value);
|
|
181
181
|
}
|
|
@@ -183,7 +183,7 @@ class RelayRecordSourceMutator {
|
|
|
183
183
|
getErrors(
|
|
184
184
|
dataID: DataID,
|
|
185
185
|
storageKey: string,
|
|
186
|
-
):
|
|
186
|
+
): ?ReadonlyArray<TRelayFieldError> {
|
|
187
187
|
for (let ii = 0; ii < this.__sources.length; ii++) {
|
|
188
188
|
const record = this.__sources[ii].get(dataID);
|
|
189
189
|
if (record) {
|
|
@@ -200,7 +200,7 @@ class RelayRecordSourceMutator {
|
|
|
200
200
|
setErrors(
|
|
201
201
|
dataID: DataID,
|
|
202
202
|
storageKey: string,
|
|
203
|
-
errors?:
|
|
203
|
+
errors?: ReadonlyArray<TRelayFieldError>,
|
|
204
204
|
): void {
|
|
205
205
|
const sinkRecord = this._getSinkRecord(dataID);
|
|
206
206
|
RelayModernRecord.setErrors(sinkRecord, storageKey, errors);
|
|
@@ -53,14 +53,14 @@ class RelayRecordSourceProxy implements RecordSourceProxy {
|
|
|
53
53
|
_getDataID: GetDataID;
|
|
54
54
|
_invalidatedStore: boolean;
|
|
55
55
|
_idsMarkedForInvalidation: DataIDSet;
|
|
56
|
-
_missingFieldHandlers:
|
|
56
|
+
_missingFieldHandlers: ReadonlyArray<MissingFieldHandler>;
|
|
57
57
|
_log: LogFunction;
|
|
58
58
|
|
|
59
59
|
constructor(
|
|
60
60
|
mutator: RelayRecordSourceMutator,
|
|
61
61
|
getDataID: GetDataID,
|
|
62
62
|
handlerProvider?: ?HandlerProvider,
|
|
63
|
-
missingFieldHandlers:
|
|
63
|
+
missingFieldHandlers: ReadonlyArray<MissingFieldHandler>,
|
|
64
64
|
log: ?LogFunction,
|
|
65
65
|
) {
|
|
66
66
|
this.__mutator = mutator;
|
|
@@ -176,7 +176,7 @@ class RelayRecordSourceProxy implements RecordSourceProxy {
|
|
|
176
176
|
return this._idsMarkedForInvalidation;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
readUpdatableQuery<TVariables
|
|
179
|
+
readUpdatableQuery<TVariables extends Variables, TData>(
|
|
180
180
|
query: UpdatableQuery<TVariables, TData>,
|
|
181
181
|
variables: TVariables,
|
|
182
182
|
): UpdatableData<TData> {
|
|
@@ -188,7 +188,7 @@ class RelayRecordSourceProxy implements RecordSourceProxy {
|
|
|
188
188
|
);
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
readUpdatableFragment<TFragmentType
|
|
191
|
+
readUpdatableFragment<TFragmentType extends FragmentType, TData>(
|
|
192
192
|
fragment: UpdatableFragment<TFragmentType, TData>,
|
|
193
193
|
fragmentReference: HasUpdatableSpread<TFragmentType>,
|
|
194
194
|
): UpdatableData<TData> {
|
|
@@ -21,7 +21,7 @@ import type {
|
|
|
21
21
|
SingularReaderSelector,
|
|
22
22
|
UpdatableData,
|
|
23
23
|
} from '../store/RelayStoreTypes';
|
|
24
|
-
import type {ReaderLinkedField} from '../util/ReaderNode';
|
|
24
|
+
import type {ReaderLinkedField, ReaderSelection} from '../util/ReaderNode';
|
|
25
25
|
import type {
|
|
26
26
|
DataID,
|
|
27
27
|
UpdatableFragment,
|
|
@@ -47,13 +47,13 @@ class RelayRecordSourceSelectorProxy implements RecordSourceSelectorProxy {
|
|
|
47
47
|
__mutator: RelayRecordSourceMutator;
|
|
48
48
|
__recordSource: RecordSourceProxy;
|
|
49
49
|
_readSelector: SingularReaderSelector;
|
|
50
|
-
_missingFieldHandlers:
|
|
50
|
+
_missingFieldHandlers: ReadonlyArray<MissingFieldHandler>;
|
|
51
51
|
|
|
52
52
|
constructor(
|
|
53
53
|
mutator: RelayRecordSourceMutator,
|
|
54
54
|
recordSource: RecordSourceProxy,
|
|
55
55
|
readSelector: SingularReaderSelector,
|
|
56
|
-
missingFieldHandlers:
|
|
56
|
+
missingFieldHandlers: ReadonlyArray<MissingFieldHandler>,
|
|
57
57
|
) {
|
|
58
58
|
this.__mutator = mutator;
|
|
59
59
|
this.__recordSource = recordSource;
|
|
@@ -90,7 +90,7 @@ class RelayRecordSourceSelectorProxy implements RecordSourceSelectorProxy {
|
|
|
90
90
|
fieldName: string,
|
|
91
91
|
plural: boolean,
|
|
92
92
|
): ReaderLinkedField {
|
|
93
|
-
let field = selector.node.selections.find(
|
|
93
|
+
let field: ReaderSelection | void = selector.node.selections.find(
|
|
94
94
|
selection =>
|
|
95
95
|
(selection.kind === 'LinkedField' && selection.name === fieldName) ||
|
|
96
96
|
(selection.kind === 'RequiredField' &&
|
|
@@ -132,7 +132,7 @@ class RelayRecordSourceSelectorProxy implements RecordSourceSelectorProxy {
|
|
|
132
132
|
this.__recordSource.invalidateStore();
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
readUpdatableQuery<TVariables
|
|
135
|
+
readUpdatableQuery<TVariables extends Variables, TData>(
|
|
136
136
|
query: UpdatableQuery<TVariables, TData>,
|
|
137
137
|
variables: TVariables,
|
|
138
138
|
): UpdatableData<TData> {
|
|
@@ -144,7 +144,7 @@ class RelayRecordSourceSelectorProxy implements RecordSourceSelectorProxy {
|
|
|
144
144
|
);
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
readUpdatableFragment<TFragmentType
|
|
147
|
+
readUpdatableFragment<TFragmentType extends FragmentType, TData>(
|
|
148
148
|
fragment: UpdatableFragment<TFragmentType, TData>,
|
|
149
149
|
fragmentReference: HasUpdatableSpread<TFragmentType>,
|
|
150
150
|
): UpdatableData<TData> {
|
|
@@ -28,7 +28,7 @@ const {
|
|
|
28
28
|
const RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
29
29
|
const invariant = require('invariant');
|
|
30
30
|
|
|
31
|
-
export type OptimisticMutationConfig<TMutation
|
|
31
|
+
export type OptimisticMutationConfig<TMutation extends MutationParameters> = {
|
|
32
32
|
configs?: ?Array<DeclarativeMutationConfig>,
|
|
33
33
|
mutation: GraphQLTaggedNode,
|
|
34
34
|
variables: Variables,
|
|
@@ -40,7 +40,7 @@ export type OptimisticMutationConfig<TMutation: MutationParameters> = {
|
|
|
40
40
|
* Higher-level helper function to execute a mutation against a specific
|
|
41
41
|
* environment.
|
|
42
42
|
*/
|
|
43
|
-
function applyOptimisticMutation<TMutation
|
|
43
|
+
function applyOptimisticMutation<TMutation extends MutationParameters>(
|
|
44
44
|
environment: IEnvironment,
|
|
45
45
|
config: OptimisticMutationConfig<TMutation>,
|
|
46
46
|
): Disposable {
|
|
@@ -37,7 +37,7 @@ const validateMutation = require('./validateMutation');
|
|
|
37
37
|
const invariant = require('invariant');
|
|
38
38
|
const warning = require('warning');
|
|
39
39
|
|
|
40
|
-
export type MutationConfig<TMutation
|
|
40
|
+
export type MutationConfig<TMutation extends MutationParameters> = Readonly<{
|
|
41
41
|
cacheConfig?: CacheConfig,
|
|
42
42
|
configs?: Array<DeclarativeMutationConfig>,
|
|
43
43
|
mutation: GraphQLTaggedNode,
|
|
@@ -59,7 +59,7 @@ export type MutationConfig<TMutation: MutationParameters> = $ReadOnly<{
|
|
|
59
59
|
variables: TMutation['variables'],
|
|
60
60
|
}>;
|
|
61
61
|
|
|
62
|
-
export type CommitMutationConfig<TVariables, TData, TRawResponse> =
|
|
62
|
+
export type CommitMutationConfig<TVariables, TData, TRawResponse> = Readonly<{
|
|
63
63
|
cacheConfig?: CacheConfig,
|
|
64
64
|
configs?: Array<DeclarativeMutationConfig>,
|
|
65
65
|
mutation: Mutation<TVariables, TData, TRawResponse>,
|
|
@@ -78,7 +78,11 @@ export type CommitMutationConfig<TVariables, TData, TRawResponse> = $ReadOnly<{
|
|
|
78
78
|
* Higher-level helper function to execute a mutation against a specific
|
|
79
79
|
* environment.
|
|
80
80
|
*/
|
|
81
|
-
function commitMutation<
|
|
81
|
+
function commitMutation<
|
|
82
|
+
TVariables extends Variables,
|
|
83
|
+
TData,
|
|
84
|
+
TRawResponse = {...},
|
|
85
|
+
>(
|
|
82
86
|
environment: IEnvironment,
|
|
83
87
|
config: CommitMutationConfig<TVariables, TData, TRawResponse>,
|
|
84
88
|
): Disposable {
|
|
@@ -122,7 +126,7 @@ function commitMutation<TVariables: Variables, TData, TRawResponse = {...}>(
|
|
|
122
126
|
if (configs) {
|
|
123
127
|
({optimisticUpdater, updater} = RelayDeclarativeMutationConfig.convert<{
|
|
124
128
|
variables: TVariables,
|
|
125
|
-
/* $FlowFixMe[incompatible-
|
|
129
|
+
/* $FlowFixMe[incompatible-type] error exposed when improving flow typing
|
|
126
130
|
* of commitMutation */
|
|
127
131
|
response: TData,
|
|
128
132
|
}>(configs, mutation, optimisticUpdater, updater));
|
|
@@ -131,7 +135,7 @@ function commitMutation<TVariables: Variables, TData, TRawResponse = {...}>(
|
|
|
131
135
|
const subscription = environment
|
|
132
136
|
.executeMutation<{
|
|
133
137
|
variables: TVariables,
|
|
134
|
-
/* $FlowFixMe[incompatible-
|
|
138
|
+
/* $FlowFixMe[incompatible-type] error exposed when improving flow typing
|
|
135
139
|
* of commitMutation */
|
|
136
140
|
response: TData,
|
|
137
141
|
}>({
|
|
@@ -142,6 +146,17 @@ function commitMutation<TVariables: Variables, TData, TRawResponse = {...}>(
|
|
|
142
146
|
uploadables,
|
|
143
147
|
})
|
|
144
148
|
.subscribe({
|
|
149
|
+
complete: () => {
|
|
150
|
+
const {onCompleted} = config;
|
|
151
|
+
if (onCompleted) {
|
|
152
|
+
const snapshot = environment.lookup(operation.fragment);
|
|
153
|
+
onCompleted(
|
|
154
|
+
snapshot.data as $FlowFixMe,
|
|
155
|
+
errors.length !== 0 ? errors : null,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
error: onError,
|
|
145
160
|
next: payload => {
|
|
146
161
|
if (Array.isArray(payload)) {
|
|
147
162
|
payload.forEach(item => {
|
|
@@ -156,17 +171,6 @@ function commitMutation<TVariables: Variables, TData, TRawResponse = {...}>(
|
|
|
156
171
|
}
|
|
157
172
|
config.onNext?.();
|
|
158
173
|
},
|
|
159
|
-
complete: () => {
|
|
160
|
-
const {onCompleted} = config;
|
|
161
|
-
if (onCompleted) {
|
|
162
|
-
const snapshot = environment.lookup(operation.fragment);
|
|
163
|
-
onCompleted(
|
|
164
|
-
(snapshot.data: $FlowFixMe),
|
|
165
|
-
errors.length !== 0 ? errors : null,
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
error: onError,
|
|
170
174
|
unsubscribe: onUnsubscribe,
|
|
171
175
|
});
|
|
172
176
|
return {dispose: subscription.unsubscribe};
|
|
@@ -27,12 +27,12 @@ const {getArgumentValues} = require('../store/RelayStoreUtils');
|
|
|
27
27
|
|
|
28
28
|
const nonUpdatableKeys = ['id', '__id', '__typename', 'js'];
|
|
29
29
|
|
|
30
|
-
function createUpdatableProxy<TData
|
|
30
|
+
function createUpdatableProxy<TData extends {...}>(
|
|
31
31
|
updatableProxyRootRecord: RecordProxy,
|
|
32
32
|
variables: Variables,
|
|
33
|
-
selections:
|
|
33
|
+
selections: ReadonlyArray<ReaderSelection>,
|
|
34
34
|
recordSourceProxy: RecordSourceProxy,
|
|
35
|
-
missingFieldHandlers:
|
|
35
|
+
missingFieldHandlers: ReadonlyArray<MissingFieldHandler>,
|
|
36
36
|
): TData {
|
|
37
37
|
const mutableUpdatableProxy = {};
|
|
38
38
|
updateProxyFromSelections(
|
|
@@ -49,16 +49,16 @@ function createUpdatableProxy<TData: {...}>(
|
|
|
49
49
|
// unless ReaderSelection carries more type information, we will never be able
|
|
50
50
|
// to flowtype mutableUpdatableProxy without a type assertion.
|
|
51
51
|
// $FlowFixMe[unclear-type]
|
|
52
|
-
return
|
|
52
|
+
return mutableUpdatableProxy as any as TData;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
function updateProxyFromSelections<TData>(
|
|
56
56
|
mutableUpdatableProxy: TData,
|
|
57
57
|
updatableProxyRootRecord: RecordProxy,
|
|
58
58
|
variables: Variables,
|
|
59
|
-
selections:
|
|
59
|
+
selections: ReadonlyArray<ReaderSelection>,
|
|
60
60
|
recordSourceProxy: RecordSourceProxy,
|
|
61
|
-
missingFieldHandlers:
|
|
61
|
+
missingFieldHandlers: ReadonlyArray<MissingFieldHandler>,
|
|
62
62
|
): void {
|
|
63
63
|
for (const selection of selections) {
|
|
64
64
|
switch (selection.kind) {
|
|
@@ -108,7 +108,7 @@ function updateProxyFromSelections<TData>(
|
|
|
108
108
|
case 'ScalarField':
|
|
109
109
|
const scalarFieldName = selection.alias ?? selection.name;
|
|
110
110
|
Object.defineProperty(mutableUpdatableProxy, scalarFieldName, {
|
|
111
|
-
get
|
|
111
|
+
get() {
|
|
112
112
|
const newVariables = getArgumentValues(
|
|
113
113
|
selection.args ?? [],
|
|
114
114
|
variables,
|
|
@@ -191,7 +191,7 @@ function updateProxyFromSelections<TData>(
|
|
|
191
191
|
'Encountered an unexpected ReaderSelection variant in RelayRecordSourceProxy. This indicates a bug in Relay.',
|
|
192
192
|
);
|
|
193
193
|
default:
|
|
194
|
-
|
|
194
|
+
selection.kind as empty;
|
|
195
195
|
throw new Error(
|
|
196
196
|
'Encountered an unexpected ReaderSelection variant in RelayRecordSourceProxy. This indicates a bug in Relay.',
|
|
197
197
|
);
|
|
@@ -205,7 +205,7 @@ function createSetterForPluralLinkedField(
|
|
|
205
205
|
updatableProxyRootRecord: RecordProxy,
|
|
206
206
|
recordSourceProxy: RecordSourceProxy,
|
|
207
207
|
) {
|
|
208
|
-
return function set(newValue:
|
|
208
|
+
return function set(newValue: ReadonlyArray<{__id: string, ...}>) {
|
|
209
209
|
const newVariables = getArgumentValues(selection.args ?? [], variables);
|
|
210
210
|
if (newValue == null) {
|
|
211
211
|
throw new Error(
|
|
@@ -276,7 +276,7 @@ function createGetterForPluralLinkedField(
|
|
|
276
276
|
variables: Variables,
|
|
277
277
|
updatableProxyRootRecord: RecordProxy,
|
|
278
278
|
recordSourceProxy: RecordSourceProxy,
|
|
279
|
-
missingFieldHandlers:
|
|
279
|
+
missingFieldHandlers: ReadonlyArray<MissingFieldHandler>,
|
|
280
280
|
): () => $FlowFixMe {
|
|
281
281
|
return function () {
|
|
282
282
|
const newVariables = getArgumentValues(selection.args ?? [], variables);
|
|
@@ -296,7 +296,7 @@ function createGetterForPluralLinkedField(
|
|
|
296
296
|
}
|
|
297
297
|
|
|
298
298
|
if (linkedRecords != null) {
|
|
299
|
-
return
|
|
299
|
+
return linkedRecords.map(linkedRecord => {
|
|
300
300
|
if (linkedRecord != null) {
|
|
301
301
|
const updatableProxy = {};
|
|
302
302
|
updateProxyFromSelections(
|
|
@@ -313,12 +313,12 @@ function createGetterForPluralLinkedField(
|
|
|
313
313
|
// Flow incorrect assumes that the return value for the get method must match
|
|
314
314
|
// the set parameter.
|
|
315
315
|
// $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
316
|
-
return
|
|
316
|
+
return updatableProxy as any;
|
|
317
317
|
} else {
|
|
318
318
|
return linkedRecord;
|
|
319
319
|
}
|
|
320
320
|
// $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
321
|
-
})
|
|
321
|
+
}) as any;
|
|
322
322
|
} else {
|
|
323
323
|
return linkedRecords;
|
|
324
324
|
}
|
|
@@ -330,7 +330,7 @@ function createGetterForSingularLinkedField(
|
|
|
330
330
|
variables: Variables,
|
|
331
331
|
updatableProxyRootRecord: RecordProxy,
|
|
332
332
|
recordSourceProxy: RecordSourceProxy,
|
|
333
|
-
missingFieldHandlers:
|
|
333
|
+
missingFieldHandlers: ReadonlyArray<MissingFieldHandler>,
|
|
334
334
|
): () => ?$FlowFixMe {
|
|
335
335
|
return function () {
|
|
336
336
|
const newVariables = getArgumentValues(selection.args ?? [], variables);
|
|
@@ -364,7 +364,7 @@ function createGetterForSingularLinkedField(
|
|
|
364
364
|
// Flow incorrect assumes that the return value for the get method must match
|
|
365
365
|
// the set parameter.
|
|
366
366
|
// $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
367
|
-
return
|
|
367
|
+
return updatableProxy as any;
|
|
368
368
|
} else {
|
|
369
369
|
return linkedRecord;
|
|
370
370
|
}
|
|
@@ -376,7 +376,7 @@ function getLinkedRecordUsingMissingFieldHandlers(
|
|
|
376
376
|
newVariables: Variables,
|
|
377
377
|
updatableProxyRootRecord: RecordProxy,
|
|
378
378
|
recordSourceProxy: RecordSourceProxy,
|
|
379
|
-
missingFieldHandlers:
|
|
379
|
+
missingFieldHandlers: ReadonlyArray<MissingFieldHandler>,
|
|
380
380
|
): ?RecordProxy {
|
|
381
381
|
for (const handler of missingFieldHandlers) {
|
|
382
382
|
if (handler.kind === 'linked') {
|
|
@@ -398,7 +398,7 @@ function getPluralLinkedRecordUsingMissingFieldHandlers(
|
|
|
398
398
|
newVariables: Variables,
|
|
399
399
|
updatableProxyRootRecord: RecordProxy,
|
|
400
400
|
recordSourceProxy: RecordSourceProxy,
|
|
401
|
-
missingFieldHandlers:
|
|
401
|
+
missingFieldHandlers: ReadonlyArray<MissingFieldHandler>,
|
|
402
402
|
): ?Array<?RecordProxy> {
|
|
403
403
|
for (const handler of missingFieldHandlers) {
|
|
404
404
|
if (handler.kind === 'pluralLinked') {
|
|
@@ -424,8 +424,8 @@ function getScalarUsingMissingFieldHandlers(
|
|
|
424
424
|
newVariables: Variables,
|
|
425
425
|
updatableProxyRootRecord: RecordProxy,
|
|
426
426
|
recordSourceProxy: RecordSourceProxy,
|
|
427
|
-
missingFieldHandlers:
|
|
428
|
-
):
|
|
427
|
+
missingFieldHandlers: ReadonlyArray<MissingFieldHandler>,
|
|
428
|
+
): unknown {
|
|
429
429
|
for (const handler of missingFieldHandlers) {
|
|
430
430
|
if (handler.kind === 'scalar') {
|
|
431
431
|
const value = handler.handle(
|
|
@@ -27,11 +27,11 @@ const {createUpdatableProxy} = require('./createUpdatableProxy');
|
|
|
27
27
|
const invariant = require('invariant');
|
|
28
28
|
|
|
29
29
|
// Note: plural fragment references are currently not supported
|
|
30
|
-
function readUpdatableFragment<TFragmentType
|
|
30
|
+
function readUpdatableFragment<TFragmentType extends FragmentType, TData>(
|
|
31
31
|
fragment: UpdatableFragment<TFragmentType, TData>,
|
|
32
32
|
fragmentReference: HasUpdatableSpread<TFragmentType>,
|
|
33
33
|
proxy: RecordSourceProxy,
|
|
34
|
-
missingFieldHandlers:
|
|
34
|
+
missingFieldHandlers: ReadonlyArray<MissingFieldHandler>,
|
|
35
35
|
): UpdatableData<TData> {
|
|
36
36
|
const updatableFragment = getFragment(fragment);
|
|
37
37
|
const fragmentVariables = getVariablesFromFragment(
|
|
@@ -48,7 +48,7 @@ function readUpdatableFragment<TFragmentType: FragmentType, TData>(
|
|
|
48
48
|
);
|
|
49
49
|
|
|
50
50
|
return {
|
|
51
|
-
// $FlowFixMe[incompatible-
|
|
51
|
+
// $FlowFixMe[incompatible-type]
|
|
52
52
|
updatableData: createUpdatableProxy<TData>(
|
|
53
53
|
fragmentRoot,
|
|
54
54
|
fragmentVariables,
|
|
@@ -21,16 +21,16 @@ import type {UpdatableQuery, Variables} from '../util/RelayRuntimeTypes';
|
|
|
21
21
|
const {getUpdatableQuery} = require('../query/GraphQLTag');
|
|
22
22
|
const {createUpdatableProxy} = require('./createUpdatableProxy');
|
|
23
23
|
|
|
24
|
-
function readUpdatableQuery<TVariables
|
|
24
|
+
function readUpdatableQuery<TVariables extends Variables, TData>(
|
|
25
25
|
query: UpdatableQuery<TVariables, TData>,
|
|
26
26
|
variables: TVariables,
|
|
27
27
|
proxy: RecordSourceProxy,
|
|
28
|
-
missingFieldHandlers:
|
|
28
|
+
missingFieldHandlers: ReadonlyArray<MissingFieldHandler>,
|
|
29
29
|
): UpdatableData<TData> {
|
|
30
30
|
const updatableQuery = getUpdatableQuery(query);
|
|
31
31
|
|
|
32
32
|
return {
|
|
33
|
-
// $FlowFixMe[incompatible-
|
|
33
|
+
// $FlowFixMe[incompatible-type]
|
|
34
34
|
updatableData: createUpdatableProxy<TData>(
|
|
35
35
|
proxy.getRoot(),
|
|
36
36
|
variables,
|
|
@@ -62,12 +62,12 @@ if (__DEV__) {
|
|
|
62
62
|
) => {
|
|
63
63
|
const operationName = mutation.operation.name;
|
|
64
64
|
const context: ValidationContext = {
|
|
65
|
-
path: 'ROOT',
|
|
66
|
-
visitedPaths: new Set(),
|
|
67
|
-
variables: variables || {},
|
|
68
|
-
missingDiff: {},
|
|
69
65
|
extraDiff: {},
|
|
66
|
+
missingDiff: {},
|
|
70
67
|
moduleImportPaths: new Set(),
|
|
68
|
+
path: 'ROOT',
|
|
69
|
+
variables: variables || {},
|
|
70
|
+
visitedPaths: new Set(),
|
|
71
71
|
};
|
|
72
72
|
validateSelections(
|
|
73
73
|
optimisticResponse,
|
|
@@ -91,7 +91,7 @@ if (__DEV__) {
|
|
|
91
91
|
|
|
92
92
|
const validateSelections = (
|
|
93
93
|
optimisticResponse: Object,
|
|
94
|
-
selections:
|
|
94
|
+
selections: ReadonlyArray<NormalizationSelection>,
|
|
95
95
|
context: ValidationContext,
|
|
96
96
|
) => {
|
|
97
97
|
selections.forEach(selection =>
|
|
@@ -156,7 +156,7 @@ if (__DEV__) {
|
|
|
156
156
|
return;
|
|
157
157
|
}
|
|
158
158
|
default:
|
|
159
|
-
|
|
159
|
+
selection as empty;
|
|
160
160
|
return;
|
|
161
161
|
}
|
|
162
162
|
};
|
|
@@ -261,4 +261,4 @@ if (__DEV__) {
|
|
|
261
261
|
};
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
-
module.exports =
|
|
264
|
+
module.exports = validateMutation as (Object, ConcreteRequest, ?Object) => void;
|
|
@@ -24,9 +24,9 @@ export interface INetwork {
|
|
|
24
24
|
+execute: ExecuteFunction;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export type LogRequestInfoFunction =
|
|
27
|
+
export type LogRequestInfoFunction = unknown => void;
|
|
28
28
|
|
|
29
|
-
export type PayloadData = {+[key: string]:
|
|
29
|
+
export type PayloadData = {+[key: string]: unknown};
|
|
30
30
|
|
|
31
31
|
export type PayloadError = interface {
|
|
32
32
|
message: string,
|
|
@@ -40,7 +40,7 @@ export type PayloadError = interface {
|
|
|
40
40
|
severity?: 'CRITICAL' | 'ERROR' | 'WARNING',
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
export type PayloadExtensions = {[key: string]:
|
|
43
|
+
export type PayloadExtensions = {[key: string]: unknown, ...};
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* The shape of a GraphQL response as dictated by the
|
|
@@ -82,7 +82,7 @@ export type GraphQLSingularResponse =
|
|
|
82
82
|
|
|
83
83
|
export type GraphQLResponse =
|
|
84
84
|
| GraphQLSingularResponse
|
|
85
|
-
|
|
|
85
|
+
| ReadonlyArray<GraphQLSingularResponse>;
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
88
|
* A function that pre-process the response at the network layer. This
|
|
@@ -23,7 +23,7 @@ export type Subscription = {
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
type SubscriptionFn = {
|
|
26
|
-
():
|
|
26
|
+
(): unknown,
|
|
27
27
|
+unsubscribe?: void,
|
|
28
28
|
+closed?: void,
|
|
29
29
|
...
|
|
@@ -34,11 +34,11 @@ type SubscriptionFn = {
|
|
|
34
34
|
* .subscribe(). Each callback function is invoked when that event occurs.
|
|
35
35
|
*/
|
|
36
36
|
export type Observer<-T> = {
|
|
37
|
-
+start?: ?(Subscription) =>
|
|
38
|
-
+next?: ?(T) =>
|
|
39
|
-
+error?: ?(Error) =>
|
|
40
|
-
+complete?: ?() =>
|
|
41
|
-
+unsubscribe?: ?(Subscription) =>
|
|
37
|
+
+start?: ?(Subscription) => unknown,
|
|
38
|
+
+next?: ?(T) => unknown,
|
|
39
|
+
+error?: ?(Error) => unknown,
|
|
40
|
+
+complete?: ?() => unknown,
|
|
41
|
+
+unsubscribe?: ?(Subscription) => unknown,
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
/**
|
|
@@ -74,7 +74,7 @@ export interface Subscribable<+T> {
|
|
|
74
74
|
export type ObservableFromValue<+T> = Subscribable<T> | Promise<T> | T;
|
|
75
75
|
|
|
76
76
|
let hostReportError:
|
|
77
|
-
| ((Error, isUncaughtThrownError: boolean) =>
|
|
77
|
+
| ((Error, isUncaughtThrownError: boolean) => unknown)
|
|
78
78
|
| ((_error: Error, _isUncaughtThrownError: boolean) => void) = swallowError;
|
|
79
79
|
|
|
80
80
|
/**
|
|
@@ -92,7 +92,7 @@ class RelayObservable<+T> implements Subscribable<T> {
|
|
|
92
92
|
+_source: Source<T>;
|
|
93
93
|
|
|
94
94
|
static create<V>(source: Source<V>): RelayObservable<V> {
|
|
95
|
-
return new RelayObservable(
|
|
95
|
+
return new RelayObservable(source as any);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
// Use RelayObservable.create()
|
|
@@ -103,7 +103,7 @@ class RelayObservable<+T> implements Subscribable<T> {
|
|
|
103
103
|
throw new Error('Source must be a Function: ' + String(source));
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
(this
|
|
106
|
+
(this as any)._source = source;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
/**
|
|
@@ -132,7 +132,7 @@ class RelayObservable<+T> implements Subscribable<T> {
|
|
|
132
132
|
* stack traces.
|
|
133
133
|
*/
|
|
134
134
|
static onUnhandledError(
|
|
135
|
-
callback: (Error, isUncaughtThrownError: boolean) =>
|
|
135
|
+
callback: (Error, isUncaughtThrownError: boolean) => unknown,
|
|
136
136
|
): void {
|
|
137
137
|
hostReportError = callback;
|
|
138
138
|
}
|
|
@@ -247,7 +247,7 @@ class RelayObservable<+T> implements Subscribable<T> {
|
|
|
247
247
|
*
|
|
248
248
|
* This is useful for cleanup such as resource finalization.
|
|
249
249
|
*/
|
|
250
|
-
finally(fn: () =>
|
|
250
|
+
finally(fn: () => unknown): RelayObservable<T> {
|
|
251
251
|
return RelayObservable.create(sink => {
|
|
252
252
|
const subscription = this.subscribe(sink);
|
|
253
253
|
return () => {
|
|
@@ -351,6 +351,8 @@ class RelayObservable<+T> implements Subscribable<T> {
|
|
|
351
351
|
}
|
|
352
352
|
|
|
353
353
|
function complete(this: ObservableContext) {
|
|
354
|
+
/* $FlowFixMe[incompatible-type] Error exposed after improved typing of
|
|
355
|
+
* Array.{includes,indexOf,lastIndexOf} */
|
|
354
356
|
subscriptions.splice(subscriptions.indexOf(this._sub), 1);
|
|
355
357
|
if (subscriptions.length === 0) {
|
|
356
358
|
sink.complete();
|
|
@@ -445,9 +447,9 @@ class RelayObservable<+T> implements Subscribable<T> {
|
|
|
445
447
|
}
|
|
446
448
|
|
|
447
449
|
// Use declarations to teach Flow how to check isObservable.
|
|
448
|
-
declare function isObservable<T>(obj:
|
|
450
|
+
declare function isObservable<T>(obj: unknown): obj is Subscribable<T>;
|
|
449
451
|
|
|
450
|
-
function isObservable(obj:
|
|
452
|
+
function isObservable(obj: unknown) {
|
|
451
453
|
return (
|
|
452
454
|
typeof obj === 'object' &&
|
|
453
455
|
obj !== null &&
|
|
@@ -490,7 +492,7 @@ function subscribe<T>(
|
|
|
490
492
|
// Relay to be used within will support property getters, and many minifier
|
|
491
493
|
// tools still do not support ES5 syntax. Instead, we can use defineProperty.
|
|
492
494
|
const withClosed: <O>(obj: O) => {...O, +closed: boolean} = (obj =>
|
|
493
|
-
Object.defineProperty(obj, 'closed',
|
|
495
|
+
Object.defineProperty(obj, 'closed', {get: () => closed} as any)) as any;
|
|
494
496
|
|
|
495
497
|
function doCleanup() {
|
|
496
498
|
if (cleanup) {
|
|
@@ -77,16 +77,16 @@ class RelayQueryResponseCache {
|
|
|
77
77
|
...payload.extensions,
|
|
78
78
|
cacheTimestamp: response.fetchTime,
|
|
79
79
|
},
|
|
80
|
-
}
|
|
80
|
+
}) as GraphQLSingularResponse,
|
|
81
81
|
);
|
|
82
82
|
}
|
|
83
|
-
return
|
|
83
|
+
return {
|
|
84
84
|
...response.payload,
|
|
85
85
|
extensions: {
|
|
86
86
|
...response.payload.extensions,
|
|
87
87
|
cacheTimestamp: response.fetchTime,
|
|
88
88
|
},
|
|
89
|
-
}
|
|
89
|
+
} as GraphQLSingularResponse;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
set(queryID: string, variables: Variables, payload: GraphQLResponse): void {
|