react-relay 0.0.0-main-4ed3edcc → 0.0.0-main-510cf1ea

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v0.0.0-main-4ed3edcc
2
+ * Relay v0.0.0-main-510cf1ea
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
package/hooks.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v0.0.0-main-4ed3edcc
2
+ * Relay v0.0.0-main-510cf1ea
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v0.0.0-main-4ed3edcc
2
+ * Relay v0.0.0-main-510cf1ea
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
package/legacy.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v0.0.0-main-4ed3edcc
2
+ * Relay v0.0.0-main-510cf1ea
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator").default;
4
+ var _require = require('relay-runtime'),
5
+ fetchQuery = _require.fetchQuery;
6
+ function serverFetchQuery(_x, _x2, _x3) {
7
+ return _serverFetchQuery.apply(this, arguments);
8
+ }
9
+ function _serverFetchQuery() {
10
+ _serverFetchQuery = _asyncToGenerator(function* (environment, query, variables) {
11
+ var observable = fetchQuery(environment, query, variables);
12
+ var result = yield observable.toPromise();
13
+ if (result == null) {
14
+ throw new Error('Unexpected null response from fetchQuery');
15
+ }
16
+ return result;
17
+ });
18
+ return _serverFetchQuery.apply(this, arguments);
19
+ }
20
+ module.exports = serverFetchQuery;
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator").default;
4
+ var _require = require('relay-runtime/experimental'),
5
+ waitForFragmentData = _require.waitForFragmentData;
6
+ function serverReadFragment(_x, _x2, _x3) {
7
+ return _serverReadFragment.apply(this, arguments);
8
+ }
9
+ function _serverReadFragment() {
10
+ _serverReadFragment = _asyncToGenerator(function* (environment, fragment, fragmentRef) {
11
+ return waitForFragmentData(environment, fragment, fragmentRef);
12
+ });
13
+ return _serverReadFragment.apply(this, arguments);
14
+ }
15
+ module.exports = serverReadFragment;
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator").default;
4
+ var serverFetchQueryImpl = require('./relay-hooks/rsc/serverFetchQuery');
5
+ var serverReadFragmentImpl = require('./relay-hooks/rsc/serverReadFragment');
6
+ var invariant = require('invariant');
7
+ var React = require('react');
8
+ function createServerEnvironment(create) {
9
+ var cache = React.cache;
10
+ !(typeof cache === 'function') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay RSC APIs require React 19+') : invariant(false) : void 0;
11
+ var getEnvironment = cache(create);
12
+ function serverFetchQuery(_x, _x2) {
13
+ return _serverFetchQuery.apply(this, arguments);
14
+ }
15
+ function _serverFetchQuery() {
16
+ _serverFetchQuery = _asyncToGenerator(function* (query, variables) {
17
+ return serverFetchQueryImpl(getEnvironment(), query, variables);
18
+ });
19
+ return _serverFetchQuery.apply(this, arguments);
20
+ }
21
+ function serverReadFragment(_x3, _x4) {
22
+ return _serverReadFragment.apply(this, arguments);
23
+ }
24
+ function _serverReadFragment() {
25
+ _serverReadFragment = _asyncToGenerator(function* (fragment, fragmentRef) {
26
+ return serverReadFragmentImpl(getEnvironment(), fragment, fragmentRef);
27
+ });
28
+ return _serverReadFragment.apply(this, arguments);
29
+ }
30
+ return {
31
+ getEnvironment: getEnvironment,
32
+ serverFetchQuery: serverFetchQuery,
33
+ serverReadFragment: serverReadFragment
34
+ };
35
+ }
36
+ module.exports = {
37
+ createServerEnvironment: createServerEnvironment
38
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-relay",
3
3
  "description": "A framework for building GraphQL-driven React applications.",
4
- "version": "0.0.0-main-4ed3edcc",
4
+ "version": "0.0.0-main-510cf1ea",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "relay",
@@ -20,7 +20,7 @@
20
20
  "fbjs": "^3.0.2",
21
21
  "invariant": "^2.2.4",
22
22
  "nullthrows": "^1.1.1",
23
- "relay-runtime": "0.0.0-main-4ed3edcc"
23
+ "relay-runtime": "0.0.0-main-510cf1ea"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react": "^16.9.0 || ^17 || ^18 || ^19"
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ * @oncall relay
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ import type {IEnvironment, Query, Variables} from 'relay-runtime';
15
+
16
+ const {fetchQuery} = require('relay-runtime');
17
+
18
+ async function serverFetchQuery<TVariables extends Variables, TData>(
19
+ environment: IEnvironment,
20
+ query: Query<TVariables, TData>,
21
+ variables: TVariables,
22
+ ): Promise<TData> {
23
+ const observable = fetchQuery(environment, query, variables);
24
+ const result = await observable.toPromise();
25
+ if (result == null) {
26
+ throw new Error('Unexpected null response from fetchQuery');
27
+ }
28
+ return result;
29
+ }
30
+
31
+ module.exports = serverFetchQuery;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ * @oncall relay
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ import type {Fragment, FragmentType, IEnvironment} from 'relay-runtime';
15
+
16
+ const {waitForFragmentData} = require('relay-runtime/experimental');
17
+
18
+ type HasSpread<TFragmentType> = {
19
+ +$fragmentSpreads: TFragmentType,
20
+ ...
21
+ };
22
+
23
+ async function serverReadFragment<TFragmentType extends FragmentType, TData>(
24
+ environment: IEnvironment,
25
+ fragment: Fragment<TFragmentType, TData>,
26
+ fragmentRef:
27
+ | HasSpread<TFragmentType>
28
+ | ReadonlyArray<HasSpread<TFragmentType>>,
29
+ ): Promise<TData> {
30
+ return waitForFragmentData(environment, fragment, fragmentRef);
31
+ }
32
+
33
+ module.exports = serverReadFragment;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Relay v0.0.0-main-510cf1ea
3
+ *
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+
10
+ module.exports = require('./lib/rsc_EXPERIMENTAL.js');
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ * @oncall relay
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ import type {
15
+ Fragment,
16
+ FragmentType,
17
+ IEnvironment,
18
+ Query,
19
+ Variables,
20
+ } from 'relay-runtime';
21
+
22
+ const serverFetchQueryImpl = require('./relay-hooks/rsc/serverFetchQuery');
23
+ const serverReadFragmentImpl = require('./relay-hooks/rsc/serverReadFragment');
24
+ const invariant = require('invariant');
25
+ const React = require('react');
26
+
27
+ type HasSpread<TFragmentType> = {+$fragmentSpreads: TFragmentType, ...};
28
+
29
+ export type ServerEnvironment = {
30
+ +getEnvironment: () => IEnvironment,
31
+ +serverFetchQuery: <TVariables extends Variables, TData>(
32
+ query: Query<TVariables, TData>,
33
+ variables: TVariables,
34
+ ) => Promise<TData>,
35
+ +serverReadFragment: <TFragmentType extends FragmentType, TData>(
36
+ fragment: Fragment<TFragmentType, TData>,
37
+ fragmentRef:
38
+ | HasSpread<TFragmentType>
39
+ | ReadonlyArray<HasSpread<TFragmentType>>,
40
+ ) => Promise<TData>,
41
+ };
42
+
43
+ function createServerEnvironment(
44
+ create: () => IEnvironment,
45
+ ): ServerEnvironment {
46
+ // $FlowFixMe[missing-export] React.cache is available in React 19+
47
+ const cache = React.cache;
48
+ invariant(typeof cache === 'function', 'Relay RSC APIs require React 19+');
49
+ const getEnvironment = cache(create);
50
+
51
+ async function serverFetchQuery<TVariables extends Variables, TData>(
52
+ query: Query<TVariables, TData>,
53
+ variables: TVariables,
54
+ ): Promise<TData> {
55
+ return serverFetchQueryImpl(getEnvironment(), query, variables);
56
+ }
57
+
58
+ async function serverReadFragment<TFragmentType extends FragmentType, TData>(
59
+ fragment: Fragment<TFragmentType, TData>,
60
+ fragmentRef:
61
+ | HasSpread<TFragmentType>
62
+ | ReadonlyArray<HasSpread<TFragmentType>>,
63
+ ): Promise<TData> {
64
+ return serverReadFragmentImpl(getEnvironment(), fragment, fragmentRef);
65
+ }
66
+
67
+ return {
68
+ getEnvironment,
69
+ serverFetchQuery,
70
+ serverReadFragment,
71
+ };
72
+ }
73
+
74
+ module.exports = {createServerEnvironment};