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.
Files changed (262) hide show
  1. package/experimental.js +1 -1
  2. package/experimental.js.flow +8 -8
  3. package/handlers/connection/ConnectionHandler.js.flow +5 -5
  4. package/handlers/connection/ConnectionInterface.js.flow +1 -1
  5. package/index.js +1 -1
  6. package/index.js.flow +125 -62
  7. package/lib/experimental.js +3 -3
  8. package/lib/index.js +105 -57
  9. package/lib/multi-actor-environment/ActorIdentifier.js +2 -2
  10. package/lib/multi-actor-environment/MultiActorEnvironment.js +3 -1
  11. package/lib/mutations/commitMutation.js +8 -8
  12. package/lib/mutations/validateMutation.js +4 -4
  13. package/lib/query/GraphQLTag.js +3 -3
  14. package/lib/query/fetchQuery.js +15 -3
  15. package/lib/store/DataChecker.js +38 -4
  16. package/lib/store/NormalizationEngine.js +373 -0
  17. package/lib/store/OperationExecutor.js +172 -113
  18. package/lib/store/RelayConcreteVariables.js +1 -1
  19. package/lib/store/RelayErrorTrie.js +2 -2
  20. package/lib/store/RelayExperimentalGraphResponseTransform.js +8 -8
  21. package/lib/store/RelayModernEnvironment.js +26 -19
  22. package/lib/store/RelayModernRecord.js +18 -8
  23. package/lib/store/RelayModernSelector.js +9 -9
  24. package/lib/store/RelayModernStore.js +152 -43
  25. package/lib/store/RelayPublishQueue.js +1 -1
  26. package/lib/store/RelayReader.js +76 -38
  27. package/lib/store/RelayRecordSource.js +6 -0
  28. package/lib/store/RelayReferenceMarker.js +2 -1
  29. package/lib/store/RelayResponseNormalizer.js +88 -55
  30. package/lib/store/RelayStoreSubscriptions.js +34 -10
  31. package/lib/store/RelayStoreUtils.js +8 -1
  32. package/lib/store/ResolverFragments.js +2 -2
  33. package/lib/store/live-resolvers/LiveResolverCache.js +25 -9
  34. package/lib/store/observeFragmentExperimental.js +17 -1
  35. package/lib/store/observeQueryExperimental.js +2 -2
  36. package/lib/subscription/requestSubscription.js +3 -3
  37. package/lib/util/RelayError.js +3 -0
  38. package/lib/util/RelayFeatureFlags.js +6 -2
  39. package/lib/util/RelayReplaySubject.js +4 -4
  40. package/lib/util/handlePotentialSnapshotErrors.js +2 -2
  41. package/lib/util/stableCopy.js +2 -2
  42. package/llm-docs/api-reference/entrypoint-apis/entrypoint-container.mdx +38 -0
  43. package/llm-docs/api-reference/entrypoint-apis/load-entrypoint.mdx +77 -0
  44. package/llm-docs/api-reference/entrypoint-apis/use-entrypoint-loader.mdx +99 -0
  45. package/llm-docs/api-reference/graphql/graphql-directives.mdx +378 -0
  46. package/llm-docs/api-reference/hooks/_use-lazy-load-query-extra.mdx +16 -0
  47. package/llm-docs/api-reference/hooks/load-query.mdx +84 -0
  48. package/llm-docs/api-reference/hooks/relay-environment-provider.mdx +78 -0
  49. package/llm-docs/api-reference/hooks/use-client-query.mdx +65 -0
  50. package/llm-docs/api-reference/hooks/use-fragment.mdx +69 -0
  51. package/llm-docs/api-reference/hooks/use-lazy-load-query.mdx +62 -0
  52. package/llm-docs/api-reference/hooks/use-mutation.mdx +94 -0
  53. package/llm-docs/api-reference/hooks/use-pagination-fragment.mdx +166 -0
  54. package/llm-docs/api-reference/hooks/use-prefetchable-forward-pagination-fragment.mdx +134 -0
  55. package/llm-docs/api-reference/hooks/use-preloaded-query.mdx +84 -0
  56. package/llm-docs/api-reference/hooks/use-query-loader.mdx +95 -0
  57. package/llm-docs/api-reference/hooks/use-refetchable-fragment.mdx +122 -0
  58. package/llm-docs/api-reference/hooks/use-relay-environment.mdx +37 -0
  59. package/llm-docs/api-reference/hooks/use-subscription.mdx +66 -0
  60. package/llm-docs/api-reference/relay-resolvers/docblock-format.mdx +321 -0
  61. package/llm-docs/api-reference/relay-resolvers/runtime-functions.mdx +94 -0
  62. package/llm-docs/api-reference/relay-runtime/commit-mutation.mdx +65 -0
  63. package/llm-docs/api-reference/relay-runtime/fetch-query.mdx +113 -0
  64. package/llm-docs/api-reference/relay-runtime/field-logger.mdx +170 -0
  65. package/llm-docs/api-reference/relay-runtime/observe-fragment.mdx +92 -0
  66. package/llm-docs/api-reference/relay-runtime/relay-environment.mdx +53 -0
  67. package/llm-docs/api-reference/relay-runtime/request-subscription.mdx +54 -0
  68. package/llm-docs/api-reference/relay-runtime/runtime-configuration.mdx +52 -0
  69. package/llm-docs/api-reference/relay-runtime/store.mdx +734 -0
  70. package/llm-docs/api-reference/relay-runtime/wait-for-fragment-data.mdx +89 -0
  71. package/llm-docs/api-reference/types/CacheConfig.mdx +8 -0
  72. package/llm-docs/api-reference/types/Disposable.mdx +4 -0
  73. package/llm-docs/api-reference/types/GraphQLSubscriptionConfig.mdx +17 -0
  74. package/llm-docs/api-reference/types/MutationConfig.mdx +31 -0
  75. package/llm-docs/api-reference/types/SelectorStoreUpdater.mdx +6 -0
  76. package/llm-docs/api-reference/types/UploadableMap.mdx +3 -0
  77. package/llm-docs/community/learning-resources.mdx +64 -0
  78. package/llm-docs/debugging/declarative-mutation-directives.mdx +34 -0
  79. package/llm-docs/debugging/disallowed-id-types-error.mdx +43 -0
  80. package/llm-docs/debugging/inconsistent-typename-error.mdx +47 -0
  81. package/llm-docs/debugging/relay-devtools.mdx +73 -0
  82. package/llm-docs/debugging/why-null.mdx +116 -0
  83. package/llm-docs/editor-support.mdx +55 -0
  84. package/llm-docs/error-reference/unknown-field.mdx +36 -0
  85. package/llm-docs/getting-started/babel-plugin.mdx +31 -0
  86. package/llm-docs/getting-started/compiler-config.mdx +25 -0
  87. package/llm-docs/getting-started/compiler.mdx +82 -0
  88. package/llm-docs/getting-started/lint-rules.mdx +87 -0
  89. package/llm-docs/getting-started/production.mdx +30 -0
  90. package/llm-docs/getting-started/quick-start.mdx +213 -0
  91. package/llm-docs/glossary/glossary.mdx +1040 -0
  92. package/llm-docs/guided-tour/list-data/advanced-pagination.mdx +157 -0
  93. package/llm-docs/guided-tour/list-data/connections.mdx +81 -0
  94. package/llm-docs/guided-tour/list-data/pagination.mdx +193 -0
  95. package/llm-docs/guided-tour/list-data/rendering-connections.mdx +112 -0
  96. package/llm-docs/guided-tour/list-data/streaming-pagination.mdx +87 -0
  97. package/llm-docs/guided-tour/managing-data-outside-react/retaining-queries.mdx +51 -0
  98. package/llm-docs/guided-tour/refetching/refetching-queries-with-different-data.mdx +337 -0
  99. package/llm-docs/guided-tour/refetching/refreshing-queries.mdx +350 -0
  100. package/llm-docs/guided-tour/rendering/environment.mdx +59 -0
  101. package/llm-docs/guided-tour/rendering/error-states.mdx +295 -0
  102. package/llm-docs/guided-tour/rendering/fragments.mdx +354 -0
  103. package/llm-docs/guided-tour/rendering/loading-states.mdx +245 -0
  104. package/llm-docs/guided-tour/rendering/queries.mdx +261 -0
  105. package/llm-docs/guided-tour/rendering/variables.mdx +233 -0
  106. package/llm-docs/guided-tour/reusing-cached-data/fetch-policies.mdx +56 -0
  107. package/llm-docs/guided-tour/reusing-cached-data/filling-in-missing-data.mdx +102 -0
  108. package/llm-docs/guided-tour/reusing-cached-data/introduction.mdx +22 -0
  109. package/llm-docs/guided-tour/reusing-cached-data/presence-of-data.mdx +93 -0
  110. package/llm-docs/guided-tour/reusing-cached-data/rendering-partially-cached-data.mdx +175 -0
  111. package/llm-docs/guided-tour/reusing-cached-data/staleness-of-data.mdx +116 -0
  112. package/llm-docs/guided-tour/updating-data/client-only-data.mdx +115 -0
  113. package/llm-docs/guided-tour/updating-data/graphql-mutations.mdx +334 -0
  114. package/llm-docs/guided-tour/updating-data/graphql-subscriptions.mdx +279 -0
  115. package/llm-docs/guided-tour/updating-data/imperatively-modifying-linked-fields.mdx +511 -0
  116. package/llm-docs/guided-tour/updating-data/imperatively-modifying-store-data-legacy.mdx +142 -0
  117. package/llm-docs/guided-tour/updating-data/imperatively-modifying-store-data.mdx +275 -0
  118. package/llm-docs/guided-tour/updating-data/introduction.mdx +25 -0
  119. package/llm-docs/guided-tour/updating-data/local-data-updates.mdx +71 -0
  120. package/llm-docs/guided-tour/updating-data/typesafe-updaters-faq.mdx +83 -0
  121. package/llm-docs/guided-tour/updating-data/updating-connections.mdx +592 -0
  122. package/llm-docs/guides/alias-directive.mdx +160 -0
  123. package/llm-docs/guides/catch-directive.mdx +167 -0
  124. package/llm-docs/guides/client-schema-extensions.mdx +208 -0
  125. package/llm-docs/guides/codemods.mdx +66 -0
  126. package/llm-docs/guides/data-driven-dependencies/client-3d.mdx +255 -0
  127. package/llm-docs/guides/data-driven-dependencies/configuration.mdx +127 -0
  128. package/llm-docs/guides/data-driven-dependencies/introduction.mdx +39 -0
  129. package/llm-docs/guides/data-driven-dependencies/server-3d.mdx +664 -0
  130. package/llm-docs/guides/document-comparison.mdx +106 -0
  131. package/llm-docs/guides/graphql-server-specification.mdx +453 -0
  132. package/llm-docs/guides/network-layer.mdx +69 -0
  133. package/llm-docs/guides/persisted-queries.mdx +328 -0
  134. package/llm-docs/guides/relay-resolvers/context.mdx +99 -0
  135. package/llm-docs/guides/relay-resolvers/defining-fields.mdx +151 -0
  136. package/llm-docs/guides/relay-resolvers/defining-types.mdx +164 -0
  137. package/llm-docs/guides/relay-resolvers/deprecated.mdx +27 -0
  138. package/llm-docs/guides/relay-resolvers/derived-fields.mdx +127 -0
  139. package/llm-docs/guides/relay-resolvers/descriptions.mdx +44 -0
  140. package/llm-docs/guides/relay-resolvers/enabling.mdx +41 -0
  141. package/llm-docs/guides/relay-resolvers/errors.mdx +64 -0
  142. package/llm-docs/guides/relay-resolvers/field-arguments.mdx +63 -0
  143. package/llm-docs/guides/relay-resolvers/introduction.mdx +62 -0
  144. package/llm-docs/guides/relay-resolvers/limitations.mdx +30 -0
  145. package/llm-docs/guides/relay-resolvers/live-fields.mdx +164 -0
  146. package/llm-docs/guides/relay-resolvers/return-types.mdx +161 -0
  147. package/llm-docs/guides/relay-resolvers/suspense.mdx +41 -0
  148. package/llm-docs/guides/required-directive.mdx +240 -0
  149. package/llm-docs/guides/semantic-nullability.mdx +93 -0
  150. package/llm-docs/guides/testing-relay-components.mdx +642 -0
  151. package/llm-docs/guides/testing-relay-with-preloaded-queries.mdx +160 -0
  152. package/llm-docs/guides/throw-on-field-error-directive.mdx +58 -0
  153. package/llm-docs/guides/type-emission.mdx +414 -0
  154. package/llm-docs/home.mdx +32 -0
  155. package/llm-docs/principles-and-architecture/architecture-overview.mdx +24 -0
  156. package/llm-docs/principles-and-architecture/compiler-architecture.mdx +106 -0
  157. package/llm-docs/principles-and-architecture/runtime-architecture.mdx +249 -0
  158. package/llm-docs/principles-and-architecture/thinking-in-graphql.mdx +309 -0
  159. package/llm-docs/principles-and-architecture/thinking-in-relay.mdx +104 -0
  160. package/llm-docs/principles-and-architecture/videos.mdx +50 -0
  161. package/llm-docs/tutorial/arrays-lists.mdx +126 -0
  162. package/llm-docs/tutorial/fragments-1.mdx +487 -0
  163. package/llm-docs/tutorial/graphql.mdx +172 -0
  164. package/llm-docs/tutorial/interfaces-polymorphism.mdx +161 -0
  165. package/llm-docs/tutorial/intro.mdx +58 -0
  166. package/llm-docs/tutorial/mutations-updates.mdx +624 -0
  167. package/llm-docs/tutorial/organizing-mutations-queries-and-subscriptions.mdx +13 -0
  168. package/llm-docs/tutorial/queries-1.mdx +267 -0
  169. package/llm-docs/tutorial/queries-2.mdx +389 -0
  170. package/llm-docs/tutorial/refetchable-fragments.mdx +352 -0
  171. package/multi-actor-environment/ActorIdentifier.js.flow +2 -2
  172. package/multi-actor-environment/ActorSpecificEnvironment.js.flow +7 -7
  173. package/multi-actor-environment/ActorUtils.js.flow +1 -1
  174. package/multi-actor-environment/MultiActorEnvironment.js.flow +12 -8
  175. package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +3 -3
  176. package/mutations/RelayDeclarativeMutationConfig.js.flow +9 -9
  177. package/mutations/RelayRecordProxy.js.flow +8 -11
  178. package/mutations/RelayRecordSourceMutator.js.flow +4 -4
  179. package/mutations/RelayRecordSourceProxy.js.flow +4 -4
  180. package/mutations/RelayRecordSourceSelectorProxy.js.flow +6 -6
  181. package/mutations/applyOptimisticMutation.js.flow +2 -2
  182. package/mutations/commitMutation.js.flow +20 -16
  183. package/mutations/createUpdatableProxy.js.flow +19 -19
  184. package/mutations/readUpdatableFragment.js.flow +3 -3
  185. package/mutations/readUpdatableQuery.js.flow +3 -3
  186. package/mutations/validateMutation.js.flow +7 -7
  187. package/network/RelayNetworkTypes.js.flow +4 -4
  188. package/network/RelayObservable.js.flow +16 -14
  189. package/network/RelayQueryResponseCache.js.flow +3 -3
  190. package/network/wrapNetworkWithLogObserver.js.flow +1 -1
  191. package/package.json +2 -1
  192. package/query/GraphQLTag.js.flow +22 -10
  193. package/query/fetchQuery.js.flow +23 -10
  194. package/query/fetchQuery_DEPRECATED.js.flow +1 -1
  195. package/store/DataChecker.js.flow +43 -9
  196. package/store/NormalizationEngine.js.flow +779 -0
  197. package/store/OperationExecutor.js.flow +173 -70
  198. package/store/RelayConcreteVariables.js.flow +5 -5
  199. package/store/RelayErrorTrie.js.flow +12 -12
  200. package/store/RelayExperimentalGraphResponseHandler.js.flow +3 -3
  201. package/store/RelayExperimentalGraphResponseTransform.js.flow +10 -10
  202. package/store/RelayModernEnvironment.js.flow +41 -26
  203. package/store/RelayModernFragmentSpecResolver.js.flow +1 -1
  204. package/store/RelayModernOperationDescriptor.js.flow +1 -1
  205. package/store/RelayModernRecord.js.flow +44 -20
  206. package/store/RelayModernSelector.js.flow +21 -21
  207. package/store/RelayModernStore.js.flow +219 -58
  208. package/store/RelayOperationTracker.js.flow +2 -2
  209. package/store/RelayOptimisticRecordSource.js.flow +2 -2
  210. package/store/RelayPublishQueue.js.flow +21 -12
  211. package/store/RelayReader.js.flow +129 -57
  212. package/store/RelayRecordSource.js.flow +10 -0
  213. package/store/RelayRecordState.js.flow +1 -1
  214. package/store/RelayReferenceMarker.js.flow +5 -4
  215. package/store/RelayResponseNormalizer.js.flow +125 -57
  216. package/store/RelayStoreSubscriptions.js.flow +52 -8
  217. package/store/RelayStoreTypes.js.flow +153 -64
  218. package/store/RelayStoreUtils.js.flow +15 -7
  219. package/store/ResolverCache.js.flow +2 -2
  220. package/store/ResolverFragments.js.flow +12 -12
  221. package/store/StoreInspector.js.flow +6 -7
  222. package/store/cloneRelayHandleSourceField.js.flow +1 -1
  223. package/store/cloneRelayScalarHandleSourceField.js.flow +1 -1
  224. package/store/createRelayContext.js.flow +1 -1
  225. package/store/createRelayLoggingContext.js.flow +4 -4
  226. package/store/defaultGetDataID.js.flow +2 -2
  227. package/store/isRelayModernEnvironment.js.flow +4 -2
  228. package/store/live-resolvers/LiveResolverCache.js.flow +55 -20
  229. package/store/live-resolvers/LiveResolverSuspenseSentinel.js.flow +3 -3
  230. package/store/live-resolvers/getOutputTypeRecordIDs.js.flow +1 -1
  231. package/store/live-resolvers/isLiveStateValue.js.flow +2 -2
  232. package/store/live-resolvers/resolverDataInjector.js.flow +8 -5
  233. package/store/observeFragmentExperimental.js.flow +49 -20
  234. package/store/observeQueryExperimental.js.flow +5 -5
  235. package/store/readInlineData.js.flow +4 -4
  236. package/store/waitForFragmentExperimental.js.flow +3 -3
  237. package/subscription/requestSubscription.js.flow +7 -7
  238. package/util/NormalizationNode.js.flow +34 -32
  239. package/util/ReaderNode.js.flow +32 -30
  240. package/util/RelayConcreteNode.js.flow +5 -5
  241. package/util/RelayError.js.flow +4 -1
  242. package/util/RelayFeatureFlags.js.flow +21 -1
  243. package/util/RelayProfiler.js.flow +1 -1
  244. package/util/RelayReplaySubject.js.flow +3 -3
  245. package/util/RelayRuntimeTypes.js.flow +11 -11
  246. package/util/createPayloadFor3DField.js.flow +9 -5
  247. package/util/deepFreeze.js.flow +2 -2
  248. package/util/getFragmentIdentifier.js.flow +1 -1
  249. package/util/getPaginationMetadata.js.flow +1 -1
  250. package/util/getPaginationVariables.js.flow +1 -1
  251. package/util/getPendingOperationsForFragment.js.flow +2 -2
  252. package/util/getRefetchMetadata.js.flow +6 -5
  253. package/util/getValueAtPath.js.flow +3 -3
  254. package/util/handlePotentialSnapshotErrors.js.flow +5 -5
  255. package/util/isEmptyObject.js.flow +1 -1
  256. package/util/isPromise.js.flow +2 -2
  257. package/util/isScalarAndEqual.js.flow +1 -1
  258. package/util/recycleNodesInto.js.flow +2 -2
  259. package/util/registerEnvironmentWithDevTools.js.flow +1 -1
  260. package/util/shallowFreeze.js.flow +1 -1
  261. package/util/stableCopy.js.flow +5 -5
  262. package/util/withProvidedVariables.js.flow +14 -10
