relay-runtime 20.1.1 → 21.0.1

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 (334) hide show
  1. package/experimental.d.ts +34 -0
  2. package/experimental.js +1 -1
  3. package/experimental.js.flow +11 -11
  4. package/handlers/RelayDefaultHandlerProvider.d.ts +12 -0
  5. package/handlers/connection/ConnectionHandler.d.ts +51 -0
  6. package/handlers/connection/ConnectionHandler.js.flow +5 -5
  7. package/handlers/connection/ConnectionInterface.d.ts +40 -0
  8. package/handlers/connection/ConnectionInterface.js.flow +1 -1
  9. package/handlers/connection/MutationHandlers.d.ts +17 -0
  10. package/index.d.ts +274 -0
  11. package/index.js +1 -1
  12. package/index.js.flow +125 -62
  13. package/lib/experimental.js +3 -3
  14. package/lib/index.js +105 -57
  15. package/lib/multi-actor-environment/ActorIdentifier.js +2 -2
  16. package/lib/multi-actor-environment/MultiActorEnvironment.js +3 -1
  17. package/lib/mutations/commitMutation.js +8 -8
  18. package/lib/mutations/validateMutation.js +4 -4
  19. package/lib/query/GraphQLTag.js +3 -3
  20. package/lib/query/fetchQuery.js +15 -3
  21. package/lib/store/DataChecker.js +38 -4
  22. package/lib/store/NormalizationEngine.js +373 -0
  23. package/lib/store/OperationExecutor.js +172 -113
  24. package/lib/store/RelayConcreteVariables.js +1 -1
  25. package/lib/store/RelayErrorTrie.js +2 -2
  26. package/lib/store/RelayExperimentalGraphResponseTransform.js +8 -8
  27. package/lib/store/RelayModernEnvironment.js +26 -19
  28. package/lib/store/RelayModernRecord.js +18 -8
  29. package/lib/store/RelayModernSelector.js +9 -9
  30. package/lib/store/RelayModernStore.js +152 -43
  31. package/lib/store/RelayPublishQueue.js +1 -1
  32. package/lib/store/RelayReader.js +76 -38
  33. package/lib/store/RelayRecordSource.js +6 -0
  34. package/lib/store/RelayReferenceMarker.js +2 -1
  35. package/lib/store/RelayResponseNormalizer.js +88 -55
  36. package/lib/store/RelayStoreSubscriptions.js +34 -10
  37. package/lib/store/RelayStoreUtils.js +8 -1
  38. package/lib/store/ResolverFragments.js +2 -2
  39. package/lib/store/live-resolvers/LiveResolverCache.js +25 -9
  40. package/lib/store/observeFragmentExperimental.js +17 -1
  41. package/lib/store/observeQueryExperimental.js +2 -2
  42. package/lib/subscription/requestSubscription.js +3 -3
  43. package/lib/util/RelayError.js +3 -0
  44. package/lib/util/RelayFeatureFlags.js +6 -2
  45. package/lib/util/RelayReplaySubject.js +4 -4
  46. package/lib/util/handlePotentialSnapshotErrors.js +2 -2
  47. package/lib/util/stableCopy.js +2 -2
  48. package/llm-docs/api-reference/entrypoint-apis/entrypoint-container.mdx +38 -0
  49. package/llm-docs/api-reference/entrypoint-apis/load-entrypoint.mdx +77 -0
  50. package/llm-docs/api-reference/entrypoint-apis/use-entrypoint-loader.mdx +99 -0
  51. package/llm-docs/api-reference/graphql/graphql-directives.mdx +378 -0
  52. package/llm-docs/api-reference/hooks/_use-lazy-load-query-extra.mdx +16 -0
  53. package/llm-docs/api-reference/hooks/load-query.mdx +84 -0
  54. package/llm-docs/api-reference/hooks/relay-environment-provider.mdx +78 -0
  55. package/llm-docs/api-reference/hooks/use-client-query.mdx +65 -0
  56. package/llm-docs/api-reference/hooks/use-fragment.mdx +69 -0
  57. package/llm-docs/api-reference/hooks/use-lazy-load-query.mdx +62 -0
  58. package/llm-docs/api-reference/hooks/use-mutation.mdx +94 -0
  59. package/llm-docs/api-reference/hooks/use-pagination-fragment.mdx +166 -0
  60. package/llm-docs/api-reference/hooks/use-prefetchable-forward-pagination-fragment.mdx +134 -0
  61. package/llm-docs/api-reference/hooks/use-preloaded-query.mdx +84 -0
  62. package/llm-docs/api-reference/hooks/use-query-loader.mdx +95 -0
  63. package/llm-docs/api-reference/hooks/use-refetchable-fragment.mdx +122 -0
  64. package/llm-docs/api-reference/hooks/use-relay-environment.mdx +37 -0
  65. package/llm-docs/api-reference/hooks/use-subscription.mdx +66 -0
  66. package/llm-docs/api-reference/relay-resolvers/docblock-format.mdx +321 -0
  67. package/llm-docs/api-reference/relay-resolvers/runtime-functions.mdx +94 -0
  68. package/llm-docs/api-reference/relay-runtime/commit-mutation.mdx +65 -0
  69. package/llm-docs/api-reference/relay-runtime/fetch-query.mdx +118 -0
  70. package/llm-docs/api-reference/relay-runtime/field-logger.mdx +170 -0
  71. package/llm-docs/api-reference/relay-runtime/observe-fragment.mdx +92 -0
  72. package/llm-docs/api-reference/relay-runtime/relay-environment.mdx +53 -0
  73. package/llm-docs/api-reference/relay-runtime/request-subscription.mdx +54 -0
  74. package/llm-docs/api-reference/relay-runtime/runtime-configuration.mdx +52 -0
  75. package/llm-docs/api-reference/relay-runtime/store.mdx +734 -0
  76. package/llm-docs/api-reference/relay-runtime/wait-for-fragment-data.mdx +89 -0
  77. package/llm-docs/api-reference/types/CacheConfig.mdx +8 -0
  78. package/llm-docs/api-reference/types/Disposable.mdx +4 -0
  79. package/llm-docs/api-reference/types/GraphQLSubscriptionConfig.mdx +17 -0
  80. package/llm-docs/api-reference/types/MutationConfig.mdx +31 -0
  81. package/llm-docs/api-reference/types/SelectorStoreUpdater.mdx +6 -0
  82. package/llm-docs/api-reference/types/UploadableMap.mdx +3 -0
  83. package/llm-docs/community/learning-resources.mdx +64 -0
  84. package/llm-docs/debugging/declarative-mutation-directives.mdx +34 -0
  85. package/llm-docs/debugging/disallowed-id-types-error.mdx +43 -0
  86. package/llm-docs/debugging/inconsistent-typename-error.mdx +47 -0
  87. package/llm-docs/debugging/relay-devtools.mdx +73 -0
  88. package/llm-docs/debugging/why-null.mdx +116 -0
  89. package/llm-docs/editor-support.mdx +55 -0
  90. package/llm-docs/error-reference/unknown-field.mdx +36 -0
  91. package/llm-docs/getting-started/babel-plugin.mdx +31 -0
  92. package/llm-docs/getting-started/compiler-config.mdx +25 -0
  93. package/llm-docs/getting-started/compiler.mdx +98 -0
  94. package/llm-docs/getting-started/lint-rules.mdx +87 -0
  95. package/llm-docs/getting-started/production.mdx +30 -0
  96. package/llm-docs/getting-started/quick-start.mdx +216 -0
  97. package/llm-docs/glossary/glossary.mdx +1040 -0
  98. package/llm-docs/guided-tour/list-data/advanced-pagination.mdx +157 -0
  99. package/llm-docs/guided-tour/list-data/connections.mdx +81 -0
  100. package/llm-docs/guided-tour/list-data/pagination.mdx +193 -0
  101. package/llm-docs/guided-tour/list-data/rendering-connections.mdx +112 -0
  102. package/llm-docs/guided-tour/list-data/streaming-pagination.mdx +87 -0
  103. package/llm-docs/guided-tour/managing-data-outside-react/retaining-queries.mdx +51 -0
  104. package/llm-docs/guided-tour/refetching/refetching-queries-with-different-data.mdx +337 -0
  105. package/llm-docs/guided-tour/refetching/refreshing-queries.mdx +350 -0
  106. package/llm-docs/guided-tour/rendering/environment.mdx +59 -0
  107. package/llm-docs/guided-tour/rendering/error-states.mdx +295 -0
  108. package/llm-docs/guided-tour/rendering/fragments.mdx +354 -0
  109. package/llm-docs/guided-tour/rendering/loading-states.mdx +245 -0
  110. package/llm-docs/guided-tour/rendering/queries.mdx +261 -0
  111. package/llm-docs/guided-tour/rendering/variables.mdx +233 -0
  112. package/llm-docs/guided-tour/reusing-cached-data/fetch-policies.mdx +56 -0
  113. package/llm-docs/guided-tour/reusing-cached-data/filling-in-missing-data.mdx +102 -0
  114. package/llm-docs/guided-tour/reusing-cached-data/introduction.mdx +22 -0
  115. package/llm-docs/guided-tour/reusing-cached-data/presence-of-data.mdx +93 -0
  116. package/llm-docs/guided-tour/reusing-cached-data/rendering-partially-cached-data.mdx +175 -0
  117. package/llm-docs/guided-tour/reusing-cached-data/staleness-of-data.mdx +116 -0
  118. package/llm-docs/guided-tour/updating-data/client-only-data.mdx +115 -0
  119. package/llm-docs/guided-tour/updating-data/graphql-mutations.mdx +334 -0
  120. package/llm-docs/guided-tour/updating-data/graphql-subscriptions.mdx +279 -0
  121. package/llm-docs/guided-tour/updating-data/imperatively-modifying-linked-fields.mdx +511 -0
  122. package/llm-docs/guided-tour/updating-data/imperatively-modifying-store-data-legacy.mdx +142 -0
  123. package/llm-docs/guided-tour/updating-data/imperatively-modifying-store-data.mdx +275 -0
  124. package/llm-docs/guided-tour/updating-data/introduction.mdx +25 -0
  125. package/llm-docs/guided-tour/updating-data/local-data-updates.mdx +71 -0
  126. package/llm-docs/guided-tour/updating-data/typesafe-updaters-faq.mdx +83 -0
  127. package/llm-docs/guided-tour/updating-data/updating-connections.mdx +592 -0
  128. package/llm-docs/guides/alias-directive.mdx +160 -0
  129. package/llm-docs/guides/catch-directive.mdx +167 -0
  130. package/llm-docs/guides/client-schema-extensions.mdx +208 -0
  131. package/llm-docs/guides/codemods.mdx +79 -0
  132. package/llm-docs/guides/data-driven-dependencies/client-3d.mdx +255 -0
  133. package/llm-docs/guides/data-driven-dependencies/configuration.mdx +127 -0
  134. package/llm-docs/guides/data-driven-dependencies/introduction.mdx +39 -0
  135. package/llm-docs/guides/data-driven-dependencies/server-3d.mdx +664 -0
  136. package/llm-docs/guides/document-comparison.mdx +106 -0
  137. package/llm-docs/guides/graphql-server-specification.mdx +453 -0
  138. package/llm-docs/guides/network-layer.mdx +69 -0
  139. package/llm-docs/guides/persisted-queries.mdx +328 -0
  140. package/llm-docs/guides/relay-resolvers/context.mdx +99 -0
  141. package/llm-docs/guides/relay-resolvers/defining-fields.mdx +151 -0
  142. package/llm-docs/guides/relay-resolvers/defining-types.mdx +164 -0
  143. package/llm-docs/guides/relay-resolvers/deprecated.mdx +27 -0
  144. package/llm-docs/guides/relay-resolvers/derived-fields.mdx +127 -0
  145. package/llm-docs/guides/relay-resolvers/descriptions.mdx +44 -0
  146. package/llm-docs/guides/relay-resolvers/enabling.mdx +41 -0
  147. package/llm-docs/guides/relay-resolvers/errors.mdx +64 -0
  148. package/llm-docs/guides/relay-resolvers/field-arguments.mdx +63 -0
  149. package/llm-docs/guides/relay-resolvers/introduction.mdx +62 -0
  150. package/llm-docs/guides/relay-resolvers/limitations.mdx +30 -0
  151. package/llm-docs/guides/relay-resolvers/live-fields.mdx +164 -0
  152. package/llm-docs/guides/relay-resolvers/return-types.mdx +161 -0
  153. package/llm-docs/guides/relay-resolvers/suspense.mdx +41 -0
  154. package/llm-docs/guides/required-directive.mdx +240 -0
  155. package/llm-docs/guides/semantic-nullability.mdx +93 -0
  156. package/llm-docs/guides/testing-relay-components.mdx +642 -0
  157. package/llm-docs/guides/testing-relay-with-preloaded-queries.mdx +160 -0
  158. package/llm-docs/guides/throw-on-field-error-directive.mdx +58 -0
  159. package/llm-docs/guides/type-emission.mdx +414 -0
  160. package/llm-docs/home.mdx +32 -0
  161. package/llm-docs/principles-and-architecture/architecture-overview.mdx +24 -0
  162. package/llm-docs/principles-and-architecture/compiler-architecture.mdx +106 -0
  163. package/llm-docs/principles-and-architecture/runtime-architecture.mdx +249 -0
  164. package/llm-docs/principles-and-architecture/thinking-in-graphql.mdx +309 -0
  165. package/llm-docs/principles-and-architecture/thinking-in-relay.mdx +104 -0
  166. package/llm-docs/principles-and-architecture/videos.mdx +50 -0
  167. package/llm-docs/tutorial/arrays-lists.mdx +126 -0
  168. package/llm-docs/tutorial/fragments-1.mdx +487 -0
  169. package/llm-docs/tutorial/graphql.mdx +172 -0
  170. package/llm-docs/tutorial/interfaces-polymorphism.mdx +161 -0
  171. package/llm-docs/tutorial/intro.mdx +58 -0
  172. package/llm-docs/tutorial/mutations-updates.mdx +624 -0
  173. package/llm-docs/tutorial/organizing-mutations-queries-and-subscriptions.mdx +13 -0
  174. package/llm-docs/tutorial/queries-1.mdx +267 -0
  175. package/llm-docs/tutorial/queries-2.mdx +389 -0
  176. package/llm-docs/tutorial/refetchable-fragments.mdx +352 -0
  177. package/multi-actor-environment/ActorIdentifier.d.ts +17 -0
  178. package/multi-actor-environment/ActorIdentifier.js.flow +2 -2
  179. package/multi-actor-environment/ActorSpecificEnvironment.js.flow +15 -15
  180. package/multi-actor-environment/ActorUtils.js.flow +1 -1
  181. package/multi-actor-environment/MultiActorEnvironment.d.ts +123 -0
  182. package/multi-actor-environment/MultiActorEnvironment.js.flow +32 -24
  183. package/multi-actor-environment/MultiActorEnvironmentTypes.d.ts +225 -0
  184. package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +6 -6
  185. package/multi-actor-environment/index.d.ts +14 -0
  186. package/multi-actor-environment.d.ts +8 -0
  187. package/mutations/RelayDeclarativeMutationConfig.d.ts +70 -0
  188. package/mutations/RelayDeclarativeMutationConfig.js.flow +9 -9
  189. package/mutations/RelayRecordProxy.js.flow +8 -11
  190. package/mutations/RelayRecordSourceMutator.js.flow +4 -4
  191. package/mutations/RelayRecordSourceProxy.js.flow +4 -4
  192. package/mutations/RelayRecordSourceSelectorProxy.js.flow +6 -6
  193. package/mutations/applyOptimisticMutation.d.ts +25 -0
  194. package/mutations/applyOptimisticMutation.js.flow +2 -2
  195. package/mutations/commitLocalUpdate.d.ts +10 -0
  196. package/mutations/commitMutation.d.ts +48 -0
  197. package/mutations/commitMutation.js.flow +21 -17
  198. package/mutations/createUpdatableProxy.js.flow +19 -19
  199. package/mutations/readUpdatableFragment.js.flow +3 -3
  200. package/mutations/readUpdatableQuery.js.flow +3 -3
  201. package/mutations/validateMutation.js.flow +7 -7
  202. package/network/RelayNetwork.d.ts +12 -0
  203. package/network/RelayNetworkTypes.d.ts +145 -0
  204. package/network/RelayNetworkTypes.js.flow +18 -18
  205. package/network/RelayObservable.d.ts +197 -0
  206. package/network/RelayObservable.js.flow +32 -30
  207. package/network/RelayQueryResponseCache.d.ts +16 -0
  208. package/network/RelayQueryResponseCache.js.flow +3 -3
  209. package/network/wrapNetworkWithLogObserver.js.flow +1 -1
  210. package/package.json +2 -1
  211. package/query/GraphQLTag.d.ts +45 -0
  212. package/query/GraphQLTag.js.flow +22 -10
  213. package/query/fetchQuery.d.ts +21 -0
  214. package/query/fetchQuery.js.flow +23 -10
  215. package/query/fetchQueryInternal.d.ts +26 -0
  216. package/query/fetchQueryInternal.js.flow +4 -4
  217. package/query/fetchQuery_DEPRECATED.d.ts +17 -0
  218. package/query/fetchQuery_DEPRECATED.js.flow +1 -1
  219. package/store/ClientID.d.ts +14 -0
  220. package/store/DataChecker.js.flow +51 -15
  221. package/store/NormalizationEngine.js.flow +782 -0
  222. package/store/OperationExecutor.d.ts +51 -0
  223. package/store/OperationExecutor.js.flow +204 -98
  224. package/store/RelayConcreteVariables.js.flow +5 -5
  225. package/store/RelayErrorTrie.js.flow +12 -12
  226. package/store/RelayExperimentalGraphResponseHandler.js.flow +3 -3
  227. package/store/RelayExperimentalGraphResponseTransform.js.flow +10 -10
  228. package/store/RelayModernEnvironment.d.ts +97 -0
  229. package/store/RelayModernEnvironment.js.flow +58 -43
  230. package/store/RelayModernFragmentSpecResolver.js.flow +1 -1
  231. package/store/RelayModernOperationDescriptor.d.ts +28 -0
  232. package/store/RelayModernOperationDescriptor.js.flow +1 -1
  233. package/store/RelayModernRecord.d.ts +92 -0
  234. package/store/RelayModernRecord.js.flow +44 -20
  235. package/store/RelayModernSelector.d.ts +123 -0
  236. package/store/RelayModernSelector.js.flow +21 -21
  237. package/store/RelayModernStore.d.ts +57 -0
  238. package/store/RelayModernStore.js.flow +219 -58
  239. package/store/RelayOperationTracker.d.ts +29 -0
  240. package/store/RelayOperationTracker.js.flow +2 -2
  241. package/store/RelayOptimisticRecordSource.js.flow +2 -2
  242. package/store/RelayPublishQueue.js.flow +29 -20
  243. package/store/RelayReader.js.flow +129 -57
  244. package/store/RelayRecordSource.d.ts +26 -0
  245. package/store/RelayRecordSource.js.flow +10 -0
  246. package/store/RelayRecordState.d.ts +28 -0
  247. package/store/RelayRecordState.js.flow +1 -1
  248. package/store/RelayReferenceMarker.js.flow +5 -4
  249. package/store/RelayResponseNormalizer.d.ts +28 -0
  250. package/store/RelayResponseNormalizer.js.flow +130 -62
  251. package/store/RelayStoreSubscriptions.js.flow +52 -8
  252. package/store/RelayStoreTypes.d.ts +1327 -0
  253. package/store/RelayStoreTypes.js.flow +371 -278
  254. package/store/RelayStoreUtils.d.ts +86 -0
  255. package/store/RelayStoreUtils.js.flow +16 -8
  256. package/store/ResolverCache.js.flow +2 -2
  257. package/store/ResolverFragments.d.ts +43 -0
  258. package/store/ResolverFragments.js.flow +22 -14
  259. package/store/StoreInspector.js.flow +7 -8
  260. package/store/ViewerPattern.d.ts +11 -0
  261. package/store/cloneRelayHandleSourceField.js.flow +1 -1
  262. package/store/cloneRelayScalarHandleSourceField.js.flow +1 -1
  263. package/store/createFragmentSpecResolver.d.ts +16 -0
  264. package/store/createRelayContext.js.flow +1 -1
  265. package/store/createRelayLoggingContext.js.flow +4 -4
  266. package/store/defaultGetDataID.js.flow +2 -2
  267. package/store/isRelayModernEnvironment.d.ts +8 -0
  268. package/store/isRelayModernEnvironment.js.flow +4 -2
  269. package/store/live-resolvers/LiveResolverCache.js.flow +55 -20
  270. package/store/live-resolvers/LiveResolverSuspenseSentinel.js.flow +3 -3
  271. package/store/live-resolvers/getOutputTypeRecordIDs.js.flow +1 -1
  272. package/store/live-resolvers/isLiveStateValue.js.flow +2 -2
  273. package/store/live-resolvers/resolverDataInjector.d.ts +27 -0
  274. package/store/live-resolvers/resolverDataInjector.js.flow +8 -5
  275. package/store/observeFragmentExperimental.d.ts +46 -0
  276. package/store/observeFragmentExperimental.js.flow +50 -21
  277. package/store/observeQueryExperimental.d.ts +30 -0
  278. package/store/observeQueryExperimental.js.flow +5 -5
  279. package/store/readInlineData.d.ts +19 -0
  280. package/store/readInlineData.js.flow +5 -5
  281. package/store/waitForFragmentExperimental.d.ts +49 -0
  282. package/store/waitForFragmentExperimental.js.flow +3 -3
  283. package/subscription/requestSubscription.d.ts +27 -0
  284. package/subscription/requestSubscription.js.flow +10 -10
  285. package/util/JSResourceTypes.flow.js.flow +4 -4
  286. package/util/NormalizationNode.d.ts +235 -0
  287. package/util/NormalizationNode.js.flow +127 -123
  288. package/util/ReaderNode.d.ts +264 -0
  289. package/util/ReaderNode.js.flow +156 -151
  290. package/util/RelayConcreteNode.d.ts +120 -0
  291. package/util/RelayConcreteNode.js.flow +32 -32
  292. package/util/RelayError.d.ts +13 -0
  293. package/util/RelayError.js.flow +4 -1
  294. package/util/RelayFeatureFlags.d.ts +40 -0
  295. package/util/RelayFeatureFlags.js.flow +21 -1
  296. package/util/RelayProfiler.d.ts +121 -0
  297. package/util/RelayProfiler.js.flow +1 -1
  298. package/util/RelayReplaySubject.d.ts +25 -0
  299. package/util/RelayReplaySubject.js.flow +3 -3
  300. package/util/RelayRuntimeTypes.d.ts +59 -0
  301. package/util/RelayRuntimeTypes.js.flow +36 -33
  302. package/util/createPayloadFor3DField.d.ts +17 -0
  303. package/util/createPayloadFor3DField.js.flow +9 -5
  304. package/util/deepFreeze.d.ts +8 -0
  305. package/util/deepFreeze.js.flow +2 -2
  306. package/util/getFragmentIdentifier.d.ts +10 -0
  307. package/util/getFragmentIdentifier.js.flow +1 -1
  308. package/util/getPaginationMetadata.d.ts +20 -0
  309. package/util/getPaginationMetadata.js.flow +1 -1
  310. package/util/getPaginationVariables.d.ts +20 -0
  311. package/util/getPaginationVariables.js.flow +1 -1
  312. package/util/getPendingOperationsForFragment.d.ts +18 -0
  313. package/util/getPendingOperationsForFragment.js.flow +2 -2
  314. package/util/getRefetchMetadata.d.ts +19 -0
  315. package/util/getRefetchMetadata.js.flow +6 -5
  316. package/util/getRelayHandleKey.d.ts +8 -0
  317. package/util/getRequestIdentifier.d.ts +17 -0
  318. package/util/getValueAtPath.d.ts +8 -0
  319. package/util/getValueAtPath.js.flow +3 -3
  320. package/util/handlePotentialSnapshotErrors.d.ts +14 -0
  321. package/util/handlePotentialSnapshotErrors.js.flow +5 -5
  322. package/util/isEmptyObject.js.flow +1 -1
  323. package/util/isPromise.d.ts +8 -0
  324. package/util/isPromise.js.flow +2 -2
  325. package/util/isScalarAndEqual.d.ts +8 -0
  326. package/util/isScalarAndEqual.js.flow +1 -1
  327. package/util/recycleNodesInto.d.ts +8 -0
  328. package/util/recycleNodesInto.js.flow +2 -2
  329. package/util/registerEnvironmentWithDevTools.js.flow +1 -1
  330. package/util/shallowFreeze.js.flow +1 -1
  331. package/util/stableCopy.d.ts +8 -0
  332. package/util/stableCopy.js.flow +5 -5
  333. package/util/withProvidedVariables.d.ts +19 -0
  334. package/util/withProvidedVariables.js.flow +14 -10