@@ -9,6 +9,7 @@ var RelayReader = require('./RelayReader');
9
9
  var RelayStoreSubscriptions = /*#__PURE__*/function () {
10
10
  function RelayStoreSubscriptions(log, resolverCache, resolverContext) {
11
11
  this._subscriptions = new Set();
12
+ this._staleSubscriptions = new Set();
12
13
  this.__log = log;
13
14
  this._resolverCache = resolverCache;
14
15
  this._resolverContext = resolverContext;
@@ -24,6 +25,9 @@ var RelayStoreSubscriptions = /*#__PURE__*/function () {
24
25
  };
25
26
  var dispose = function dispose() {
26
27
  _this._subscriptions["delete"](subscription);
28
+ if (RelayFeatureFlags.OPTIMIZE_NOTIFY && subscription.stale) {
29
+ _this._staleSubscriptions["delete"](subscription);
30
+ }
27
31
  };
28
32
  this._subscriptions.add(subscription);
29
33
  return {
@@ -38,39 +42,56 @@ var RelayStoreSubscriptions = /*#__PURE__*/function () {
38
42
  return;
39
43
  }
40
44
  var snapshot = subscription.snapshot;
41
- var backup = RelayReader.read(source, snapshot.selector, _this2._resolverCache, _this2._resolverContext);
45
+ var backup = RelayReader.read(source, snapshot.selector, _this2.__log, _this2._resolverCache, _this2._resolverContext);
42
46
  var nextData = recycleNodesInto(snapshot.data, backup.data);
43
47
  backup.data = nextData;
44
48
  subscription.backup = backup;
45
49
  });
46
50
  };