@@ -0,0 +1,255 @@
1
+ ---
2
+ id: client-3d
3
+ title: Client 3D
4
+ slug: /guides/data-driven-dependencies/client-3d/
5
+ description: Client side data driven dependencies (3D)
6
+ keywords:
7
+ - 3D
8
+ - Client 3D
9
+ - data driven dependencies
10
+ - module
11
+ - match
12
+ - MatchContainer
13
+ ---
14
+ import {FbInternalOnly} from 'docusaurus-plugin-internaldocs-fb/internal';
15
+ import Tabs from '@theme/Tabs';
16
+ import TabItem from '@theme/TabItem';
17
+
18
+ Use client 3D when all the data fields used to render your 3D components are resolved by client-side [Relay Resolvers](../../relay-resolvers/introduction/).
19
+
20
+ ## Example
21
+
22
+ Here is an example of how Client 3D can be used in a React app.
23
+
24
+ <FbInternalOnly>
25
+
26
+ :::note
27
+ For an example diff implementing Client 3D in www, see D62352682.
28
+ :::
29
+
30
+ </FbInternalOnly>
31
+
32
+ ### Schema
33
+ You have an interface `IClient3D` that is a return type for a field on the query in your client schema extensions file:
34
+
35
+ ```graphql
36
+ type Client3DData {
37
+ type: String!
38
+ info: String!
39
+ }
40
+
41
+ interface IClient3D {
42
+ id: ID!
43
+ data: Client3DData!
44
+ }
45
+
46
+ extend type Query {
47
+ client3D: IClient3D
48
+ }
49
+ ```
50
+
51
+ ### Relay Resolvers
52
+ You have 3 Relay Resolvers that return concrete objects that implement the `IClient3D` interface:
53
+
54
+ <Tabs>
55
+ <TabItem value="1" label="Client3DBar" default>
56
+
57
+ ```ts
58
+ export type Client3DModel = {
59
+ __id: DataID,
60
+ };
61
+
62
+ /**
63
+ * @relayType Client3DBar implements IClient3D
64
+ */
65
+ function Client3DBar(id: DataID): ?Client3DModel {
66
+ if (id === INVALID_ID) {
67
+ return null;
68
+ }
69
+ return {
70
+ __id: id,
71
+ };
72
+ }
73
+
74
+ /**
75
+ * @relayField Client3DBar.data: Client3DData
76
+ */
77
+ function data(client3DModel: Client3DModel): Client3DData {
78
+ return {
79
+ type: 'BAR',
80
+ info: 'someBarInfo',
81
+ }
82
+ }
83
+ ```
84
+
85
+ </TabItem>
86
+ <TabItem value="2" label="Client3DFoo">
87
+
88
+ ```ts
89
+ /**
90
+ * @relayType Client3DFoo implements IClient3D
91
+ */
92
+ function Client3DFoo(id: DataID): ?Client3DModel {
93
+ if (id === INVALID_ID) {
94
+ return null;
95
+ }
96
+ return {
97
+ __id: id,
98
+ };
99
+ }
100
+
101
+ /**
102
+ * @relayField Client3DFoo.data: Client3DData
103
+ */
104
+ function data(client3DModel: Client3DModel): Client3DData {
105
+ return {
106
+ type: 'FOO',
107
+ info: 'someFooInfo',
108
+ }
109
+ }
110
+ ```
111
+
112
+ </TabItem>
113
+ <TabItem value="3" label="Client3DHelloWorld">
114
+
115
+ ```ts
116
+ /**
117
+ * @relayType Client3DHelloWorld implements IClient3D
118
+ */
119
+ function Client3DHelloWorld(id: DataID): ?Client3DModel {
120
+ if (id === INVALID_ID) {
121
+ return null;
122
+ }
123
+ return {
124
+ __id: id,
125
+ };
126
+ }
127
+
128
+ /**
129
+ * @relayField Client3DHelloWorld.data: Client3DData
130
+ */
131
+ function data(client3DModel: Client3DModel): Client3DData {
132
+ return {
133
+ type: 'HELLO_WORLD',
134
+ info: 'someHelloWorldInfo',
135
+ }
136
+ }
137
+ ```
138
+
139
+ </TabItem>
140
+ </Tabs>
141
+
142
+
143
+ ### Component
144
+ Before making use of Client 3D, your component will look something like this:
145
+ ```jsx
146
+ component Client3DRelayRenderer() {
147
+ const CLIENT_3D_FRAGMENT = graphql`
148
+ fragment Client3DRelayRendererClient3DFragment on IClient3D {
149
+ data {
150
+ type
151
+ info
152
+ }
153
+ }
154
+ `;
155
+ const client3DData = useClientQuery(
156
+ graphql`
157
+ query Client3DRelayQuery {
158
+ client3D {
159
+ ...Client3DRelayRendererClient3DFragment
160
+ }
161
+ }
162
+ `
163
+ );
164
+
165
+ let component;
166
+ if (client3DData?.data?.type === 'FOO'):
167
+ component = <Client3DFooComponent data={client3DData.data} />
168
+ else if (client3DData?.data?.type === 'BAR'):
169
+ component = <Client3DBarComponent data={client3DData.data} />
170
+ else if (client3DData?.data?.type === 'HELLO_WORLD'):
171
+ component = <Client3DHelloWorldComponent data={client3DData.data} />
172
+
173
+ return (
174
+ component
175
+ );
176
+ }
177
+ ```
178
+
179
+ In order to use Client 3D, you don't have to modify your Relay Resolvers or schema at all.
180
+
181
+ Just modify your component in the following ways:
182
+ 1. Declare separate fragments for each concrete type implementing `IClient3D` that you're fetching. So in this example, these separate fragments are `FOO_FRAGMENT`, `BAR_FRAGMENT`, and `HELLO_WORLD_FRAGMENT`.
183
+ 2. Add the `@module` directive to your fragment, and include the name of the corresponding UI component to this fragment's data as an argument.
184
+ 3. Return the final component using Relay's `MatchContainer`, providing the returned query data as a prop.
185
+
186
+ Notice that in Client 3D, just as in Server 3D, you cannot use `@module` on multiple fragments on the SAME concrete type (but they can be on the same abstract type i.e. a union or an interface).
187
+
188
+ So in this example, `Client3DFooComponent_Fragment` is on the concrete type `Client3DFoo`, and `Client3DBarComponent_Fragment` is on the concrete type `Client3DBar`. If `Client3DBarComponent_Fragment` was also on `Client3DFoo`, the relay compiler would report an error. However, all three concrete types implement the same parent interface `IClient3D`, which is fine.
189
+
190
+ <FbInternalOnly>
191
+
192
+ :::tip
193
+ If you are in www, but not in Comet, you should use `RelayFBMatchContainer` instead of `MatchContainer`.
194
+ :::
195
+
196
+ </FbInternalOnly>
197
+
198
+ After Client 3D, your component code will look something like this:
199
+ ```jsx
200
+ const {graphql, useFragment, useClientQuery, MatchContainer} = require('react-relay');
201
+
202
+ component Client3DRelayRenderer() {
203
+ const FOO_FRAGMENT = graphql`
204
+ fragment Client3DFooComponent_Fragment on Client3DFoo {
205
+ data {
206
+ type
207
+ info
208
+ }
209
+ }
210
+ `;
211
+ const BAR_FRAGMENT = graphql`
212
+ fragment Client3DBarComponent_Fragment on Client3DBar {
213
+ data {
214
+ type
215
+ info
216
+ }
217
+ }
218
+ `;
219
+ const HELLO_WORLD_FRAGMENT = graphql`
220
+ fragment Client3DHelloWorldComponent_Fragment on Client3DHelloWorld {
221
+ data {
222
+ type
223
+ info
224
+ }
225
+ }
226
+ `;
227
+ const client3DData = useClientQuery(
228
+ graphql`
229
+ query Client3DRelayQuery {
230
+ client3D {
231
+ ...Client3DFooComponent_Fragment
232
+ @module(name: "Client3DFooComponent.react")
233
+ ...Client3DBarComponent_Fragment
234
+ @module(name: "Client3DBarComponent.react")
235
+ ...Client3DHelloWorldComponent_Fragment
236
+ @module(name: "Client3DHelloWorldComponent.react")
237
+ }
238
+ }
239
+ `
240
+ );
241
+ return (
242
+ <MatchContainer match={client3DData.client3D} />
243
+ );
244
+ }
245
+ ```
246
+
247
+ ## Limitations
248
+
249
+ While Client 3D can offer many benefits such as a more intuitive developer experience, enhanced maintainability, and faster performance, it also has some limitations that Server 3D does not.
250
+
251
+ One key difference is the number of round trips required to fetch data. Server 3D requires at most two round trips: one to the server for data and one to the CDN for JavaScript. In contrast, Client 3D evaluates resolver code as part of rendering the component, which means that the client needs to render the component to discover what JavaScript code is needed. This can lead to additional round trips, especially when dealing with nested Client 3D usage.
252
+
253
+ For example, consider a blog entry that uses Client 3D to render either a photo blog post or text blog post. The text blog post then uses Client 3D again to determine what type of text presentation format should be used. This can result in nested Client 3D usage, leading to multiple round trips.
254
+
255
+ Relay is working on solutions to this drawback at the moment, but they have not been productionized yet. Hence, when using Client 3D please make sure that you're not using it in a nested manner to avoid performance degradation.
@@ -0,0 +1,127 @@
1
+ ---
2
+ id: configuration
3
+ title: Configuration
4
+ slug: /guides/data-driven-dependencies/configuration/
5
+ description: Data driven dependencies configuration
6
+ keywords:
7
+ - 3D
8
+ - 3D config
9
+ - data driven dependencies
10
+ - module
11
+ - match
12
+ - MatchContainer
13
+ ---
14
+ import {FbInternalOnly, OssOnly} from 'docusaurus-plugin-internaldocs-fb/internal';
15
+ import DocsRating from '@site/src/core/DocsRating';
16
+
17
+ Server 3D is automatically enabled without any changes to your configuration.
18
+
19
+ In order to use Client 3D, you need to add an extra field to your relay [compiler configuration](https://relay.dev/docs/getting-started/installation-and-setup/#compiler-configuration) file: `moduleImportConfig`.
20
+
21
+ <FbInternalOnly>
22
+
23
+ If you're working on a project in xplat, [config.xplat.json](https://www.internalfb.com/code/fbsource/[3b58a2b59826]/xplat/relay/compiler-rs/config.xplat.json) is your configuration file. If you're working on a
24
+ project in www, [config.www.json](https://www.internalfb.com/code/www/[93b4b956668f]/scripts/relay/compiler-rs/config.www.json) is your configuration file.
25
+
26
+ </FbInternalOnly>
27
+
28
+
29
+ There are 2 subfields in `moduleImportConfig`:
30
+ - `dynamicModuleProvider`: This field defines the way the 3D components will be imported.
31
+ - `surface`: This field defines the surfaces for which client 3D should be enabled.
32
+
33
+ These fields are necessary to differentiate between different use cases in Meta's internal codebase, but in OSS they're more straightforward.
34
+
35
+ <FbInternalOnly>
36
+
37
+ ### `dynamicModuleProvider`
38
+
39
+ `dynamicModuleProvider` has 2 subfields: `mode` and `statement`.
40
+
41
+ There are 2 modes that `dynamicModuleProvider` can be set to:
42
+ - `JSResource`: This indicates to the Relay Compiler that the 3D component should be imported as a [JSResource](https://www.internalfb.com/intern/wiki/Static_Resources/haste_comet/JSResource/), a dynamically loadable Javascript module. In this case, you can omit the `statement` subfield entirely.
43
+
44
+ For example:
45
+
46
+ ```js
47
+ "moduleImportConfig": {
48
+ "dynamicModuleProvider": {
49
+ "mode": "JSResource"
50
+ }
51
+ },
52
+ ```
53
+
54
+ - `Custom`: This indicates that you want to write a custom statement import statement to load your 3D component. Fill in the `statement`
55
+ subfield with your custom import statement, using `<$module>` in place of your 3D component name.
56
+
57
+ For example:
58
+ ```js
59
+ "moduleImportConfig": {
60
+ "dynamicModuleProvider": {
61
+ "mode": "Custom",
62
+ "statement": "function() { var JSResource = require('JSResource'); return JSResource('m#<$module>'); }"
63
+ }
64
+ }
65
+ ```
66
+
67
+ ### `surface`
68
+
69
+ Surface can be set to one of 3 options:
70
+ - `resolvers`: this indicates that Client 3D should work only for data fields determined entirely by Relay Resolvers on the client side. You can consider this to be the "vanilla" client 3D use case.
71
+
72
+ For example:
73
+ ```js
74
+ "moduleImportConfig": {
75
+ "dynamicModuleProvider": {
76
+ "mode": "JSResource",
77
+ },
78
+ "surface": "resolvers"
79
+ }
80
+ ```
81
+
82
+ - None: you can omit the `surface` configuration field altogether. This is what most projects in Xplat are configured to currently, as
83
+ you can see in the [Xplat relay configuration file](https://www.internalfb.com/code/fbsource/[3b58a2b59826]/xplat/relay/compiler-rs/config.xplat.json). This case is a special variation of Server 3D where the 3D component module information is stored on the client side by the Relay compiler, and not downloaded from the server along with the data at runtime. This variation of Client 3D doesn't offer any performance gains over server 3D. Rather, it was developed for Xplat to support code sharing between Xplat and WWW.
84
+
85
+ The two config examples given in the `dynamicModuleProvider` section above are both examples of this None case.
86
+ - `all`: this indicates that BOTH the `resolvers` case and None case above should work.
87
+
88
+ For example:
89
+ ```js
90
+ "moduleImportConfig": {
91
+ "dynamicModuleProvider": {
92
+ "mode": "JSResource",
93
+ },
94
+ "surface": "all"
95
+ }
96
+ ```
97
+
98
+ </FbInternalOnly>
99
+
100
+ <OssOnly>
101
+
102
+ ### `dynamicModuleProvider`
103
+
104
+ The `dynamicModuleProvider` has two subfields:
105
+ - `mode`: This should be set to "Custom".
106
+ - `statement`: This is the statement that will be used to import your UI module `<$module>` into the
107
+ parent component where 3D is being used. You can set it to whatever you need to import your module successfully.
108
+
109
+ ### `surface`
110
+
111
+ The `surface` field should be set to `resolvers`.
112
+
113
+ Here is an example of what a Relay compiler configuration that enables client 3D could look like:
114
+
115
+ ```js
116
+ "moduleImportConfig": {
117
+ "dynamicModuleProvider": {
118
+ "mode": "Custom",
119
+ "statement": "() => require('./<$module>')"
120
+ },
121
+ "surface": "resolvers"
122
+ }
123
+ ```
124
+
125
+ </OssOnly>
126
+
127
+ <DocsRating />
@@ -0,0 +1,39 @@
1
+ ---
2
+ id: introduction
3
+ title: Introduction
4
+ slug: /guides/data-driven-dependencies/introduction/
5
+ description: Introduction to data driven dependencies (3D) in Relay
6
+ keywords:
7
+ - 3D
8
+ - data driven dependencies
9
+ - module
10
+ - match
11
+ - MatchContainer
12
+ ---
13
+
14
+ import DocsRating from '@site/src/core/DocsRating';
15
+ import {FbInternalOnly, OssOnly} from 'docusaurus-plugin-internaldocs-fb/internal';
16
+
17
+ Data Driven Dependencies (3D) is a feature in Relay that allows for the dynamic loading of components based on the data being rendered. This is useful when you have multiple possible components that could be used to render a piece of data, and you want to only load the component that is actually needed.
18
+
19
+ The main benefit of using 3D is that it allows you to avoid loading unnecessary code, which can improve the performance of your application. By only loading the code for the components that are actually needed, you can reduce the overall size of your JavaScript bundle and make your application faster.
20
+
21
+ In addition to improving performance, 3D also makes it easier to manage complex rendering logic. By allowing you to define multiple possible components for a single piece of data, 3D makes it easy to handle different rendering scenarios without having to write complex conditional logic.
22
+
23
+ ## Use-Cases
24
+
25
+ There are a few canonical use-cases where 3D is recommended:
26
+
27
+ * **Fields that are typically null.** For example, a `Comment` type that may optionally include an image. Most comments won't include this type so ideally the code for the image rendering component would only be downloaded when necessary to make the average case faster.
28
+ * **Unions.** For example, a News Feed type may have a union of variants, each rendered by a different React component (e.g. text update, videos, photos, etc.). A given page of stories will only contain a small number of story types, so ideally the application would only have to download the code for the types a user actually sees, rather than all possible story types.
29
+ * **Rendering strategies.** Finally, some pieces of content can be rendered using a variety of different **rendering strategies**. As an example, consider a `Video` type that can be rendered as a thumbnail or autoplaying video, depending on whether the user has opted into autoplaying video. Data-driven dependencies allows products to only download the code and data for the *selected* rendering strategy for each item.
30
+
31
+ ## Types of 3D
32
+
33
+ There are two types of 3D that Relay supports:
34
+ - [Server 3D](./server-3d.mdx): used when all the data in your 3D-rendered components are resolved on GraphQL servers.
35
+ - [Client 3D](./client-3d.mdx): used when all the data in your 3D-rendered components are resolved via client-side [Relay resolvers](../relay-resolvers/introduction.mdx).
36
+
37
+ For details on how to configure Relay to support the type of 3D you need, see [Configuration](./configuration.mdx).
38
+
39
+ <DocsRating />