47
51
  _proto.restoreSubscriptions = function restoreSubscriptions() {
52
+ var _this3 = this;
48
53
  this._subscriptions.forEach(function (subscription) {
49
54
  var backup = subscription.backup;
50
55
  subscription.backup = null;
51
56
  if (backup) {
52
57
  if (backup.data !== subscription.snapshot.data) {
53
58
  subscription.stale = true;
59
+ if (RelayFeatureFlags.OPTIMIZE_NOTIFY) {
60
+ _this3._staleSubscriptions.add(subscription);
61
+ }
54
62
  }
55
63
  subscription.snapshot = {
56
64
  data: subscription.snapshot.data,
65
+ fieldErrors: backup.fieldErrors,
57
66
  isMissingData: backup.isMissingData,
58
67
  missingClientEdges: backup.missingClientEdges,
59
68
  missingLiveResolverFields: backup.missingLiveResolverFields,
60
69
  seenRecords: backup.seenRecords,
61
- selector: backup.selector,
62
- fieldErrors: backup.fieldErrors
70
+ selector: backup.selector
63
71
  };
64
72
  } else {
65
73
  subscription.stale = true;
74
+ if (RelayFeatureFlags.OPTIMIZE_NOTIFY) {
75
+ _this3._staleSubscriptions.add(subscription);
76
+ }
66
77
  }
67
78
  });
68
79
  };
69
80
  _proto.updateSubscriptions = function updateSubscriptions(source, updatedRecordIDs, updatedOwners, sourceOperation) {
70
- var _this3 = this;
81
+ var _this4 = this;
71
82
  var hasUpdatedRecords = updatedRecordIDs.size !== 0;
72
83
  this._subscriptions.forEach(function (subscription) {
73
- var owner = _this3._updateSubscription(source, subscription, updatedRecordIDs, hasUpdatedRecords, sourceOperation);
84
+ var owner = _this4._updateSubscription(source, subscription, updatedRecordIDs, hasUpdatedRecords, sourceOperation);
85
+ if (owner != null) {
86
+ updatedOwners.push(owner);
87
+ }
88
+ });
89
+ };
90
+ _proto.updateStaleSubscriptions = function updateStaleSubscriptions(source, updatedRecordIDs, updatedOwners, sourceOperation) {
91
+ var _this5 = this;
92
+ var hasUpdatedRecords = updatedRecordIDs.size !== 0;
93
+ this._staleSubscriptions.forEach(function (subscription) {
94
+ var owner = _this5._updateSubscription(source, subscription, updatedRecordIDs, hasUpdatedRecords, sourceOperation);
74
95
  if (owner != null) {
75
96
  updatedOwners.push(owner);
76
97
  }
@@ -85,29 +106,32 @@ var RelayStoreSubscriptions = /*#__PURE__*/function () {
85
106
  if (!stale && !hasOverlappingUpdates) {
86
107
  return;
87
108
  }
88
- var nextSnapshot = hasOverlappingUpdates || !backup ? RelayReader.read(source, snapshot.selector, this._resolverCache, this._resolverContext) : backup;
109
+ var nextSnapshot = hasOverlappingUpdates || !backup ? RelayReader.read(source, snapshot.selector, this.__log, this._resolverCache, this._resolverContext) : backup;
89
110
  var nextData = recycleNodesInto(snapshot.data, nextSnapshot.data);
90
111
  nextSnapshot = {
91
112
  data: nextData,
113
+ fieldErrors: nextSnapshot.fieldErrors,
92
114
  isMissingData: nextSnapshot.isMissingData,
93
115
  missingClientEdges: nextSnapshot.missingClientEdges,
94
116
  missingLiveResolverFields: nextSnapshot.missingLiveResolverFields,
95
117
  seenRecords: nextSnapshot.seenRecords,
96
- selector: nextSnapshot.selector,
97
- fieldErrors: nextSnapshot.fieldErrors
118
+ selector: nextSnapshot.selector
98
119
  };
99
120
  if (process.env.NODE_ENV !== "production") {
100
121
  deepFreeze(nextSnapshot);
101
122
  }
102
123
  subscription.snapshot = nextSnapshot;
103
124
  subscription.stale = false;
125
+ if (RelayFeatureFlags.OPTIMIZE_NOTIFY && stale) {
126
+ this._staleSubscriptions["delete"](subscription);
127
+ }
104
128
  if (nextSnapshot.data !== snapshot.data) {
105
129
  if (this.__log && RelayFeatureFlags.ENABLE_NOTIFY_SUBSCRIPTION) {
106
130
  this.__log({
107
131
  name: 'store.notify.subscription',
108
- sourceOperation: sourceOperation,
132
+ nextSnapshot: nextSnapshot,
109
133
  snapshot: snapshot,
110
- nextSnapshot: nextSnapshot
134
+ sourceOperation: sourceOperation
111
135
  });
112
136
  }
113
137
  callback(nextSnapshot);
@@ -13,6 +13,7 @@ var VARIABLE = RelayConcreteNode.VARIABLE,
13
13
  OBJECT_VALUE = RelayConcreteNode.OBJECT_VALUE,
14
14
  LIST_VALUE = RelayConcreteNode.LIST_VALUE;
15
15
  var ERRORS_KEY = '__errors';
16
+ var FIELD_GRANULAR_NOTIFICATIONS_KEY = '__fieldGranularNotifications';
16
17
  var MODULE_COMPONENT_KEY_PREFIX = '__module_component_';
17
18
  var MODULE_OPERATION_KEY_PREFIX = '__module_operation_';
18
19
  var RELAY_READ_TIME_RESOLVER_KEY_PREFIX = '$r:';
@@ -126,6 +127,9 @@ function getModuleComponentKey(documentName) {
126
127
  function getModuleOperationKey(documentName) {
127
128
  return "".concat(MODULE_OPERATION_KEY_PREFIX).concat(documentName);
128
129
  }
130
+ function getFieldNotificationKey(dataID, storageKey) {
131
+ return "__fn:".concat(dataID, ":").concat(storageKey);
132
+ }
129
133
  var RelayStoreUtils = {
130
134
  ACTOR_IDENTIFIER_KEY: '__actorIdentifier',
131
135
  CLIENT_EDGE_TRAVERSAL_PATH: '__clientEdgeTraversalPath',
@@ -135,6 +139,7 @@ var RelayStoreUtils = {
135
139
  FRAGMENT_PROP_NAME_KEY: '__fragmentPropName',
136
140
  MODULE_COMPONENT_KEY: '__module_component',
137
141
  ERRORS_KEY: ERRORS_KEY,
142
+ FIELD_GRANULAR_NOTIFICATIONS_KEY: FIELD_GRANULAR_NOTIFICATIONS_KEY,
138
143
  ID_KEY: '__id',
139
144
  REF_KEY: '__ref',
140
145
  REFS_KEY: '__refs',
@@ -147,6 +152,7 @@ var RelayStoreUtils = {
147
152
  RELAY_RESOLVER_SNAPSHOT_KEY: '__resolverSnapshot',
148
153
  RELAY_RESOLVER_ERROR_KEY: '__resolverError',
149
154
  RELAY_RESOLVER_OUTPUT_TYPE_RECORD_IDS: '__resolverOutputTypeRecordIDs',
155
+ RELAY_RESOLVER_RECORD_TYPENAME: '__RELAY_RESOLVER__',
150
156
  RELAY_READ_TIME_RESOLVER_KEY_PREFIX: RELAY_READ_TIME_RESOLVER_KEY_PREFIX,
151
157
  formatStorageKey: formatStorageKey,
152
158
  getArgumentValue: getArgumentValue,
@@ -156,6 +162,7 @@ var RelayStoreUtils = {
156
162
  getReadTimeResolverStorageKey: getReadTimeResolverStorageKey,
157
163
  getStableStorageKey: getStableStorageKey,
158
164
  getModuleComponentKey: getModuleComponentKey,
159
- getModuleOperationKey: getModuleOperationKey
165
+ getModuleOperationKey: getModuleOperationKey,
166
+ getFieldNotificationKey: getFieldNotificationKey
160
167
  };
161
168
  module.exports = RelayStoreUtils;
@@ -36,7 +36,7 @@ function readFragment(fragmentInput, fragmentKey) {
36
36
  }
37
37
  var RESOLVER_FRAGMENT_ERRORED_SENTINEL = {};
38
38
  module.exports = {
39
+ RESOLVER_FRAGMENT_ERRORED_SENTINEL: RESOLVER_FRAGMENT_ERRORED_SENTINEL,
39
40
  readFragment: readFragment,
40
- withResolverContext: withResolverContext,
41
- RESOLVER_FRAGMENT_ERRORED_SENTINEL: RESOLVER_FRAGMENT_ERRORED_SENTINEL
41
+ withResolverContext: withResolverContext
42
42
  };
@@ -20,6 +20,7 @@ var _require5 = require('../RelayStoreUtils'),
20
20
  RELAY_RESOLVER_ERROR_KEY = _require5.RELAY_RESOLVER_ERROR_KEY,
21
21
  RELAY_RESOLVER_INVALIDATION_KEY = _require5.RELAY_RESOLVER_INVALIDATION_KEY,
22
22
  RELAY_RESOLVER_OUTPUT_TYPE_RECORD_IDS = _require5.RELAY_RESOLVER_OUTPUT_TYPE_RECORD_IDS,
23
+ RELAY_RESOLVER_RECORD_TYPENAME = _require5.RELAY_RESOLVER_RECORD_TYPENAME,
23
24
  RELAY_RESOLVER_SNAPSHOT_KEY = _require5.RELAY_RESOLVER_SNAPSHOT_KEY,
24
25
  RELAY_RESOLVER_VALUE_KEY = _require5.RELAY_RESOLVER_VALUE_KEY,
25
26
  getReadTimeResolverStorageKey = _require5.getReadTimeResolverStorageKey,
@@ -33,7 +34,6 @@ var warning = require("fbjs/lib/warning");
33
34
  var RELAY_RESOLVER_LIVE_STATE_SUBSCRIPTION_KEY = '__resolverLiveStateSubscription';
34
35
  var RELAY_RESOLVER_LIVE_STATE_VALUE = '__resolverLiveStateValue';
35
36
  var RELAY_RESOLVER_LIVE_STATE_DIRTY = '__resolverLiveStateDirty';
36
- var RELAY_RESOLVER_RECORD_TYPENAME = '__RELAY_RESOLVER__';
37
37
  var MODEL_PROPERTY_NAME = '__relay_model_instance';
38
38
  function addDependencyEdge(edges, from, to) {
39
39
  var set = edges.get(from);
@@ -204,6 +204,21 @@ var LiveResolverCache = /*#__PURE__*/function () {
204
204
  this._handlingBatch = false;
205
205
  }
206
206
  };
207
+ _proto.batchLiveStateUpdatesWithoutNotify = function batchLiveStateUpdatesWithoutNotify(callback) {
208
+ !!this._handlingBatch ? process.env.NODE_ENV !== "production" ? invariant(false, 'Unexpected nested call to batchLiveStateUpdates.') : invariant(false) : void 0;
209
+ this._handlingBatch = true;
210
+ try {
211
+ callback();
212
+ } finally {
213
+ var shouldPublish = this._liveResolverBatchRecordSource != null;
214
+ if (shouldPublish) {
215
+ this._store.publish(this._liveResolverBatchRecordSource);
216
+ }
217
+ this._liveResolverBatchRecordSource = null;
218
+ this._handlingBatch = false;
219
+ return shouldPublish;
220
+ }
221
+ };
207
222
  _proto._setLiveResolverValue = function _setLiveResolverValue(resolverRecord, liveValue, field, variables) {
208
223
  var value = null;
209
224
  var resolverError = null;
@@ -278,6 +293,7 @@ var LiveResolverCache = /*#__PURE__*/function () {
278
293
  } else {
279
294
  shallowFreeze(value);
280
295
  RelayModernRecord.setValue(resolverRecord, RELAY_RESOLVER_VALUE_KEY, value);
296
+ RelayModernRecord.setValue(resolverRecord, RELAY_RESOLVER_OUTPUT_TYPE_RECORD_IDS, new Set());
281
297
  }
282
298
  return updatedDataIDs;
283
299
  };
@@ -514,20 +530,20 @@ function unsubscribeFromLiveResolverRecordsImpl(recordSource, invalidatedDataIDs
514
530
  if (invalidatedDataIDs.size === 0) {
515
531
  return;
516
532
  }
517
- var _iterator10 = (0, _createForOfIteratorHelper2["default"])(invalidatedDataIDs),
518
- _step10;
533
+ var _iterator0 = (0, _createForOfIteratorHelper2["default"])(invalidatedDataIDs),
534
+ _step0;
519
535
  try {
520
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
521
- var dataID = _step10.value;
536
+ for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
537
+ var dataID = _step0.value;
522
538
  var record = recordSource.get(dataID);
523
539
  if (record != null && isResolverRecord(record)) {
524
540
  maybeUnsubscribeFromLiveState(record);
525
541
  }
526
542
  }
527
543
  } catch (err) {
528
- _iterator10.e(err);
544
+ _iterator0.e(err);
529
545
  } finally {
530
- _iterator10.f();
546
+ _iterator0.f();
531
547
  }
532
548
  }
533
549
  function isResolverRecord(record) {
@@ -555,6 +571,6 @@ function getConcreteTypename(normalizationInfo, currentValue) {
555
571
  }
556
572
  module.exports = {
557
573
  LiveResolverCache: LiveResolverCache,
558
- getUpdatedDataIDs: getUpdatedDataIDs,
559
- RELAY_RESOLVER_LIVE_STATE_SUBSCRIPTION_KEY: RELAY_RESOLVER_LIVE_STATE_SUBSCRIPTION_KEY
574
+ RELAY_RESOLVER_LIVE_STATE_SUBSCRIPTION_KEY: RELAY_RESOLVER_LIVE_STATE_SUBSCRIPTION_KEY,
575
+ getUpdatedDataIDs: getUpdatedDataIDs
560
576
  };
@@ -46,8 +46,8 @@ function observeFragment(environment, fragment, fragmentRef) {
46
46
  var _fragmentNode$metadat;
47
47
  var fragmentNode = getFragment(fragment);
48
48
  var fragmentSelector = getSelector(fragmentNode, fragmentRef);
49
- !(((_fragmentNode$metadat = fragmentNode.metadata) === null || _fragmentNode$metadat === void 0 ? void 0 : _fragmentNode$metadat.hasClientEdges) == null) ? process.env.NODE_ENV !== "production" ? invariant(false, "Client edges aren't supported yet.") : invariant(false) : void 0;
50
49
  !(fragmentSelector != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected a selector, got null.') : invariant(false) : void 0;
50
+ !(((_fragmentNode$metadat = fragmentNode.metadata) === null || _fragmentNode$metadat === void 0 ? void 0 : _fragmentNode$metadat.hasClientEdges) == null || fragmentSelectorUsesExecTimeResolver(fragmentSelector)) ? process.env.NODE_ENV !== "production" ? invariant(false, "Client edges aren't supported yet.") : invariant(false) : void 0;
51
51
  switch (fragmentSelector.kind) {
52
52
  case 'SingularReaderSelector':
53
53
  return observeSingularSelector(environment, fragment, fragmentSelector);
@@ -58,6 +58,22 @@ function observeFragment(environment, fragment, fragmentRef) {
58
58
  }
59
59
  !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'Unsupported fragment selector kind') : invariant(false) : void 0;
60
60
  }
61
+ function fragmentSelectorUsesExecTimeResolver(fragmentSelector) {
62
+ var _fragmentSelector$own, _fragmentSelector$own2, _fragmentSelector$own3, _fragmentSelector$own4;
63
+ switch (fragmentSelector === null || fragmentSelector === void 0 ? void 0 : fragmentSelector.kind) {
64
+ case 'SingularReaderSelector':
65
+ return ((_fragmentSelector$own = (_fragmentSelector$own2 = fragmentSelector.owner.node.operation) === null || _fragmentSelector$own2 === void 0 ? void 0 : _fragmentSelector$own2.use_exec_time_resolvers) !== null && _fragmentSelector$own !== void 0 ? _fragmentSelector$own : (_fragmentSelector$own3 = fragmentSelector.owner.node.operation) === null || _fragmentSelector$own3 === void 0 ? void 0 : (_fragmentSelector$own4 = _fragmentSelector$own3.exec_time_resolvers_enabled_provider) === null || _fragmentSelector$own4 === void 0 ? void 0 : _fragmentSelector$own4.get()) === true;
66
+ case 'PluralReaderSelector':
67
+ {
68
+ var _fragmentSelector$sel;
69
+ return (_fragmentSelector$sel = fragmentSelector.selectors) === null || _fragmentSelector$sel === void 0 ? void 0 : _fragmentSelector$sel.every(function (selector) {
70
+ var _selector$owner$node$, _selector$owner$node$2, _selector$owner$node$3;
71
+ return ((_selector$owner$node$ = selector.owner.node.operation.use_exec_time_resolvers) !== null && _selector$owner$node$ !== void 0 ? _selector$owner$node$ : (_selector$owner$node$2 = selector.owner.node.operation) === null || _selector$owner$node$2 === void 0 ? void 0 : (_selector$owner$node$3 = _selector$owner$node$2.exec_time_resolvers_enabled_provider) === null || _selector$owner$node$3 === void 0 ? void 0 : _selector$owner$node$3.get()) === true;
72
+ });
73
+ }
74
+ }
75
+ return false;
76
+ }
61
77
  function observeSingularSelector(environment, fragmentNode, fragmentSelector) {
62
78
  var snapshot = environment.lookup(fragmentSelector);
63
79
  return Observable.create(function (sink) {
@@ -9,9 +9,9 @@ var _require2 = require('./RelayModernOperationDescriptor'),
9
9
  function observeQuery(environment, gqlQuery, variables) {
10
10
  var operation = createOperationDescriptor(gqlQuery, variables);
11
11
  var rootFragmentRef = {
12
- __id: operation.fragment.dataID,
12
+ __fragmentOwner: operation.request,
13
13
  __fragments: (0, _defineProperty2["default"])({}, operation.fragment.node.name, operation.request.variables),
14
- __fragmentOwner: operation.request
14
+ __id: operation.fragment.dataID
15
15
  };
16
16
  var fragmentNode = operation.request.node.fragment;
17
17
  return observeFragment(environment, fragmentNode, rootFragmentRef);
@@ -27,6 +27,8 @@ function requestSubscription(environment, config) {
27
27
  operation: operation,
28
28
  updater: updater
29
29
  }).subscribe({
30
+ complete: onCompleted,
31
+ error: onError,
30
32
  next: function next(responses) {
31
33
  if (onNext != null) {
32
34
  var selector = operation.fragment;
@@ -44,9 +46,7 @@ function requestSubscription(environment, config) {
44
46
  var data = environment.lookup(selector).data;
45
47
  onNext(data);
46
48
  }
47
- },
48
- error: onError,
49
- complete: onCompleted
49
+ }
50
50
  });
51
51
  return {
52
52
  dispose: sub.unsubscribe
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  function createError(type, name, messageFormat) {
4
+ var _messageParams$;
4
5
  for (var _len = arguments.length, messageParams = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
5
6
  messageParams[_key - 3] = arguments[_key];
6
7
  }
@@ -9,11 +10,13 @@ function createError(type, name, messageFormat) {
9
10
  return String(messageParams[index++]);
10
11
  });
11
12
  var err = new Error(message);
13
+ var operation = (_messageParams$ = messageParams[2]) !== null && _messageParams$ !== void 0 ? _messageParams$ : null;
12
14
  var error = Object.assign(err, {
13
15
  name: name,
14
16
  messageFormat: messageFormat,
15
17
  messageParams: messageParams,
16
18
  type: type,
19
+ operation: operation,
17
20
  taalOpcodes: [2, 2]
18
21
  });
19
22
  if (error.stack === undefined) {
@@ -20,12 +20,16 @@ var RelayFeatureFlags = {
20
20
  PROCESS_OPTIMISTIC_UPDATE_BEFORE_SUBSCRIPTION: false,
21
21
  MARK_RESOLVER_VALUES_AS_CLEAN_AFTER_FRAGMENT_REREAD: false,
22
22
  ENABLE_CYLE_DETECTION_IN_VARIABLES: false,
23
- ENABLE_ACTIVITY_COMPATIBILITY: false,
23
+ ENABLE_ACTIVITY_COMPATIBILITY: true,
24
24
  ENABLE_READ_TIME_RESOLVER_STORAGE_KEY_PREFIX: true,
25
25
  ENABLE_USE_PAGINATION_IS_LOADING_FIX: false,
26
26
  DISALLOW_NESTED_UPDATES: false,
27
27
  ENABLE_TYPENAME_PREFIXED_DATA_ID: false,
28
28
  ENABLE_UI_CONTEXT_ON_RELAY_LOGGER: false,
29
- CHECK_ALL_FRAGMENTS_FOR_MISSING_CLIENT_EDGES: false
29
+ CHECK_ALL_FRAGMENTS_FOR_MISSING_CLIENT_EDGES: false,
30
+ FILTER_OUT_RELAY_RESOLVER_RECORDS: false,
31
+ OPTIMIZE_NOTIFY: false,
32
+ ENABLE_FIELD_GRANULAR_NOTIFICATIONS: false,
33
+ ENABLE_READER_FRAGMENTS_LOGGING: false
30
34
  };
31
35
  module.exports = RelayFeatureFlags;
@@ -59,8 +59,8 @@ var RelayReplaySubject = /*#__PURE__*/function () {
59
59
  }
60
60
  this._complete = true;
61
61
  this._events.push({
62
- kind: 'error',
63
- error: _error
62
+ error: _error,
63
+ kind: 'error'
64
64
  });
65
65
  this._sinks.forEach(function (sink) {
66
66
  return sink.error(_error);
@@ -71,8 +71,8 @@ var RelayReplaySubject = /*#__PURE__*/function () {
71
71
  return;
72
72
  }
73
73
  this._events.push({
74
- kind: 'next',
75
- data: data
74
+ data: data,
75
+ kind: 'next'
76
76
  });
77
77
  this._sinks.forEach(function (sink) {
78
78
  return sink.next(data);
@@ -71,6 +71,6 @@ function handlePotentialSnapshotErrors(environment, fieldErrors, loggingContext)
71
71
  }
72
72
  }
73
73
  module.exports = {
74
- handlePotentialSnapshotErrors: handlePotentialSnapshotErrors,
75
- eventShouldThrow: eventShouldThrow
74
+ eventShouldThrow: eventShouldThrow,
75
+ handlePotentialSnapshotErrors: handlePotentialSnapshotErrors
76
76
  };
@@ -30,6 +30,6 @@ function hasCycle(value) {
30
30
  });
31
31
  }
32
32
  module.exports = {
33
- stableCopy: stableCopy,
34
- hasCycle: hasCycle
33
+ hasCycle: hasCycle,
34
+ stableCopy: stableCopy
35
35
  };
@@ -0,0 +1,38 @@
1
+ ---
2
+ id: entrypoint-container
3
+ title: EntryPointContainer
4
+ slug: /api-reference/entrypoint-container/
5
+ description: API reference for EntryPointContainer, a React component used to render the root component of an entrypoint
6
+ keywords:
7
+ - entrypoint
8
+ - container
9
+ - root
10
+ ---
11
+
12
+ import DocsRating from '@site/src/core/DocsRating';
13
+ import {OssOnly, FbInternalOnly} from 'docusaurus-plugin-internaldocs-fb/internal';
14
+
15
+ ## `EntryPointContainer`
16
+
17
+ <FbInternalOnly>
18
+
19
+ For more information, see the [Defining EntryPoints](../../guides/entrypoints/using-entrypoints/#defining-entrypoints) and [Consuming EntryPoints](../../guides/entrypoints/using-entrypoints/#-entrypoints) guides.
20
+
21
+ </FbInternalOnly>
22
+
23
+ ```js
24
+ function EntryPointContainer({
25
+ entryPointReference,
26
+ props,
27
+ }: {
28
+ +entryPointReference: PreloadedEntryPoint<TEntryPointComponent>,
29
+ +props: TRuntimeProps,
30
+ }): ReactElement
31
+ ```
32
+
33
+ A React component that renders a preloaded EntryPoint.
34
+
35
+ * `entryPointReference`: the value returned from a call to `loadEntryPoint` or acquired from the `useEntryPointLoader` hook.
36
+ * `props`: additional runtime props that will be passed to the `Component`
37
+
38
+ <DocsRating />
@@ -0,0 +1,77 @@
1
+ ---
2
+ id: load-entrypoint
3
+ title: loadEntryPoint
4
+ slug: /api-reference/load-entrypoint/
5
+ description: API reference for loadEntryPoint, which imperatively loads an entrypoint and data for its queries
6
+ keywords:
7
+ - entrypoint
8
+ - preload
9
+ - render-as-you-fetch
10
+ ---
11
+
12
+ import DocsRating from '@site/src/core/DocsRating';
13
+ import {OssOnly, FbInternalOnly} from 'docusaurus-plugin-internaldocs-fb/internal';
14
+
15
+ ## `loadEntryPoint`
16
+
17
+ This function is designed to be used with `EntryPointContainer` to implement the "render-as-you-fetch" pattern.
18
+
19
+ EntryPoint references returned from `loadEntryPoint` will leak data to the Relay store (if they have associated queries) unless `.dispose()` is called on them once they are no longer referenced. As such, prefer using `useEntryPointLoader` when possible, which ensures that EntryPoint references are correctly disposed for you. See the [`useEntryPointLoader`](../use-entrypoint-loader) docs for a more complete example.
20
+
21
+ <FbInternalOnly>
22
+
23
+ For more information, see the [Loading EntryPoints](../../guides/entrypoints/using-entrypoints/#loading-entrypoints) guide.
24
+
25
+ </FbInternalOnly>
26
+
27
+ ```js
28
+ const EntryPoint = require('MyComponent.entrypoint.js');
29
+
30
+ const {loadQuery} = require('react-relay');
31
+
32
+ // Generally, your component should access the environment from the React context,
33
+ // and pass that environment to this function.
34
+ const getEntrypointReference = environment => loadEntryPoint(
35
+ { getEnvironment: () => environment },
36
+ EntryPoint,
37
+ {id: '4'},
38
+ );
39
+
40
+ // later: pass entryPointReference to EntryPointContainer
41
+ // Note that EntryPoint references should have .dispose() called on them,
42
+ // which is missing in this example.
43
+ ```
44
+
45
+ ### Arguments
46
+
47
+ * `environmentProvider`: A provider for a Relay Environment instance on which to execute the request. If you're starting this request somewhere within a React component, you probably want to use the environment you obtain from using [`useRelayEnvironment`](../use-relay-environment/).
48
+ * `EntryPoint`: EntryPoint to load.
49
+ * `entryPointParams`: Parameters that will be passed to the EntryPoint's `getPreloadProps` method.
50
+
51
+ ### Flow Type Parameters
52
+
53
+ * `TEntryPointParams`: Type parameter corresponding to the type of the first parameter of the `getPreloadProps` method of the EntryPoint.
54
+ * `TPreloadedQueries`: the type of the `queries` parameter to the EntryPoint component.
55
+ * `TPreloadedEntryPoints`: the type of the `entrypoints` parameter passed to the EntryPoint component.
56
+ * `TRuntimeProps`: the type of the `props` prop passed to `EntryPointContainer`. This object is passed down to the EntryPoint component, also as `props`.
57
+ * `TExtraProps`: if an EntryPoint's `getPreloadProps` method returns an object with an `extraProps` property, those extra props will be passed to the EntryPoint component as `extraProps`.
58
+ * `TEntryPointComponent`: the type of the EntryPoint.
59
+ * `TEntryPoint`: the type of the EntryPoint.
60
+
61
+ ### Return Value
62
+
63
+ An EntryPoint reference with the following properties:
64
+
65
+ * `dispose`: a method that will release any query references loaded by this EntryPoint (including indirectly, by way of other EntryPoints) from being retained by the store. This can cause the data referenced by these query reference to be garbage collected.
66
+
67
+ The exact format of the return value is *unstable and highly likely to change*. We strongly recommend not using any other properties of the return value, as such code would be highly likely to break when upgrading to future versions of Relay. Instead, pass the result of `loadEntryPoint()` to `EntryPointContainer`.
68
+
69
+ ### Behavior
70
+
71
+ * When `loadEntryPoint()` is called, each of an EntryPoint's associated queries (if it has any) will load their query data and query AST. Once both the query AST and the data are available, the data will be written to the store. This differs from the behavior of `prepareEntryPoint_DEPRECATED`, which would only write the data from an associated query to the store when that query was rendered with `usePreloadedQuery`.
72
+ * The EntryPoint reference's associated query references will be retained by the Relay store, preventing the data from being garbage collected. Once you call `.dispose()` on the EntryPoint reference, the data from the associated queries is liable to be garbage collected.
73
+ * `loadEntryPoint` may throw an error if it is called during React's render phase.
74
+
75
+
76
+
77
+ <DocsRating />
@@ -0,0 +1,99 @@
1
+ ---
2
+ id: use-entrypoint-loader
3
+ title: useEntryPointLoader
4
+ slug: /api-reference/use-entrypoint-loader/
5
+ description: API reference for useEntryPointLoader, a React hook used to load entrypoints in response to user events
6
+ keywords:
7
+ - render-as-you-fetch
8
+ - entrypoint
9
+ - preload
10
+ ---
11
+
12
+ import DocsRating from '@site/src/core/DocsRating';
13
+ import {OssOnly, FbInternalOnly} from 'docusaurus-plugin-internaldocs-fb/internal';
14
+
15
+ ## `useEntryPointLoader`
16
+
17
+ Hook used to make it easy to safely work with EntryPoints, while avoiding data leaking into the Relay store. It will keep an EntryPoint reference in state, and dispose of it when it is no longer accessible via state.
18
+
19
+ <FbInternalOnly>
20
+
21
+ For more information, see the [Loading EntryPoints](https://www.internalfb.com/intern/wiki/Relay/Guides/entry-points/#loading-entrypoints) guide.
22
+
23
+ </FbInternalOnly>
24
+
25
+ ```js
26
+ const {useEntryPointLoader, EntryPointContainer} = require('react-relay');
27
+
28
+ const ComponentEntryPoint = require('Component.entrypoint');
29
+
30
+ function EntryPointRevealer(): React.MixedElement {
31
+ const environmentProvider = useMyEnvironmentProvider();
32
+ const [
33
+ entryPointReference,
34
+ loadEntryPoint,
35
+ disposeEntryPoint,
36
+ ] = useEntryPointLoader(environmentProvider, ComponentEntryPoint);
37
+
38
+ return (
39
+ <>
40
+ {
41
+ entryPointReference == null && (
42
+ <Button onClick={() => loadEntryPoint({})}>
43
+ Click to reveal the contents of the EntryPoint
44
+ </Button>
45
+ )
46
+ }
47
+ {
48
+ entryPointReference != null && (
49
+ <>
50
+ <Button onClick={disposeEntryPoint}>
51
+ Click to hide and dispose the EntryPoint.
52
+ </Button>
53
+ <Suspense fallback="Loading...">
54
+ <EntryPointContainer
55
+ entryPointReference={entryPointReference}
56
+ props={{}}
57
+ />
58
+ </Suspense>
59
+ </>
60
+ )
61
+ }
62
+ </>
63
+ );
64
+ }
65
+ ```
66
+
67
+ ### Arguments
68
+
69
+ * `environmentProvider`: an object with a `getEnvironment` method that returns a Relay environment.
70
+ * `EntryPoint`: the EntryPoint, usually acquired by importing a `.entrypoint.js` file.
71
+
72
+ ### Flow Type Parameters
73
+
74
+ * `TEntryPointParams`: the type of the first argument to the `getPreloadProps` method of the EntryPoint.
75
+ * `TPreloadedQueries`: the type of the `queries` prop passed to the EntryPoint component.
76
+ * `TPreloadedEntryPoints`: the type of the `entryPoints` prop passed to the EntryPoint component.
77
+ * `TRuntimeProps`: the type of the `props` prop passed to `EntryPointContainer`. This object is passed down to the EntryPoint component, also as `props`.
78
+ * `TExtraProps`: if an EntryPoint's `getPreloadProps` method returns an object with an `extraProps` property, those extra props will be passed to the EntryPoint component as `extraProps` and have type `TExtraProps`.
79
+ * `TEntryPointComponent`: the type of the EntryPoint component.
80
+ * `TEntryPoint`: the type of the EntryPoint.
81
+
82
+ ### Return value
83
+
84
+ A tuple containing the following values:
85
+
86
+ * `entryPointReference`: the EntryPoint reference, or `null`.
87
+ * `loadEntryPoint`: a callback that, when executed, will load an EntryPoint, which will be accessible as `entryPointReference`. If a previous EntryPoint was loaded, it will dispose of it. It may throw an error if called during React's render phase.
88
+ * Parameters
89
+ * `params: TEntryPointParams`: the params passed to the EntryPoint's `getPreloadProps` method.
90
+ * `disposeEntryPoint`: a callback that, when executed, will set `entryPointReference` to `null` and call `.dispose()` on it. It has type `() => void`. It should not be called during React's render phase.
91
+
92
+ ### Behavior
93
+
94
+ * When the `loadEntryPoint` callback is called, each of an EntryPoint's associated queries (if it has any) will load their query data and query AST. Once both the query AST and the data are available, the data will be written to the store. This differs from the behavior of `prepareEntryPoint_DEPRECATED`, which would only write the data from an associated query to the store when that query was rendered with `usePreloadedQuery`.
95
+ * The EntryPoint reference's associated query references will be retained by the Relay store, preventing the data from being garbage collected. Once you call `.dispose()` on the EntryPoint reference, the data from the associated queries is liable to be garbage collected.
96
+ * The `loadEntryPoint` callback may throw an error if it is called during React's render phase.
97
+
98
+
99
+ <DocsRating />