Initial Sample.

This commit is contained in:
2024-06-03 20:23:50 +05:30
parent ef2b65f673
commit 5269ec3c66
2575 changed files with 282312 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
import * as PropTypes from "prop-types";
import type * as ReactTypes from "react";
import type { OperationVariables } from "../../core/index.js";
import type { MutationComponentOptions } from "./types.js";
/**
* @deprecated
* Official support for React Apollo render prop components ended in March 2020.
* This library is still included in the `@apollo/client` package,
* but it no longer receives feature updates or bug fixes.
*/
export declare function Mutation<TData = any, TVariables = OperationVariables>(props: MutationComponentOptions<TData, TVariables>): ReactTypes.JSX.Element | null;
export declare namespace Mutation {
var propTypes: PropTypes.InferProps<MutationComponentOptions<any, any, import("../../core/types.js").DefaultContext, import("../../core/index.js").ApolloCache<any>>>;
}
export interface Mutation<TData, TVariables> {
propTypes: PropTypes.InferProps<MutationComponentOptions<TData, TVariables>>;
}
//# sourceMappingURL=Mutation.d.ts.map

View File

@@ -0,0 +1,28 @@
import * as PropTypes from "prop-types";
import { useMutation } from "../hooks/index.js";
/**
* @deprecated
* Official support for React Apollo render prop components ended in March 2020.
* This library is still included in the `@apollo/client` package,
* but it no longer receives feature updates or bug fixes.
*/
export function Mutation(props) {
var _a = useMutation(props.mutation, props), runMutation = _a[0], result = _a[1];
return props.children ? props.children(runMutation, result) : null;
}
Mutation.propTypes = {
mutation: PropTypes.object.isRequired,
variables: PropTypes.object,
optimisticResponse: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
refetchQueries: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.object])),
PropTypes.func,
]),
awaitRefetchQueries: PropTypes.bool,
update: PropTypes.func,
children: PropTypes.func.isRequired,
onCompleted: PropTypes.func,
onError: PropTypes.func,
fetchPolicy: PropTypes.string,
};
//# sourceMappingURL=Mutation.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Mutation.js","sourceRoot":"","sources":["../../../src/react/components/Mutation.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AAKxC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CACtB,KAAkD;IAE5C,IAAA,KAAwB,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAzD,WAAW,QAAA,EAAE,MAAM,QAAsC,CAAC;IACjE,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACrE,CAAC;AAMD,QAAQ,CAAC,SAAS,GAAG;IACnB,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,UAAU;IACrC,SAAS,EAAE,SAAS,CAAC,MAAM;IAC3B,kBAAkB,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;IAC3E,cAAc,EAAE,SAAS,CAAC,SAAS,CAAC;QAClC,SAAS,CAAC,OAAO,CACf,SAAS,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAC1D;QACD,SAAS,CAAC,IAAI;KACf,CAAC;IACF,mBAAmB,EAAE,SAAS,CAAC,IAAI;IACnC,MAAM,EAAE,SAAS,CAAC,IAAI;IACtB,QAAQ,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU;IACnC,WAAW,EAAE,SAAS,CAAC,IAAI;IAC3B,OAAO,EAAE,SAAS,CAAC,IAAI;IACvB,WAAW,EAAE,SAAS,CAAC,MAAM;CACK,CAAC","sourcesContent":["import * as PropTypes from \"prop-types\";\nimport type * as ReactTypes from \"react\";\n\nimport type { OperationVariables } from \"../../core/index.js\";\nimport type { MutationComponentOptions } from \"./types.js\";\nimport { useMutation } from \"../hooks/index.js\";\n\n/**\n * @deprecated\n * Official support for React Apollo render prop components ended in March 2020.\n * This library is still included in the `@apollo/client` package,\n * but it no longer receives feature updates or bug fixes.\n */\nexport function Mutation<TData = any, TVariables = OperationVariables>(\n props: MutationComponentOptions<TData, TVariables>\n): ReactTypes.JSX.Element | null {\n const [runMutation, result] = useMutation(props.mutation, props);\n return props.children ? props.children(runMutation, result) : null;\n}\n\nexport interface Mutation<TData, TVariables> {\n propTypes: PropTypes.InferProps<MutationComponentOptions<TData, TVariables>>;\n}\n\nMutation.propTypes = {\n mutation: PropTypes.object.isRequired,\n variables: PropTypes.object,\n optimisticResponse: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),\n refetchQueries: PropTypes.oneOfType([\n PropTypes.arrayOf(\n PropTypes.oneOfType([PropTypes.string, PropTypes.object])\n ),\n PropTypes.func,\n ]),\n awaitRefetchQueries: PropTypes.bool,\n update: PropTypes.func,\n children: PropTypes.func.isRequired,\n onCompleted: PropTypes.func,\n onError: PropTypes.func,\n fetchPolicy: PropTypes.string,\n} as Mutation<any, any>[\"propTypes\"];\n"]}

View File

@@ -0,0 +1,18 @@
import * as PropTypes from "prop-types";
import type * as ReactTypes from "react";
import type { OperationVariables } from "../../core/index.js";
import type { QueryComponentOptions } from "./types.js";
/**
* @deprecated
* Official support for React Apollo render prop components ended in March 2020.
* This library is still included in the `@apollo/client` package,
* but it no longer receives feature updates or bug fixes.
*/
export declare function Query<TData = any, TVariables extends OperationVariables = OperationVariables>(props: QueryComponentOptions<TData, TVariables>): ReactTypes.JSX.Element | null;
export declare namespace Query {
var propTypes: PropTypes.InferProps<QueryComponentOptions<any, any>>;
}
export interface Query<TData, TVariables extends OperationVariables> {
propTypes: PropTypes.InferProps<QueryComponentOptions<TData, TVariables>>;
}
//# sourceMappingURL=Query.d.ts.map

View File

@@ -0,0 +1,29 @@
import { __rest } from "tslib";
import * as PropTypes from "prop-types";
import { useQuery } from "../hooks/index.js";
/**
* @deprecated
* Official support for React Apollo render prop components ended in March 2020.
* This library is still included in the `@apollo/client` package,
* but it no longer receives feature updates or bug fixes.
*/
export function Query(props) {
var children = props.children, query = props.query, options = __rest(props, ["children", "query"]);
var result = useQuery(query, options);
return result ? children(result) : null;
}
Query.propTypes = {
client: PropTypes.object,
children: PropTypes.func.isRequired,
fetchPolicy: PropTypes.string,
notifyOnNetworkStatusChange: PropTypes.bool,
onCompleted: PropTypes.func,
onError: PropTypes.func,
pollInterval: PropTypes.number,
query: PropTypes.object.isRequired,
variables: PropTypes.object,
ssr: PropTypes.bool,
partialRefetch: PropTypes.bool,
returnPartialData: PropTypes.bool,
};
//# sourceMappingURL=Query.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Query.js","sourceRoot":"","sources":["../../../src/react/components/Query.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AAKxC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAInB,KAA+C;IAEvC,IAAA,QAAQ,GAAwB,KAAK,SAA7B,EAAE,KAAK,GAAiB,KAAK,MAAtB,EAAK,OAAO,UAAK,KAAK,EAAvC,qBAA+B,CAAF,CAAW;IAC9C,IAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACxC,OAAO,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACjD,CAAC;AAMD,KAAK,CAAC,SAAS,GAAG;IAChB,MAAM,EAAE,SAAS,CAAC,MAAM;IACxB,QAAQ,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU;IACnC,WAAW,EAAE,SAAS,CAAC,MAAM;IAC7B,2BAA2B,EAAE,SAAS,CAAC,IAAI;IAC3C,WAAW,EAAE,SAAS,CAAC,IAAI;IAC3B,OAAO,EAAE,SAAS,CAAC,IAAI;IACvB,YAAY,EAAE,SAAS,CAAC,MAAM;IAC9B,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,UAAU;IAClC,SAAS,EAAE,SAAS,CAAC,MAAM;IAC3B,GAAG,EAAE,SAAS,CAAC,IAAI;IACnB,cAAc,EAAE,SAAS,CAAC,IAAI;IAC9B,iBAAiB,EAAE,SAAS,CAAC,IAAI;CACF,CAAC","sourcesContent":["import * as PropTypes from \"prop-types\";\nimport type * as ReactTypes from \"react\";\n\nimport type { OperationVariables } from \"../../core/index.js\";\nimport type { QueryComponentOptions } from \"./types.js\";\nimport { useQuery } from \"../hooks/index.js\";\n\n/**\n * @deprecated\n * Official support for React Apollo render prop components ended in March 2020.\n * This library is still included in the `@apollo/client` package,\n * but it no longer receives feature updates or bug fixes.\n */\nexport function Query<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n props: QueryComponentOptions<TData, TVariables>\n): ReactTypes.JSX.Element | null {\n const { children, query, ...options } = props;\n const result = useQuery(query, options);\n return result ? children(result as any) : null;\n}\n\nexport interface Query<TData, TVariables extends OperationVariables> {\n propTypes: PropTypes.InferProps<QueryComponentOptions<TData, TVariables>>;\n}\n\nQuery.propTypes = {\n client: PropTypes.object,\n children: PropTypes.func.isRequired,\n fetchPolicy: PropTypes.string,\n notifyOnNetworkStatusChange: PropTypes.bool,\n onCompleted: PropTypes.func,\n onError: PropTypes.func,\n pollInterval: PropTypes.number,\n query: PropTypes.object.isRequired,\n variables: PropTypes.object,\n ssr: PropTypes.bool,\n partialRefetch: PropTypes.bool,\n returnPartialData: PropTypes.bool,\n} as Query<any, any>[\"propTypes\"];\n"]}

View File

@@ -0,0 +1,18 @@
import * as PropTypes from "prop-types";
import type * as ReactTypes from "react";
import type { OperationVariables } from "../../core/index.js";
import type { SubscriptionComponentOptions } from "./types.js";
/**
* @deprecated
* Official support for React Apollo render prop components ended in March 2020.
* This library is still included in the `@apollo/client` package,
* but it no longer receives feature updates or bug fixes.
*/
export declare function Subscription<TData = any, TVariables extends OperationVariables = OperationVariables>(props: SubscriptionComponentOptions<TData, TVariables>): ReactTypes.JSX.Element | null;
export declare namespace Subscription {
var propTypes: PropTypes.InferProps<SubscriptionComponentOptions<any, any>>;
}
export interface Subscription<TData, TVariables extends OperationVariables> {
propTypes: PropTypes.InferProps<SubscriptionComponentOptions<TData, TVariables>>;
}
//# sourceMappingURL=Subscription.d.ts.map

View File

@@ -0,0 +1,23 @@
import * as PropTypes from "prop-types";
import { useSubscription } from "../hooks/index.js";
/**
* @deprecated
* Official support for React Apollo render prop components ended in March 2020.
* This library is still included in the `@apollo/client` package,
* but it no longer receives feature updates or bug fixes.
*/
export function Subscription(props) {
var result = useSubscription(props.subscription, props);
return props.children && result ? props.children(result) : null;
}
Subscription.propTypes = {
subscription: PropTypes.object.isRequired,
variables: PropTypes.object,
children: PropTypes.func,
onSubscriptionData: PropTypes.func,
onData: PropTypes.func,
onSubscriptionComplete: PropTypes.func,
onComplete: PropTypes.func,
shouldResubscribe: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
};
//# sourceMappingURL=Subscription.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Subscription.js","sourceRoot":"","sources":["../../../src/react/components/Subscription.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AAKxC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAI1B,KAAsD;IAEtD,IAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IAC1D,OAAO,KAAK,CAAC,QAAQ,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAClE,CAAC;AAQD,YAAY,CAAC,SAAS,GAAG;IACvB,YAAY,EAAE,SAAS,CAAC,MAAM,CAAC,UAAU;IACzC,SAAS,EAAE,SAAS,CAAC,MAAM;IAC3B,QAAQ,EAAE,SAAS,CAAC,IAAI;IACxB,kBAAkB,EAAE,SAAS,CAAC,IAAI;IAClC,MAAM,EAAE,SAAS,CAAC,IAAI;IACtB,sBAAsB,EAAE,SAAS,CAAC,IAAI;IACtC,UAAU,EAAE,SAAS,CAAC,IAAI;IAC1B,iBAAiB,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;CAClC,CAAC","sourcesContent":["import * as PropTypes from \"prop-types\";\nimport type * as ReactTypes from \"react\";\n\nimport type { OperationVariables } from \"../../core/index.js\";\nimport type { SubscriptionComponentOptions } from \"./types.js\";\nimport { useSubscription } from \"../hooks/index.js\";\n\n/**\n * @deprecated\n * Official support for React Apollo render prop components ended in March 2020.\n * This library is still included in the `@apollo/client` package,\n * but it no longer receives feature updates or bug fixes.\n */\nexport function Subscription<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n props: SubscriptionComponentOptions<TData, TVariables>\n): ReactTypes.JSX.Element | null {\n const result = useSubscription(props.subscription, props);\n return props.children && result ? props.children(result) : null;\n}\n\nexport interface Subscription<TData, TVariables extends OperationVariables> {\n propTypes: PropTypes.InferProps<\n SubscriptionComponentOptions<TData, TVariables>\n >;\n}\n\nSubscription.propTypes = {\n subscription: PropTypes.object.isRequired,\n variables: PropTypes.object,\n children: PropTypes.func,\n onSubscriptionData: PropTypes.func,\n onData: PropTypes.func,\n onSubscriptionComplete: PropTypes.func,\n onComplete: PropTypes.func,\n shouldResubscribe: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),\n} as Subscription<any, any>[\"propTypes\"];\n"]}

View File

@@ -0,0 +1,81 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var tslib = require('tslib');
var PropTypes = require('prop-types');
var hooks = require('../hooks');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
for (var k in e) {
n[k] = e[k];
}
}
n["default"] = e;
return Object.freeze(n);
}
var PropTypes__namespace = /*#__PURE__*/_interopNamespace(PropTypes);
function Query(props) {
var children = props.children, query = props.query, options = tslib.__rest(props, ["children", "query"]);
var result = hooks.useQuery(query, options);
return result ? children(result) : null;
}
Query.propTypes = {
client: PropTypes__namespace.object,
children: PropTypes__namespace.func.isRequired,
fetchPolicy: PropTypes__namespace.string,
notifyOnNetworkStatusChange: PropTypes__namespace.bool,
onCompleted: PropTypes__namespace.func,
onError: PropTypes__namespace.func,
pollInterval: PropTypes__namespace.number,
query: PropTypes__namespace.object.isRequired,
variables: PropTypes__namespace.object,
ssr: PropTypes__namespace.bool,
partialRefetch: PropTypes__namespace.bool,
returnPartialData: PropTypes__namespace.bool,
};
function Mutation(props) {
var _a = hooks.useMutation(props.mutation, props), runMutation = _a[0], result = _a[1];
return props.children ? props.children(runMutation, result) : null;
}
Mutation.propTypes = {
mutation: PropTypes__namespace.object.isRequired,
variables: PropTypes__namespace.object,
optimisticResponse: PropTypes__namespace.oneOfType([PropTypes__namespace.object, PropTypes__namespace.func]),
refetchQueries: PropTypes__namespace.oneOfType([
PropTypes__namespace.arrayOf(PropTypes__namespace.oneOfType([PropTypes__namespace.string, PropTypes__namespace.object])),
PropTypes__namespace.func,
]),
awaitRefetchQueries: PropTypes__namespace.bool,
update: PropTypes__namespace.func,
children: PropTypes__namespace.func.isRequired,
onCompleted: PropTypes__namespace.func,
onError: PropTypes__namespace.func,
fetchPolicy: PropTypes__namespace.string,
};
function Subscription(props) {
var result = hooks.useSubscription(props.subscription, props);
return props.children && result ? props.children(result) : null;
}
Subscription.propTypes = {
subscription: PropTypes__namespace.object.isRequired,
variables: PropTypes__namespace.object,
children: PropTypes__namespace.func,
onSubscriptionData: PropTypes__namespace.func,
onData: PropTypes__namespace.func,
onSubscriptionComplete: PropTypes__namespace.func,
onComplete: PropTypes__namespace.func,
shouldResubscribe: PropTypes__namespace.oneOfType([PropTypes__namespace.func, PropTypes__namespace.bool]),
};
exports.Mutation = Mutation;
exports.Query = Query;
exports.Subscription = Subscription;
//# sourceMappingURL=components.cjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,81 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var tslib = require('tslib');
var PropTypes = require('prop-types');
var hooks = require('../hooks');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
for (var k in e) {
n[k] = e[k];
}
}
n["default"] = e;
return Object.freeze(n);
}
var PropTypes__namespace = /*#__PURE__*/_interopNamespace(PropTypes);
function Query(props) {
var children = props.children, query = props.query, options = tslib.__rest(props, ["children", "query"]);
var result = hooks.useQuery(query, options);
return result ? children(result) : null;
}
Query.propTypes = {
client: PropTypes__namespace.object,
children: PropTypes__namespace.func.isRequired,
fetchPolicy: PropTypes__namespace.string,
notifyOnNetworkStatusChange: PropTypes__namespace.bool,
onCompleted: PropTypes__namespace.func,
onError: PropTypes__namespace.func,
pollInterval: PropTypes__namespace.number,
query: PropTypes__namespace.object.isRequired,
variables: PropTypes__namespace.object,
ssr: PropTypes__namespace.bool,
partialRefetch: PropTypes__namespace.bool,
returnPartialData: PropTypes__namespace.bool,
};
function Mutation(props) {
var _a = hooks.useMutation(props.mutation, props), runMutation = _a[0], result = _a[1];
return props.children ? props.children(runMutation, result) : null;
}
Mutation.propTypes = {
mutation: PropTypes__namespace.object.isRequired,
variables: PropTypes__namespace.object,
optimisticResponse: PropTypes__namespace.oneOfType([PropTypes__namespace.object, PropTypes__namespace.func]),
refetchQueries: PropTypes__namespace.oneOfType([
PropTypes__namespace.arrayOf(PropTypes__namespace.oneOfType([PropTypes__namespace.string, PropTypes__namespace.object])),
PropTypes__namespace.func,
]),
awaitRefetchQueries: PropTypes__namespace.bool,
update: PropTypes__namespace.func,
children: PropTypes__namespace.func.isRequired,
onCompleted: PropTypes__namespace.func,
onError: PropTypes__namespace.func,
fetchPolicy: PropTypes__namespace.string,
};
function Subscription(props) {
var result = hooks.useSubscription(props.subscription, props);
return props.children && result ? props.children(result) : null;
}
Subscription.propTypes = {
subscription: PropTypes__namespace.object.isRequired,
variables: PropTypes__namespace.object,
children: PropTypes__namespace.func,
onSubscriptionData: PropTypes__namespace.func,
onData: PropTypes__namespace.func,
onSubscriptionComplete: PropTypes__namespace.func,
onComplete: PropTypes__namespace.func,
shouldResubscribe: PropTypes__namespace.oneOfType([PropTypes__namespace.func, PropTypes__namespace.bool]),
};
exports.Mutation = Mutation;
exports.Query = Query;
exports.Subscription = Subscription;
//# sourceMappingURL=components.cjs.map

View File

@@ -0,0 +1,5 @@
export { Query } from "./Query.js";
export { Mutation } from "./Mutation.js";
export { Subscription } from "./Subscription.js";
export * from "./types.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,5 @@
export { Query } from "./Query.js";
export { Mutation } from "./Mutation.js";
export { Subscription } from "./Subscription.js";
export * from "./types.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,cAAc,YAAY,CAAC","sourcesContent":["export { Query } from \"./Query.js\";\nexport { Mutation } from \"./Mutation.js\";\nexport { Subscription } from \"./Subscription.js\";\n\nexport * from \"./types.js\";\n"]}

View File

@@ -0,0 +1,8 @@
{
"name": "@apollo/client/react/components",
"type": "module",
"main": "components.cjs",
"module": "index.js",
"types": "index.d.ts",
"sideEffects": false
}

View File

@@ -0,0 +1,21 @@
import type { DocumentNode } from "graphql";
import type { TypedDocumentNode } from "@graphql-typed-document-node/core";
import type * as ReactTypes from "react";
import type { OperationVariables, DefaultContext, ApolloCache } from "../../core/index.js";
import type { QueryFunctionOptions, QueryResult, BaseMutationOptions, MutationFunction, MutationResult, BaseSubscriptionOptions, SubscriptionResult } from "../types/types.js";
export interface QueryComponentOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends QueryFunctionOptions<TData, TVariables> {
children: (result: QueryResult<TData, TVariables>) => ReactTypes.JSX.Element | null;
query: DocumentNode | TypedDocumentNode<TData, TVariables>;
}
export interface MutationComponentOptions<TData = any, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>> extends BaseMutationOptions<TData, TVariables, TContext, TCache> {
mutation: DocumentNode | TypedDocumentNode<TData, TVariables>;
children: (mutateFunction: MutationFunction<TData, TVariables, TContext>, result: MutationResult<TData>) => ReactTypes.JSX.Element | null;
}
export interface SubscriptionComponentOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends BaseSubscriptionOptions<TData, TVariables> {
/**
* A GraphQL document, often created with `gql` from the `graphql-tag` package, that contains a single subscription inside of it.
*/
subscription: DocumentNode | TypedDocumentNode<TData, TVariables>;
children?: null | ((result: SubscriptionResult<TData>) => ReactTypes.JSX.Element | null);
}
//# sourceMappingURL=types.d.ts.map

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/react/components/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DocumentNode } from \"graphql\";\nimport type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\n\nimport type * as ReactTypes from \"react\";\n\nimport type {\n OperationVariables,\n DefaultContext,\n ApolloCache,\n} from \"../../core/index.js\";\nimport type {\n QueryFunctionOptions,\n QueryResult,\n BaseMutationOptions,\n MutationFunction,\n MutationResult,\n BaseSubscriptionOptions,\n SubscriptionResult,\n} from \"../types/types.js\";\n\nexport interface QueryComponentOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends QueryFunctionOptions<TData, TVariables> {\n children: (\n result: QueryResult<TData, TVariables>\n ) => ReactTypes.JSX.Element | null;\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n}\n\nexport interface MutationComponentOptions<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> extends BaseMutationOptions<TData, TVariables, TContext, TCache> {\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>;\n children: (\n mutateFunction: MutationFunction<TData, TVariables, TContext>,\n result: MutationResult<TData>\n ) => ReactTypes.JSX.Element | null;\n}\n\nexport interface SubscriptionComponentOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n> extends BaseSubscriptionOptions<TData, TVariables> {\n /** {@inheritDoc @apollo/client!SubscriptionOptionsDocumentation#query:member} */\n subscription: DocumentNode | TypedDocumentNode<TData, TVariables>;\n children?:\n | null\n | ((result: SubscriptionResult<TData>) => ReactTypes.JSX.Element | null);\n}\n"]}

View File

@@ -0,0 +1,7 @@
import type * as ReactTypes from "react";
import type { ApolloClient } from "../../core/index.js";
export interface ApolloConsumerProps {
children: (client: ApolloClient<object>) => ReactTypes.ReactChild | null;
}
export declare const ApolloConsumer: ReactTypes.FC<ApolloConsumerProps>;
//# sourceMappingURL=ApolloConsumer.d.ts.map

View File

@@ -0,0 +1,11 @@
import { invariant } from "../../utilities/globals/index.js";
import * as React from "rehackt";
import { getApolloContext } from "./ApolloContext.js";
export var ApolloConsumer = function (props) {
var ApolloContext = getApolloContext();
return (React.createElement(ApolloContext.Consumer, null, function (context) {
invariant(context && context.client, 44);
return props.children(context.client);
}));
};
//# sourceMappingURL=ApolloConsumer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ApolloConsumer.js","sourceRoot":"","sources":["../../../src/react/context/ApolloConsumer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE7D,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAIjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAMtD,MAAM,CAAC,IAAM,cAAc,GAAuC,UAAC,KAAK;IACtE,IAAM,aAAa,GAAG,gBAAgB,EAAE,CAAC;IACzC,OAAO,CACL,oBAAC,aAAa,CAAC,QAAQ,QACpB,UAAC,OAAY;QACZ,SAAS,CACP,OAAO,IAAI,OAAO,CAAC,MAAM,EACzB,4DAA4D;YAC1D,iDAAiD,CACpD,CAAC;QACF,OAAO,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC,CACsB,CAC1B,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { invariant } from \"../../utilities/globals/index.js\";\n\nimport * as React from \"rehackt\";\nimport type * as ReactTypes from \"react\";\n\nimport type { ApolloClient } from \"../../core/index.js\";\nimport { getApolloContext } from \"./ApolloContext.js\";\n\nexport interface ApolloConsumerProps {\n children: (client: ApolloClient<object>) => ReactTypes.ReactChild | null;\n}\n\nexport const ApolloConsumer: ReactTypes.FC<ApolloConsumerProps> = (props) => {\n const ApolloContext = getApolloContext();\n return (\n <ApolloContext.Consumer>\n {(context: any) => {\n invariant(\n context && context.client,\n 'Could not find \"client\" in the context of ApolloConsumer. ' +\n \"Wrap the root component in an <ApolloProvider>.\"\n );\n return props.children(context.client);\n }}\n </ApolloContext.Consumer>\n );\n};\n"]}

View File

@@ -0,0 +1,15 @@
import type * as ReactTypes from "react";
import type { ApolloClient } from "../../core/index.js";
import type { RenderPromises } from "../ssr/index.js";
export interface ApolloContextValue {
client?: ApolloClient<object>;
renderPromises?: RenderPromises;
}
export declare function getApolloContext(): ReactTypes.Context<ApolloContextValue>;
/**
* @deprecated This function has no "resetting" effect since Apollo Client 3.4.12,
* and will be removed in the next major version of Apollo Client.
* If you want to get the Apollo Context, use `getApolloContext` instead.
*/
export declare const resetApolloContext: typeof getApolloContext;
//# sourceMappingURL=ApolloContext.d.ts.map

View File

@@ -0,0 +1,29 @@
import * as React from "rehackt";
import { canUseSymbol } from "../../utilities/index.js";
import { invariant } from "../../utilities/globals/index.js";
// To make sure Apollo Client doesn't create more than one React context
// (which can lead to problems like having an Apollo Client instance added
// in one context, then attempting to retrieve it from another different
// context), a single Apollo context is created and tracked in global state.
var contextKey = canUseSymbol ? Symbol.for("__APOLLO_CONTEXT__") : "__APOLLO_CONTEXT__";
export function getApolloContext() {
invariant("createContext" in React, 45);
var context = React.createContext[contextKey];
if (!context) {
Object.defineProperty(React.createContext, contextKey, {
value: (context = React.createContext({})),
enumerable: false,
writable: false,
configurable: true,
});
context.displayName = "ApolloContext";
}
return context;
}
/**
* @deprecated This function has no "resetting" effect since Apollo Client 3.4.12,
* and will be removed in the next major version of Apollo Client.
* If you want to get the Apollo Context, use `getApolloContext` instead.
*/
export var resetApolloContext = getApolloContext;
//# sourceMappingURL=ApolloContext.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ApolloContext.js","sourceRoot":"","sources":["../../../src/react/context/ApolloContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAGjC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAO7D,wEAAwE;AACxE,0EAA0E;AAC1E,wEAAwE;AACxE,4EAA4E;AAC5E,IAAM,UAAU,GACd,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC;AAEzE,MAAM,UAAU,gBAAgB;IAC9B,SAAS,CACP,eAAe,IAAI,KAAK,EACxB,+FAA+F;QAC7F,uGAAuG;QACvG,iEAAiE;QACjE,4GAA4G;QAC5G,sGAAsG,CACzG,CAAC;IAEF,IAAI,OAAO,GAAI,KAAK,CAAC,aAAqB,CACxC,UAAU,CAC0B,CAAC;IACvC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,aAAa,EAAE,UAAU,EAAE;YACrD,KAAK,EAAE,CAAC,OAAO,GAAG,KAAK,CAAC,aAAa,CAAqB,EAAE,CAAC,CAAC;YAC9D,UAAU,EAAE,KAAK;YACjB,QAAQ,EAAE,KAAK;YACf,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;QACH,OAAO,CAAC,WAAW,GAAG,eAAe,CAAC;IACxC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,IAAM,kBAAkB,GAAG,gBAAgB,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport type * as ReactTypes from \"react\";\nimport type { ApolloClient } from \"../../core/index.js\";\nimport { canUseSymbol } from \"../../utilities/index.js\";\nimport type { RenderPromises } from \"../ssr/index.js\";\nimport { invariant } from \"../../utilities/globals/index.js\";\n\nexport interface ApolloContextValue {\n client?: ApolloClient<object>;\n renderPromises?: RenderPromises;\n}\n\n// To make sure Apollo Client doesn't create more than one React context\n// (which can lead to problems like having an Apollo Client instance added\n// in one context, then attempting to retrieve it from another different\n// context), a single Apollo context is created and tracked in global state.\nconst contextKey =\n canUseSymbol ? Symbol.for(\"__APOLLO_CONTEXT__\") : \"__APOLLO_CONTEXT__\";\n\nexport function getApolloContext(): ReactTypes.Context<ApolloContextValue> {\n invariant(\n \"createContext\" in React,\n \"Invoking `getApolloContext` in an environment where `React.createContext` is not available.\\n\" +\n \"The Apollo Client functionality you are trying to use is only available in React Client Components.\\n\" +\n 'Please make sure to add \"use client\" at the top of your file.\\n' +\n // TODO: change to React documentation once React documentation contains information about Client Components\n \"For more information, see https://nextjs.org/docs/getting-started/react-essentials#client-components\"\n );\n\n let context = (React.createContext as any)[\n contextKey\n ] as React.Context<ApolloContextValue>;\n if (!context) {\n Object.defineProperty(React.createContext, contextKey, {\n value: (context = React.createContext<ApolloContextValue>({})),\n enumerable: false,\n writable: false,\n configurable: true,\n });\n context.displayName = \"ApolloContext\";\n }\n return context;\n}\n\n/**\n * @deprecated This function has no \"resetting\" effect since Apollo Client 3.4.12,\n * and will be removed in the next major version of Apollo Client.\n * If you want to get the Apollo Context, use `getApolloContext` instead.\n */\nexport const resetApolloContext = getApolloContext;\n"]}

View File

@@ -0,0 +1,8 @@
import type * as ReactTypes from "react";
import type { ApolloClient } from "../../core/index.js";
export interface ApolloProviderProps<TCache> {
client: ApolloClient<TCache>;
children: ReactTypes.ReactNode | ReactTypes.ReactNode[] | null;
}
export declare const ApolloProvider: ReactTypes.FC<ApolloProviderProps<any>>;
//# sourceMappingURL=ApolloProvider.d.ts.map

View File

@@ -0,0 +1,15 @@
import { __assign } from "tslib";
import { invariant } from "../../utilities/globals/index.js";
import * as React from "rehackt";
import { getApolloContext } from "./ApolloContext.js";
export var ApolloProvider = function (_a) {
var client = _a.client, children = _a.children;
var ApolloContext = getApolloContext();
var parentContext = React.useContext(ApolloContext);
var context = React.useMemo(function () {
return __assign(__assign({}, parentContext), { client: client || parentContext.client });
}, [parentContext, client]);
invariant(context.client, 46);
return (React.createElement(ApolloContext.Provider, { value: context }, children));
};
//# sourceMappingURL=ApolloProvider.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ApolloProvider.js","sourceRoot":"","sources":["../../../src/react/context/ApolloProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE7D,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAIjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAOtD,MAAM,CAAC,IAAM,cAAc,GAA4C,UAAC,EAGvE;QAFC,MAAM,YAAA,EACN,QAAQ,cAAA;IAER,IAAM,aAAa,GAAG,gBAAgB,EAAE,CAAC;IACzC,IAAM,aAAa,GAAG,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IAEtD,IAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC5B,6BACK,aAAa,KAChB,MAAM,EAAE,MAAM,IAAI,aAAa,CAAC,MAAM,IACtC;IACJ,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC;IAE5B,SAAS,CACP,OAAO,CAAC,MAAM,EACd,wDAAwD;QACtD,qDAAqD,CACxD,CAAC;IAEF,OAAO,CACL,oBAAC,aAAa,CAAC,QAAQ,IAAC,KAAK,EAAE,OAAO,IAAG,QAAQ,CAA0B,CAC5E,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { invariant } from \"../../utilities/globals/index.js\";\n\nimport * as React from \"rehackt\";\nimport type * as ReactTypes from \"react\";\n\nimport type { ApolloClient } from \"../../core/index.js\";\nimport { getApolloContext } from \"./ApolloContext.js\";\n\nexport interface ApolloProviderProps<TCache> {\n client: ApolloClient<TCache>;\n children: ReactTypes.ReactNode | ReactTypes.ReactNode[] | null;\n}\n\nexport const ApolloProvider: ReactTypes.FC<ApolloProviderProps<any>> = ({\n client,\n children,\n}) => {\n const ApolloContext = getApolloContext();\n const parentContext = React.useContext(ApolloContext);\n\n const context = React.useMemo(() => {\n return {\n ...parentContext,\n client: client || parentContext.client,\n };\n }, [parentContext, client]);\n\n invariant(\n context.client,\n \"ApolloProvider was not passed a client instance. Make \" +\n 'sure you pass in your client via the \"client\" prop.'\n );\n\n return (\n <ApolloContext.Provider value={context}>{children}</ApolloContext.Provider>\n );\n};\n"]}

View File

@@ -0,0 +1,64 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var globals = require('../../utilities/globals');
var React = require('rehackt');
var utilities = require('../../utilities');
var tslib = require('tslib');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
for (var k in e) {
n[k] = e[k];
}
}
n["default"] = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespace(React);
var contextKey = utilities.canUseSymbol ? Symbol.for("__APOLLO_CONTEXT__") : "__APOLLO_CONTEXT__";
function getApolloContext() {
globals.invariant("createContext" in React__namespace, 45);
var context = React__namespace.createContext[contextKey];
if (!context) {
Object.defineProperty(React__namespace.createContext, contextKey, {
value: (context = React__namespace.createContext({})),
enumerable: false,
writable: false,
configurable: true,
});
context.displayName = "ApolloContext";
}
return context;
}
var resetApolloContext = getApolloContext;
var ApolloConsumer = function (props) {
var ApolloContext = getApolloContext();
return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
globals.invariant(context && context.client, 44);
return props.children(context.client);
}));
};
var ApolloProvider = function (_a) {
var client = _a.client, children = _a.children;
var ApolloContext = getApolloContext();
var parentContext = React__namespace.useContext(ApolloContext);
var context = React__namespace.useMemo(function () {
return tslib.__assign(tslib.__assign({}, parentContext), { client: client || parentContext.client });
}, [parentContext, client]);
globals.invariant(context.client, 46);
return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
};
exports.ApolloConsumer = ApolloConsumer;
exports.ApolloProvider = ApolloProvider;
exports.getApolloContext = getApolloContext;
exports.resetApolloContext = resetApolloContext;
//# sourceMappingURL=context.cjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"context.cjs","sources":["ApolloContext.js","ApolloConsumer.js","ApolloProvider.js"],"sourcesContent":["import * as React from \"rehackt\";\nimport { canUseSymbol } from \"../../utilities/index.js\";\nimport { invariant } from \"../../utilities/globals/index.js\";\n// To make sure Apollo Client doesn't create more than one React context\n// (which can lead to problems like having an Apollo Client instance added\n// in one context, then attempting to retrieve it from another different\n// context), a single Apollo context is created and tracked in global state.\nvar contextKey = canUseSymbol ? Symbol.for(\"__APOLLO_CONTEXT__\") : \"__APOLLO_CONTEXT__\";\nexport function getApolloContext() {\n invariant(\"createContext\" in React, 45);\n var context = React.createContext[contextKey];\n if (!context) {\n Object.defineProperty(React.createContext, contextKey, {\n value: (context = React.createContext({})),\n enumerable: false,\n writable: false,\n configurable: true,\n });\n context.displayName = \"ApolloContext\";\n }\n return context;\n}\n/**\n * @deprecated This function has no \"resetting\" effect since Apollo Client 3.4.12,\n * and will be removed in the next major version of Apollo Client.\n * If you want to get the Apollo Context, use `getApolloContext` instead.\n */\nexport var resetApolloContext = getApolloContext;\n//# sourceMappingURL=ApolloContext.js.map","import { invariant } from \"../../utilities/globals/index.js\";\nimport * as React from \"rehackt\";\nimport { getApolloContext } from \"./ApolloContext.js\";\nexport var ApolloConsumer = function (props) {\n var ApolloContext = getApolloContext();\n return (React.createElement(ApolloContext.Consumer, null, function (context) {\n invariant(context && context.client, 44);\n return props.children(context.client);\n }));\n};\n//# sourceMappingURL=ApolloConsumer.js.map","import { __assign } from \"tslib\";\nimport { invariant } from \"../../utilities/globals/index.js\";\nimport * as React from \"rehackt\";\nimport { getApolloContext } from \"./ApolloContext.js\";\nexport var ApolloProvider = function (_a) {\n var client = _a.client, children = _a.children;\n var ApolloContext = getApolloContext();\n var parentContext = React.useContext(ApolloContext);\n var context = React.useMemo(function () {\n return __assign(__assign({}, parentContext), { client: client || parentContext.client });\n }, [parentContext, client]);\n invariant(context.client, 46);\n return (React.createElement(ApolloContext.Provider, { value: context }, children));\n};\n//# sourceMappingURL=ApolloProvider.js.map"],"names":["canUseSymbol","invariant","React","__assign"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAOA,IAAI,UAAU,GAAGA,sBAAY,GAAG,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,GAAG,oBAAoB,CAAC;AACjF,SAAS,gBAAgB,GAAG;AACnC,IAAIC,iBAAS,CAAC,eAAe,IAAIC,gBAAK,EAAE,EAAE,CAAC,CAAC;AAC5C,IAAI,IAAI,OAAO,GAAGA,gBAAK,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;AAClD,IAAI,IAAI,CAAC,OAAO,EAAE;AAClB,QAAQ,MAAM,CAAC,cAAc,CAACA,gBAAK,CAAC,aAAa,EAAE,UAAU,EAAE;AAC/D,YAAY,KAAK,GAAG,OAAO,GAAGA,gBAAK,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;AACtD,YAAY,UAAU,EAAE,KAAK;AAC7B,YAAY,QAAQ,EAAE,KAAK;AAC3B,YAAY,YAAY,EAAE,IAAI;AAC9B,SAAS,CAAC,CAAC;AACX,QAAQ,OAAO,CAAC,WAAW,GAAG,eAAe,CAAC;AAC9C,KAAK;AACL,IAAI,OAAO,OAAO,CAAC;AACnB,CAAC;AAMS,IAAC,kBAAkB,GAAG;;ACxBtB,IAAC,cAAc,GAAG,UAAU,KAAK,EAAE;AAC7C,IAAI,IAAI,aAAa,GAAG,gBAAgB,EAAE,CAAC;AAC3C,IAAI,QAAQA,gBAAK,CAAC,aAAa,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,UAAU,OAAO,EAAE;AACjF,QAAQD,iBAAS,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACjD,QAAQ,OAAO,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AAC9C,KAAK,CAAC,EAAE;AACR;;ACLU,IAAC,cAAc,GAAG,UAAU,EAAE,EAAE;AAC1C,IAAI,IAAI,MAAM,GAAG,EAAE,CAAC,MAAM,EAAE,QAAQ,GAAG,EAAE,CAAC,QAAQ,CAAC;AACnD,IAAI,IAAI,aAAa,GAAG,gBAAgB,EAAE,CAAC;AAC3C,IAAI,IAAI,aAAa,GAAGC,gBAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AACxD,IAAI,IAAI,OAAO,GAAGA,gBAAK,CAAC,OAAO,CAAC,YAAY;AAC5C,QAAQ,OAAOC,cAAQ,CAACA,cAAQ,CAAC,EAAE,EAAE,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,IAAI,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC;AACjG,KAAK,EAAE,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC;AAChC,IAAIF,iBAAS,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAClC,IAAI,QAAQC,gBAAK,CAAC,aAAa,CAAC,aAAa,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,QAAQ,CAAC,EAAE;AACvF;;;;;;;"}

View File

@@ -0,0 +1,64 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var globals = require('../../utilities/globals');
var React = require('rehackt');
var utilities = require('../../utilities');
var tslib = require('tslib');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
for (var k in e) {
n[k] = e[k];
}
}
n["default"] = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespace(React);
var contextKey = utilities.canUseSymbol ? Symbol.for("__APOLLO_CONTEXT__") : "__APOLLO_CONTEXT__";
function getApolloContext() {
globals.invariant("createContext" in React__namespace, 45);
var context = React__namespace.createContext[contextKey];
if (!context) {
Object.defineProperty(React__namespace.createContext, contextKey, {
value: (context = React__namespace.createContext({})),
enumerable: false,
writable: false,
configurable: true,
});
context.displayName = "ApolloContext";
}
return context;
}
var resetApolloContext = getApolloContext;
var ApolloConsumer = function (props) {
var ApolloContext = getApolloContext();
return (React__namespace.createElement(ApolloContext.Consumer, null, function (context) {
globals.invariant(context && context.client, 44);
return props.children(context.client);
}));
};
var ApolloProvider = function (_a) {
var client = _a.client, children = _a.children;
var ApolloContext = getApolloContext();
var parentContext = React__namespace.useContext(ApolloContext);
var context = React__namespace.useMemo(function () {
return tslib.__assign(tslib.__assign({}, parentContext), { client: client || parentContext.client });
}, [parentContext, client]);
globals.invariant(context.client, 46);
return (React__namespace.createElement(ApolloContext.Provider, { value: context }, children));
};
exports.ApolloConsumer = ApolloConsumer;
exports.ApolloProvider = ApolloProvider;
exports.getApolloContext = getApolloContext;
exports.resetApolloContext = resetApolloContext;
//# sourceMappingURL=context.cjs.map

View File

@@ -0,0 +1,8 @@
import "../../utilities/globals/index.js";
export type { ApolloConsumerProps } from "./ApolloConsumer.js";
export { ApolloConsumer } from "./ApolloConsumer.js";
export type { ApolloContextValue } from "./ApolloContext.js";
export { getApolloContext, resetApolloContext } from "./ApolloContext.js";
export type { ApolloProviderProps } from "./ApolloProvider.js";
export { ApolloProvider } from "./ApolloProvider.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,5 @@
import "../../utilities/globals/index.js";
export { ApolloConsumer } from "./ApolloConsumer.js";
export { getApolloContext, resetApolloContext } from "./ApolloContext.js";
export { ApolloProvider } from "./ApolloProvider.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAG1C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE1E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["import \"../../utilities/globals/index.js\";\n\nexport type { ApolloConsumerProps } from \"./ApolloConsumer.js\";\nexport { ApolloConsumer } from \"./ApolloConsumer.js\";\nexport type { ApolloContextValue } from \"./ApolloContext.js\";\nexport { getApolloContext, resetApolloContext } from \"./ApolloContext.js\";\nexport type { ApolloProviderProps } from \"./ApolloProvider.js\";\nexport { ApolloProvider } from \"./ApolloProvider.js\";\n"]}

View File

@@ -0,0 +1,8 @@
{
"name": "@apollo/client/react/context",
"type": "module",
"main": "context.cjs",
"module": "index.js",
"types": "index.d.ts",
"sideEffects": false
}

View File

@@ -0,0 +1,11 @@
import type { DocumentNode } from "graphql";
import type * as ReactTypes from "react";
import type { OperationOption, DataProps, MutateProps } from "./types.js";
import type { OperationVariables } from "../../core/index.js";
/**
* @deprecated
* Official support for React Apollo higher order components ended in March 2020.
* This library is still included in the `@apollo/client` package, but it no longer receives feature updates or bug fixes.
*/
export declare function graphql<TProps extends TGraphQLVariables | {} = {}, TData extends object = {}, TGraphQLVariables extends OperationVariables = {}, TChildProps extends object = Partial<DataProps<TData, TGraphQLVariables>> & Partial<MutateProps<TData, TGraphQLVariables>>>(document: DocumentNode, operationOptions?: OperationOption<TProps, TData, TGraphQLVariables, TChildProps>): (WrappedComponent: ReactTypes.ComponentType<TProps & TChildProps>) => ReactTypes.ComponentClass<TProps>;
//# sourceMappingURL=graphql.d.ts.map

View File

@@ -0,0 +1,22 @@
import { parser, DocumentType } from "../parser/index.js";
import { withQuery } from "./query-hoc.js";
import { withMutation } from "./mutation-hoc.js";
import { withSubscription } from "./subscription-hoc.js";
/**
* @deprecated
* Official support for React Apollo higher order components ended in March 2020.
* This library is still included in the `@apollo/client` package, but it no longer receives feature updates or bug fixes.
*/
export function graphql(document, operationOptions) {
if (operationOptions === void 0) { operationOptions = {}; }
switch (parser(document).type) {
case DocumentType.Mutation:
return withMutation(document, operationOptions);
case DocumentType.Subscription:
return withSubscription(document, operationOptions);
case DocumentType.Query:
default:
return withQuery(document, operationOptions);
}
}
//# sourceMappingURL=graphql.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../../src/react/hoc/graphql.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAIzD;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAOrB,QAAsB,EACtB,gBAKM;IALN,iCAAA,EAAA,qBAKM;IAIN,QAAQ,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QAC9B,KAAK,YAAY,CAAC,QAAQ;YACxB,OAAO,YAAY,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QAClD,KAAK,YAAY,CAAC,YAAY;YAC5B,OAAO,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QACtD,KAAK,YAAY,CAAC,KAAK,CAAC;QACxB;YACE,OAAO,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;IACjD,CAAC;AACH,CAAC","sourcesContent":["import type { DocumentNode } from \"graphql\";\nimport type * as ReactTypes from \"react\";\n\nimport { parser, DocumentType } from \"../parser/index.js\";\nimport { withQuery } from \"./query-hoc.js\";\nimport { withMutation } from \"./mutation-hoc.js\";\nimport { withSubscription } from \"./subscription-hoc.js\";\nimport type { OperationOption, DataProps, MutateProps } from \"./types.js\";\nimport type { OperationVariables } from \"../../core/index.js\";\n\n/**\n * @deprecated\n * Official support for React Apollo higher order components ended in March 2020.\n * This library is still included in the `@apollo/client` package, but it no longer receives feature updates or bug fixes.\n */\nexport function graphql<\n TProps extends TGraphQLVariables | {} = {},\n TData extends object = {},\n TGraphQLVariables extends OperationVariables = {},\n TChildProps extends object = Partial<DataProps<TData, TGraphQLVariables>> &\n Partial<MutateProps<TData, TGraphQLVariables>>,\n>(\n document: DocumentNode,\n operationOptions: OperationOption<\n TProps,\n TData,\n TGraphQLVariables,\n TChildProps\n > = {}\n): (\n WrappedComponent: ReactTypes.ComponentType<TProps & TChildProps>\n) => ReactTypes.ComponentClass<TProps> {\n switch (parser(document).type) {\n case DocumentType.Mutation:\n return withMutation(document, operationOptions);\n case DocumentType.Subscription:\n return withSubscription(document, operationOptions);\n case DocumentType.Query:\n default:\n return withQuery(document, operationOptions);\n }\n}\n"]}

View File

@@ -0,0 +1,18 @@
/// <reference types="react" />
import * as React from "rehackt";
import type { OperationVariables } from "../../core/index.js";
import type { IDocumentDefinition } from "../parser/index.js";
export declare const defaultMapPropsToOptions: () => {};
export declare const defaultMapResultToProps: <P>(props: P) => P;
export declare const defaultMapPropsToSkip: () => boolean;
export declare function getDisplayName<P>(WrappedComponent: React.ComponentType<P>): string;
export declare function calculateVariablesFromProps<TProps>(operation: IDocumentDefinition, props: TProps): OperationVariables;
export type RefSetter<TChildProps> = (ref: React.ComponentClass<TChildProps>) => void | void;
export declare class GraphQLBase<TProps, TChildProps, TState = any> extends React.Component<TProps, TState> {
withRef: boolean;
private wrappedInstance?;
constructor(props: TProps);
getWrappedInstance(): React.ComponentClass<TChildProps, any> | undefined;
setWrappedInstance(ref: React.ComponentClass<TChildProps>): void;
}
//# sourceMappingURL=hoc-utils.d.ts.map

View File

@@ -0,0 +1,48 @@
import { __extends } from "tslib";
import { invariant } from "../../utilities/globals/index.js";
import * as React from "rehackt";
export var defaultMapPropsToOptions = function () { return ({}); };
export var defaultMapResultToProps = function (props) { return props; };
export var defaultMapPropsToSkip = function () { return false; };
export function getDisplayName(WrappedComponent) {
return WrappedComponent.displayName || WrappedComponent.name || "Component";
}
export function calculateVariablesFromProps(operation, props) {
var variables = {};
for (var _i = 0, _a = operation.variables; _i < _a.length; _i++) {
var _b = _a[_i], variable = _b.variable, type = _b.type;
if (!variable.name || !variable.name.value)
continue;
var variableName = variable.name.value;
var variableProp = props[variableName];
if (typeof variableProp !== "undefined") {
variables[variableName] = variableProp;
continue;
}
// Allow optional props
if (type.kind !== "NonNullType") {
variables[variableName] = undefined;
}
}
return variables;
}
// base class for hocs to easily manage refs
var GraphQLBase = /** @class */ (function (_super) {
__extends(GraphQLBase, _super);
function GraphQLBase(props) {
var _this = _super.call(this, props) || this;
_this.withRef = false;
_this.setWrappedInstance = _this.setWrappedInstance.bind(_this);
return _this;
}
GraphQLBase.prototype.getWrappedInstance = function () {
invariant(this.withRef, 47);
return this.wrappedInstance;
};
GraphQLBase.prototype.setWrappedInstance = function (ref) {
this.wrappedInstance = ref;
};
return GraphQLBase;
}(React.Component));
export { GraphQLBase };
//# sourceMappingURL=hoc-utils.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"hoc-utils.js","sourceRoot":"","sources":["../../../src/react/hoc/hoc-utils.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAIjC,MAAM,CAAC,IAAM,wBAAwB,GAAG,cAAM,OAAA,CAAC,EAAE,CAAC,EAAJ,CAAI,CAAC;AACnD,MAAM,CAAC,IAAM,uBAAuB,GAAuB,UAAC,KAAK,IAAK,OAAA,KAAK,EAAL,CAAK,CAAC;AAC5E,MAAM,CAAC,IAAM,qBAAqB,GAAG,cAAM,OAAA,KAAK,EAAL,CAAK,CAAC;AAEjD,MAAM,UAAU,cAAc,CAAI,gBAAwC;IACxE,OAAO,gBAAgB,CAAC,WAAW,IAAI,gBAAgB,CAAC,IAAI,IAAI,WAAW,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,2BAA2B,CACzC,SAA8B,EAC9B,KAAa;IAEb,IAAI,SAAS,GAAuB,EAAE,CAAC;IACvC,KAA+B,UAAmB,EAAnB,KAAA,SAAS,CAAC,SAAS,EAAnB,cAAmB,EAAnB,IAAmB,EAAE,CAAC;QAA5C,IAAA,WAAkB,EAAhB,QAAQ,cAAA,EAAE,IAAI,UAAA;QACvB,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK;YAAE,SAAS;QAErD,IAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;QACzC,IAAM,YAAY,GAAI,KAAa,CAAC,YAAY,CAAC,CAAC;QAElD,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE,CAAC;YACxC,SAAS,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC;YACvC,SAAS;QACX,CAAC;QAED,uBAAuB;QACvB,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;YAChC,SAAS,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;QACtC,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAMD,4CAA4C;AAC5C;IAIU,+BAA+B;IAKvC,qBAAY,KAAa;QACvB,YAAA,MAAK,YAAC,KAAK,CAAC,SAAC;QALR,aAAO,GAAY,KAAK,CAAC;QAM9B,KAAI,CAAC,kBAAkB,GAAG,KAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAI,CAAC,CAAC;;IAC/D,CAAC;IAED,wCAAkB,GAAlB;QACE,SAAS,CACP,IAAI,CAAC,OAAO,EACZ,sDAAsD;YACpD,kCAAkC,CACrC,CAAC;QAEF,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED,wCAAkB,GAAlB,UAAmB,GAAsC;QACvD,IAAI,CAAC,eAAe,GAAG,GAAG,CAAC;IAC7B,CAAC;IACH,kBAAC;AAAD,CAAC,AA3BD,CAIU,KAAK,CAAC,SAAS,GAuBxB","sourcesContent":["import { invariant } from \"../../utilities/globals/index.js\";\nimport * as React from \"rehackt\";\nimport type { OperationVariables } from \"../../core/index.js\";\nimport type { IDocumentDefinition } from \"../parser/index.js\";\n\nexport const defaultMapPropsToOptions = () => ({});\nexport const defaultMapResultToProps: <P>(props: P) => P = (props) => props;\nexport const defaultMapPropsToSkip = () => false;\n\nexport function getDisplayName<P>(WrappedComponent: React.ComponentType<P>) {\n return WrappedComponent.displayName || WrappedComponent.name || \"Component\";\n}\n\nexport function calculateVariablesFromProps<TProps>(\n operation: IDocumentDefinition,\n props: TProps\n) {\n let variables: OperationVariables = {};\n for (let { variable, type } of operation.variables) {\n if (!variable.name || !variable.name.value) continue;\n\n const variableName = variable.name.value;\n const variableProp = (props as any)[variableName];\n\n if (typeof variableProp !== \"undefined\") {\n variables[variableName] = variableProp;\n continue;\n }\n\n // Allow optional props\n if (type.kind !== \"NonNullType\") {\n variables[variableName] = undefined;\n }\n }\n return variables;\n}\n\nexport type RefSetter<TChildProps> = (\n ref: React.ComponentClass<TChildProps>\n) => void | void;\n\n// base class for hocs to easily manage refs\nexport class GraphQLBase<\n TProps,\n TChildProps,\n TState = any,\n> extends React.Component<TProps, TState> {\n public withRef: boolean = false;\n // wrapped instance\n private wrappedInstance?: React.ComponentClass<TChildProps>;\n\n constructor(props: TProps) {\n super(props);\n this.setWrappedInstance = this.setWrappedInstance.bind(this);\n }\n\n getWrappedInstance() {\n invariant(\n this.withRef,\n `To access the wrapped instance, you need to specify ` +\n `{ withRef: true } in the options`\n );\n\n return this.wrappedInstance;\n }\n\n setWrappedInstance(ref: React.ComponentClass<TChildProps>) {\n this.wrappedInstance = ref;\n }\n}\n"]}

View File

@@ -0,0 +1,316 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var globals = require('../../utilities/globals');
var parser = require('../parser');
var tslib = require('tslib');
var React = require('rehackt');
var hoistNonReactStatics = require('hoist-non-react-statics');
var components = require('../components');
var context = require('../context');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
for (var k in e) {
n[k] = e[k];
}
}
n["default"] = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespace(React);
var hoistNonReactStatics__default = /*#__PURE__*/_interopDefaultLegacy(hoistNonReactStatics);
var defaultMapPropsToOptions = function () { return ({}); };
var defaultMapPropsToSkip = function () { return false; };
function getDisplayName$1(WrappedComponent) {
return WrappedComponent.displayName || WrappedComponent.name || "Component";
}
function calculateVariablesFromProps(operation, props) {
var variables = {};
for (var _i = 0, _a = operation.variables; _i < _a.length; _i++) {
var _b = _a[_i], variable = _b.variable, type = _b.type;
if (!variable.name || !variable.name.value)
continue;
var variableName = variable.name.value;
var variableProp = props[variableName];
if (typeof variableProp !== "undefined") {
variables[variableName] = variableProp;
continue;
}
if (type.kind !== "NonNullType") {
variables[variableName] = undefined;
}
}
return variables;
}
var GraphQLBase = (function (_super) {
tslib.__extends(GraphQLBase, _super);
function GraphQLBase(props) {
var _this = _super.call(this, props) || this;
_this.withRef = false;
_this.setWrappedInstance = _this.setWrappedInstance.bind(_this);
return _this;
}
GraphQLBase.prototype.getWrappedInstance = function () {
globals.invariant(this.withRef, 47);
return this.wrappedInstance;
};
GraphQLBase.prototype.setWrappedInstance = function (ref) {
this.wrappedInstance = ref;
};
return GraphQLBase;
}(React__namespace.Component));
function withQuery(document, operationOptions) {
if (operationOptions === void 0) { operationOptions = {}; }
var operation = parser.parser(document);
var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.skip, skip = _b === void 0 ? defaultMapPropsToSkip : _b, _c = operationOptions.alias, alias = _c === void 0 ? "Apollo" : _c;
var mapPropsToOptions = options;
if (typeof mapPropsToOptions !== "function") {
mapPropsToOptions = function () { return options; };
}
var mapPropsToSkip = skip;
if (typeof mapPropsToSkip !== "function") {
mapPropsToSkip = function () { return skip; };
}
var lastResultProps;
return function (WrappedComponent) {
var graphQLDisplayName = "".concat(alias, "(").concat(getDisplayName$1(WrappedComponent), ")");
var GraphQL = (function (_super) {
tslib.__extends(GraphQL, _super);
function GraphQL() {
return _super !== null && _super.apply(this, arguments) || this;
}
GraphQL.prototype.render = function () {
var _this = this;
var props = this.props;
var shouldSkip = mapPropsToSkip(props);
var opts = shouldSkip ? Object.create(null) : tslib.__assign({}, mapPropsToOptions(props));
if (!shouldSkip && !opts.variables && operation.variables.length > 0) {
opts.variables = calculateVariablesFromProps(operation, props);
}
return (React__namespace.createElement(components.Query, tslib.__assign({}, opts, { displayName: graphQLDisplayName, skip: shouldSkip, query: document }), function (_a) {
var _b, _c;
_a.client; var data = _a.data, r = tslib.__rest(_a, ["client", "data"]);
if (operationOptions.withRef) {
_this.withRef = true;
props = Object.assign({}, props, {
ref: _this.setWrappedInstance,
});
}
if (shouldSkip) {
return (React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, {})));
}
var result = Object.assign(r, data || {});
var name = operationOptions.name || "data";
var childProps = (_b = {}, _b[name] = result, _b);
if (operationOptions.props) {
var newResult = (_c = {},
_c[name] = result,
_c.ownProps = props,
_c);
lastResultProps = operationOptions.props(newResult, lastResultProps);
childProps = lastResultProps;
}
return (React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, childProps)));
}));
};
GraphQL.displayName = graphQLDisplayName;
GraphQL.WrappedComponent = WrappedComponent;
return GraphQL;
}(GraphQLBase));
return hoistNonReactStatics__default(GraphQL, WrappedComponent, {});
};
}
function withMutation(document, operationOptions) {
if (operationOptions === void 0) { operationOptions = {}; }
var operation = parser.parser(document);
var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.alias, alias = _b === void 0 ? "Apollo" : _b;
var mapPropsToOptions = options;
if (typeof mapPropsToOptions !== "function")
mapPropsToOptions = function () {
return options;
};
return function (WrappedComponent) {
var graphQLDisplayName = "".concat(alias, "(").concat(getDisplayName$1(WrappedComponent), ")");
var GraphQL = (function (_super) {
tslib.__extends(GraphQL, _super);
function GraphQL() {
return _super !== null && _super.apply(this, arguments) || this;
}
GraphQL.prototype.render = function () {
var props = this.props;
var opts = mapPropsToOptions(props);
if (operationOptions.withRef) {
this.withRef = true;
props = Object.assign({}, props, {
ref: this.setWrappedInstance,
});
}
if (!opts.variables && operation.variables.length > 0) {
opts.variables = calculateVariablesFromProps(operation, props);
}
return (React__namespace.createElement(components.Mutation, tslib.__assign({ ignoreResults: true }, opts, { mutation: document }), function (mutate, _a) {
var _b, _c;
var data = _a.data, r = tslib.__rest(_a, ["data"]);
var result = Object.assign(r, data || {});
var name = operationOptions.name || "mutate";
var resultName = operationOptions.name ? "".concat(name, "Result") : "result";
var childProps = (_b = {},
_b[name] = mutate,
_b[resultName] = result,
_b);
if (operationOptions.props) {
var newResult = (_c = {},
_c[name] = mutate,
_c[resultName] = result,
_c.ownProps = props,
_c);
childProps = operationOptions.props(newResult);
}
return React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, childProps));
}));
};
GraphQL.displayName = graphQLDisplayName;
GraphQL.WrappedComponent = WrappedComponent;
return GraphQL;
}(GraphQLBase));
return hoistNonReactStatics__default(GraphQL, WrappedComponent, {});
};
}
function withSubscription(document, operationOptions) {
if (operationOptions === void 0) { operationOptions = {}; }
var operation = parser.parser(document);
var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.skip, skip = _b === void 0 ? defaultMapPropsToSkip : _b, _c = operationOptions.alias, alias = _c === void 0 ? "Apollo" : _c, shouldResubscribe = operationOptions.shouldResubscribe;
var mapPropsToOptions = options;
if (typeof mapPropsToOptions !== "function")
mapPropsToOptions = function () { return options; };
var mapPropsToSkip = skip;
if (typeof mapPropsToSkip !== "function")
mapPropsToSkip = function () { return skip; };
var lastResultProps;
return function (WrappedComponent) {
var graphQLDisplayName = "".concat(alias, "(").concat(getDisplayName$1(WrappedComponent), ")");
var GraphQL = (function (_super) {
tslib.__extends(GraphQL, _super);
function GraphQL(props) {
var _this = _super.call(this, props) || this;
_this.state = { resubscribe: false };
return _this;
}
GraphQL.prototype.updateResubscribe = function (resubscribe) {
this.setState({ resubscribe: resubscribe });
};
GraphQL.prototype.componentDidUpdate = function (prevProps) {
var resubscribe = !!(shouldResubscribe && shouldResubscribe(prevProps, this.props));
if (this.state.resubscribe !== resubscribe) {
this.updateResubscribe(resubscribe);
}
};
GraphQL.prototype.render = function () {
var _this = this;
var props = this.props;
var shouldSkip = mapPropsToSkip(props);
var opts = shouldSkip ? Object.create(null) : mapPropsToOptions(props);
if (!shouldSkip && !opts.variables && operation.variables.length > 0) {
opts.variables = calculateVariablesFromProps(operation, props);
}
return (React__namespace.createElement(components.Subscription, tslib.__assign({}, opts, { displayName: graphQLDisplayName, skip: shouldSkip, subscription: document, shouldResubscribe: this.state.resubscribe }), function (_a) {
var _b, _c;
var data = _a.data, r = tslib.__rest(_a, ["data"]);
if (operationOptions.withRef) {
_this.withRef = true;
props = Object.assign({}, props, {
ref: _this.setWrappedInstance,
});
}
if (shouldSkip) {
return (React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, {})));
}
var result = Object.assign(r, data || {});
var name = operationOptions.name || "data";
var childProps = (_b = {}, _b[name] = result, _b);
if (operationOptions.props) {
var newResult = (_c = {},
_c[name] = result,
_c.ownProps = props,
_c);
lastResultProps = operationOptions.props(newResult, lastResultProps);
childProps = lastResultProps;
}
return (React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, childProps)));
}));
};
GraphQL.displayName = graphQLDisplayName;
GraphQL.WrappedComponent = WrappedComponent;
return GraphQL;
}(GraphQLBase));
return hoistNonReactStatics__default(GraphQL, WrappedComponent, {});
};
}
function graphql(document, operationOptions) {
if (operationOptions === void 0) { operationOptions = {}; }
switch (parser.parser(document).type) {
case parser.DocumentType.Mutation:
return withMutation(document, operationOptions);
case parser.DocumentType.Subscription:
return withSubscription(document, operationOptions);
case parser.DocumentType.Query:
default:
return withQuery(document, operationOptions);
}
}
function getDisplayName(WrappedComponent) {
return WrappedComponent.displayName || WrappedComponent.name || "Component";
}
function withApollo(WrappedComponent, operationOptions) {
if (operationOptions === void 0) { operationOptions = {}; }
var withDisplayName = "withApollo(".concat(getDisplayName(WrappedComponent), ")");
var WithApollo = (function (_super) {
tslib.__extends(WithApollo, _super);
function WithApollo(props) {
var _this = _super.call(this, props) || this;
_this.setWrappedInstance = _this.setWrappedInstance.bind(_this);
return _this;
}
WithApollo.prototype.getWrappedInstance = function () {
globals.invariant(operationOptions.withRef, 48);
return this.wrappedInstance;
};
WithApollo.prototype.setWrappedInstance = function (ref) {
this.wrappedInstance = ref;
};
WithApollo.prototype.render = function () {
var _this = this;
return (React__namespace.createElement(context.ApolloConsumer, null, function (client) {
var props = Object.assign({}, _this.props, {
client: client,
ref: operationOptions.withRef ? _this.setWrappedInstance : undefined,
});
return React__namespace.createElement(WrappedComponent, tslib.__assign({}, props));
}));
};
WithApollo.displayName = withDisplayName;
WithApollo.WrappedComponent = WrappedComponent;
return WithApollo;
}(React__namespace.Component));
return hoistNonReactStatics__default(WithApollo, WrappedComponent, {});
}
exports.graphql = graphql;
exports.withApollo = withApollo;
exports.withMutation = withMutation;
exports.withQuery = withQuery;
exports.withSubscription = withSubscription;
//# sourceMappingURL=hoc.cjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,316 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var globals = require('../../utilities/globals');
var parser = require('../parser');
var tslib = require('tslib');
var React = require('rehackt');
var hoistNonReactStatics = require('hoist-non-react-statics');
var components = require('../components');
var context = require('../context');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
for (var k in e) {
n[k] = e[k];
}
}
n["default"] = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespace(React);
var hoistNonReactStatics__default = /*#__PURE__*/_interopDefaultLegacy(hoistNonReactStatics);
var defaultMapPropsToOptions = function () { return ({}); };
var defaultMapPropsToSkip = function () { return false; };
function getDisplayName$1(WrappedComponent) {
return WrappedComponent.displayName || WrappedComponent.name || "Component";
}
function calculateVariablesFromProps(operation, props) {
var variables = {};
for (var _i = 0, _a = operation.variables; _i < _a.length; _i++) {
var _b = _a[_i], variable = _b.variable, type = _b.type;
if (!variable.name || !variable.name.value)
continue;
var variableName = variable.name.value;
var variableProp = props[variableName];
if (typeof variableProp !== "undefined") {
variables[variableName] = variableProp;
continue;
}
if (type.kind !== "NonNullType") {
variables[variableName] = undefined;
}
}
return variables;
}
var GraphQLBase = (function (_super) {
tslib.__extends(GraphQLBase, _super);
function GraphQLBase(props) {
var _this = _super.call(this, props) || this;
_this.withRef = false;
_this.setWrappedInstance = _this.setWrappedInstance.bind(_this);
return _this;
}
GraphQLBase.prototype.getWrappedInstance = function () {
globals.invariant(this.withRef, 47);
return this.wrappedInstance;
};
GraphQLBase.prototype.setWrappedInstance = function (ref) {
this.wrappedInstance = ref;
};
return GraphQLBase;
}(React__namespace.Component));
function withQuery(document, operationOptions) {
if (operationOptions === void 0) { operationOptions = {}; }
var operation = parser.parser(document);
var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.skip, skip = _b === void 0 ? defaultMapPropsToSkip : _b, _c = operationOptions.alias, alias = _c === void 0 ? "Apollo" : _c;
var mapPropsToOptions = options;
if (typeof mapPropsToOptions !== "function") {
mapPropsToOptions = function () { return options; };
}
var mapPropsToSkip = skip;
if (typeof mapPropsToSkip !== "function") {
mapPropsToSkip = function () { return skip; };
}
var lastResultProps;
return function (WrappedComponent) {
var graphQLDisplayName = "".concat(alias, "(").concat(getDisplayName$1(WrappedComponent), ")");
var GraphQL = (function (_super) {
tslib.__extends(GraphQL, _super);
function GraphQL() {
return _super !== null && _super.apply(this, arguments) || this;
}
GraphQL.prototype.render = function () {
var _this = this;
var props = this.props;
var shouldSkip = mapPropsToSkip(props);
var opts = shouldSkip ? Object.create(null) : tslib.__assign({}, mapPropsToOptions(props));
if (!shouldSkip && !opts.variables && operation.variables.length > 0) {
opts.variables = calculateVariablesFromProps(operation, props);
}
return (React__namespace.createElement(components.Query, tslib.__assign({}, opts, { displayName: graphQLDisplayName, skip: shouldSkip, query: document }), function (_a) {
var _b, _c;
_a.client; var data = _a.data, r = tslib.__rest(_a, ["client", "data"]);
if (operationOptions.withRef) {
_this.withRef = true;
props = Object.assign({}, props, {
ref: _this.setWrappedInstance,
});
}
if (shouldSkip) {
return (React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, {})));
}
var result = Object.assign(r, data || {});
var name = operationOptions.name || "data";
var childProps = (_b = {}, _b[name] = result, _b);
if (operationOptions.props) {
var newResult = (_c = {},
_c[name] = result,
_c.ownProps = props,
_c);
lastResultProps = operationOptions.props(newResult, lastResultProps);
childProps = lastResultProps;
}
return (React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, childProps)));
}));
};
GraphQL.displayName = graphQLDisplayName;
GraphQL.WrappedComponent = WrappedComponent;
return GraphQL;
}(GraphQLBase));
return hoistNonReactStatics__default(GraphQL, WrappedComponent, {});
};
}
function withMutation(document, operationOptions) {
if (operationOptions === void 0) { operationOptions = {}; }
var operation = parser.parser(document);
var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.alias, alias = _b === void 0 ? "Apollo" : _b;
var mapPropsToOptions = options;
if (typeof mapPropsToOptions !== "function")
mapPropsToOptions = function () {
return options;
};
return function (WrappedComponent) {
var graphQLDisplayName = "".concat(alias, "(").concat(getDisplayName$1(WrappedComponent), ")");
var GraphQL = (function (_super) {
tslib.__extends(GraphQL, _super);
function GraphQL() {
return _super !== null && _super.apply(this, arguments) || this;
}
GraphQL.prototype.render = function () {
var props = this.props;
var opts = mapPropsToOptions(props);
if (operationOptions.withRef) {
this.withRef = true;
props = Object.assign({}, props, {
ref: this.setWrappedInstance,
});
}
if (!opts.variables && operation.variables.length > 0) {
opts.variables = calculateVariablesFromProps(operation, props);
}
return (React__namespace.createElement(components.Mutation, tslib.__assign({ ignoreResults: true }, opts, { mutation: document }), function (mutate, _a) {
var _b, _c;
var data = _a.data, r = tslib.__rest(_a, ["data"]);
var result = Object.assign(r, data || {});
var name = operationOptions.name || "mutate";
var resultName = operationOptions.name ? "".concat(name, "Result") : "result";
var childProps = (_b = {},
_b[name] = mutate,
_b[resultName] = result,
_b);
if (operationOptions.props) {
var newResult = (_c = {},
_c[name] = mutate,
_c[resultName] = result,
_c.ownProps = props,
_c);
childProps = operationOptions.props(newResult);
}
return React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, childProps));
}));
};
GraphQL.displayName = graphQLDisplayName;
GraphQL.WrappedComponent = WrappedComponent;
return GraphQL;
}(GraphQLBase));
return hoistNonReactStatics__default(GraphQL, WrappedComponent, {});
};
}
function withSubscription(document, operationOptions) {
if (operationOptions === void 0) { operationOptions = {}; }
var operation = parser.parser(document);
var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.skip, skip = _b === void 0 ? defaultMapPropsToSkip : _b, _c = operationOptions.alias, alias = _c === void 0 ? "Apollo" : _c, shouldResubscribe = operationOptions.shouldResubscribe;
var mapPropsToOptions = options;
if (typeof mapPropsToOptions !== "function")
mapPropsToOptions = function () { return options; };
var mapPropsToSkip = skip;
if (typeof mapPropsToSkip !== "function")
mapPropsToSkip = function () { return skip; };
var lastResultProps;
return function (WrappedComponent) {
var graphQLDisplayName = "".concat(alias, "(").concat(getDisplayName$1(WrappedComponent), ")");
var GraphQL = (function (_super) {
tslib.__extends(GraphQL, _super);
function GraphQL(props) {
var _this = _super.call(this, props) || this;
_this.state = { resubscribe: false };
return _this;
}
GraphQL.prototype.updateResubscribe = function (resubscribe) {
this.setState({ resubscribe: resubscribe });
};
GraphQL.prototype.componentDidUpdate = function (prevProps) {
var resubscribe = !!(shouldResubscribe && shouldResubscribe(prevProps, this.props));
if (this.state.resubscribe !== resubscribe) {
this.updateResubscribe(resubscribe);
}
};
GraphQL.prototype.render = function () {
var _this = this;
var props = this.props;
var shouldSkip = mapPropsToSkip(props);
var opts = shouldSkip ? Object.create(null) : mapPropsToOptions(props);
if (!shouldSkip && !opts.variables && operation.variables.length > 0) {
opts.variables = calculateVariablesFromProps(operation, props);
}
return (React__namespace.createElement(components.Subscription, tslib.__assign({}, opts, { displayName: graphQLDisplayName, skip: shouldSkip, subscription: document, shouldResubscribe: this.state.resubscribe }), function (_a) {
var _b, _c;
var data = _a.data, r = tslib.__rest(_a, ["data"]);
if (operationOptions.withRef) {
_this.withRef = true;
props = Object.assign({}, props, {
ref: _this.setWrappedInstance,
});
}
if (shouldSkip) {
return (React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, {})));
}
var result = Object.assign(r, data || {});
var name = operationOptions.name || "data";
var childProps = (_b = {}, _b[name] = result, _b);
if (operationOptions.props) {
var newResult = (_c = {},
_c[name] = result,
_c.ownProps = props,
_c);
lastResultProps = operationOptions.props(newResult, lastResultProps);
childProps = lastResultProps;
}
return (React__namespace.createElement(WrappedComponent, tslib.__assign({}, props, childProps)));
}));
};
GraphQL.displayName = graphQLDisplayName;
GraphQL.WrappedComponent = WrappedComponent;
return GraphQL;
}(GraphQLBase));
return hoistNonReactStatics__default(GraphQL, WrappedComponent, {});
};
}
function graphql(document, operationOptions) {
if (operationOptions === void 0) { operationOptions = {}; }
switch (parser.parser(document).type) {
case parser.DocumentType.Mutation:
return withMutation(document, operationOptions);
case parser.DocumentType.Subscription:
return withSubscription(document, operationOptions);
case parser.DocumentType.Query:
default:
return withQuery(document, operationOptions);
}
}
function getDisplayName(WrappedComponent) {
return WrappedComponent.displayName || WrappedComponent.name || "Component";
}
function withApollo(WrappedComponent, operationOptions) {
if (operationOptions === void 0) { operationOptions = {}; }
var withDisplayName = "withApollo(".concat(getDisplayName(WrappedComponent), ")");
var WithApollo = (function (_super) {
tslib.__extends(WithApollo, _super);
function WithApollo(props) {
var _this = _super.call(this, props) || this;
_this.setWrappedInstance = _this.setWrappedInstance.bind(_this);
return _this;
}
WithApollo.prototype.getWrappedInstance = function () {
globals.invariant(operationOptions.withRef, 48);
return this.wrappedInstance;
};
WithApollo.prototype.setWrappedInstance = function (ref) {
this.wrappedInstance = ref;
};
WithApollo.prototype.render = function () {
var _this = this;
return (React__namespace.createElement(context.ApolloConsumer, null, function (client) {
var props = Object.assign({}, _this.props, {
client: client,
ref: operationOptions.withRef ? _this.setWrappedInstance : undefined,
});
return React__namespace.createElement(WrappedComponent, tslib.__assign({}, props));
}));
};
WithApollo.displayName = withDisplayName;
WithApollo.WrappedComponent = WrappedComponent;
return WithApollo;
}(React__namespace.Component));
return hoistNonReactStatics__default(WithApollo, WrappedComponent, {});
}
exports.graphql = graphql;
exports.withApollo = withApollo;
exports.withMutation = withMutation;
exports.withQuery = withQuery;
exports.withSubscription = withSubscription;
//# sourceMappingURL=hoc.cjs.map

View File

@@ -0,0 +1,8 @@
import "../../utilities/globals/index.js";
export { graphql } from "./graphql.js";
export { withQuery } from "./query-hoc.js";
export { withMutation } from "./mutation-hoc.js";
export { withSubscription } from "./subscription-hoc.js";
export { withApollo } from "./withApollo.js";
export * from "./types.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,8 @@
import "../../utilities/globals/index.js";
export { graphql } from "./graphql.js";
export { withQuery } from "./query-hoc.js";
export { withMutation } from "./mutation-hoc.js";
export { withSubscription } from "./subscription-hoc.js";
export { withApollo } from "./withApollo.js";
export * from "./types.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/hoc/index.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAE1C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,cAAc,YAAY,CAAC","sourcesContent":["import \"../../utilities/globals/index.js\";\n\nexport { graphql } from \"./graphql.js\";\n\nexport { withQuery } from \"./query-hoc.js\";\nexport { withMutation } from \"./mutation-hoc.js\";\nexport { withSubscription } from \"./subscription-hoc.js\";\nexport { withApollo } from \"./withApollo.js\";\n\nexport * from \"./types.js\";\n"]}

View File

@@ -0,0 +1,12 @@
import type * as ReactTypes from "react";
import type { DocumentNode } from "graphql";
import type { DefaultContext, OperationVariables } from "../../core/types.js";
import type { OperationOption, MutateProps } from "./types.js";
import type { ApolloCache } from "../../core/index.js";
/**
* @deprecated
* Official support for React Apollo higher order components ended in March 2020.
* This library is still included in the `@apollo/client` package, but it no longer receives feature updates or bug fixes.
*/
export declare function withMutation<TProps extends TGraphQLVariables | {} = {}, TData extends Record<string, any> = {}, TGraphQLVariables extends OperationVariables = {}, TChildProps = MutateProps<TData, TGraphQLVariables>, TContext extends Record<string, any> = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>>(document: DocumentNode, operationOptions?: OperationOption<TProps, TData, TGraphQLVariables, TChildProps>): (WrappedComponent: ReactTypes.ComponentType<TProps & TChildProps>) => ReactTypes.ComponentClass<TProps>;
//# sourceMappingURL=mutation-hoc.d.ts.map

View File

@@ -0,0 +1,75 @@
import { __assign, __extends, __rest } from "tslib";
import * as React from "rehackt";
import hoistNonReactStatics from "hoist-non-react-statics";
import { parser } from "../parser/index.js";
import { Mutation } from "../components/index.js";
import { defaultMapPropsToOptions, getDisplayName, calculateVariablesFromProps, GraphQLBase, } from "./hoc-utils.js";
/**
* @deprecated
* Official support for React Apollo higher order components ended in March 2020.
* This library is still included in the `@apollo/client` package, but it no longer receives feature updates or bug fixes.
*/
export function withMutation(document, operationOptions) {
if (operationOptions === void 0) { operationOptions = {}; }
// this is memoized so if coming from `graphql` there is nearly no extra cost
var operation = parser(document);
// extract options
var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.alias, alias = _b === void 0 ? "Apollo" : _b;
var mapPropsToOptions = options;
if (typeof mapPropsToOptions !== "function")
mapPropsToOptions = function () {
return options;
};
return function (WrappedComponent) {
var graphQLDisplayName = "".concat(alias, "(").concat(getDisplayName(WrappedComponent), ")");
var GraphQL = /** @class */ (function (_super) {
__extends(GraphQL, _super);
function GraphQL() {
return _super !== null && _super.apply(this, arguments) || this;
}
GraphQL.prototype.render = function () {
var props = this.props;
var opts = mapPropsToOptions(props);
if (operationOptions.withRef) {
this.withRef = true;
props = Object.assign({}, props, {
ref: this.setWrappedInstance,
});
}
if (!opts.variables && operation.variables.length > 0) {
opts.variables = calculateVariablesFromProps(operation, props);
}
return (React.createElement(Mutation, __assign({ ignoreResults: true }, opts, { mutation: document }), function (mutate, _a) {
var _b, _c;
var data = _a.data, r = __rest(_a, ["data"]);
// the HOC's historically hoisted the data from the execution result
// up onto the result since it was passed as a nested prop
// we massage the Mutation component's shape here to replicate that
// this matches the query HoC
var result = Object.assign(r, data || {});
var name = operationOptions.name || "mutate";
var resultName = operationOptions.name ? "".concat(name, "Result") : "result";
var childProps = (_b = {},
_b[name] = mutate,
_b[resultName] = result,
_b);
if (operationOptions.props) {
var newResult = (_c = {},
_c[name] = mutate,
_c[resultName] = result,
_c.ownProps = props,
_c);
childProps = operationOptions.props(newResult);
}
return React.createElement(WrappedComponent, __assign({}, props, childProps));
}));
};
GraphQL.displayName = graphQLDisplayName;
GraphQL.WrappedComponent = WrappedComponent;
return GraphQL;
}(GraphQLBase));
// Make sure we preserve any custom statics on the original component.
return hoistNonReactStatics(GraphQL, WrappedComponent, {});
};
}
//# sourceMappingURL=mutation-hoc.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,8 @@
{
"name": "@apollo/client/react/hoc",
"type": "module",
"main": "hoc.cjs",
"module": "index.js",
"types": "index.d.ts",
"sideEffects": false
}

View File

@@ -0,0 +1,10 @@
import type * as ReactTypes from "react";
import type { DocumentNode } from "graphql";
import type { OperationOption, DataProps } from "./types.js";
/**
* @deprecated
* Official support for React Apollo higher order components ended in March 2020.
* This library is still included in the `@apollo/client` package, but it no longer receives feature updates or bug fixes.
*/
export declare function withQuery<TProps extends TGraphQLVariables | Record<string, any> = Record<string, any>, TData extends object = {}, TGraphQLVariables extends object = {}, TChildProps extends object = DataProps<TData, TGraphQLVariables>>(document: DocumentNode, operationOptions?: OperationOption<TProps, TData, TGraphQLVariables, TChildProps>): (WrappedComponent: ReactTypes.ComponentType<TProps & TChildProps>) => ReactTypes.ComponentClass<TProps>;
//# sourceMappingURL=query-hoc.d.ts.map

View File

@@ -0,0 +1,81 @@
import { __assign, __extends, __rest } from "tslib";
import * as React from "rehackt";
import hoistNonReactStatics from "hoist-non-react-statics";
import { parser } from "../parser/index.js";
import { Query } from "../components/index.js";
import { getDisplayName, GraphQLBase, calculateVariablesFromProps, defaultMapPropsToOptions, defaultMapPropsToSkip, } from "./hoc-utils.js";
/**
* @deprecated
* Official support for React Apollo higher order components ended in March 2020.
* This library is still included in the `@apollo/client` package, but it no longer receives feature updates or bug fixes.
*/
export function withQuery(document, operationOptions) {
if (operationOptions === void 0) { operationOptions = {}; }
// this is memoized so if coming from `graphql` there is nearly no extra cost
var operation = parser(document);
// extract options
var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.skip, skip = _b === void 0 ? defaultMapPropsToSkip : _b, _c = operationOptions.alias, alias = _c === void 0 ? "Apollo" : _c;
var mapPropsToOptions = options;
if (typeof mapPropsToOptions !== "function") {
mapPropsToOptions = function () { return options; };
}
var mapPropsToSkip = skip;
if (typeof mapPropsToSkip !== "function") {
mapPropsToSkip = function () { return skip; };
}
// allow for advanced referential equality checks
var lastResultProps;
return function (WrappedComponent) {
var graphQLDisplayName = "".concat(alias, "(").concat(getDisplayName(WrappedComponent), ")");
var GraphQL = /** @class */ (function (_super) {
__extends(GraphQL, _super);
function GraphQL() {
return _super !== null && _super.apply(this, arguments) || this;
}
GraphQL.prototype.render = function () {
var _this = this;
var props = this.props;
var shouldSkip = mapPropsToSkip(props);
var opts = shouldSkip ? Object.create(null) : __assign({}, mapPropsToOptions(props));
if (!shouldSkip && !opts.variables && operation.variables.length > 0) {
opts.variables = calculateVariablesFromProps(operation, props);
}
return (React.createElement(Query, __assign({}, opts, { displayName: graphQLDisplayName, skip: shouldSkip, query: document }), function (_a) {
var _b, _c;
var _ = _a.client, data = _a.data, r = __rest(_a, ["client", "data"]);
if (operationOptions.withRef) {
_this.withRef = true;
props = Object.assign({}, props, {
ref: _this.setWrappedInstance,
});
}
// if we have skipped, no reason to manage any reshaping
if (shouldSkip) {
return (React.createElement(WrappedComponent, __assign({}, props, {})));
}
// the HOC's historically hoisted the data from the execution result
// up onto the result since it was passed as a nested prop
// we massage the Query components shape here to replicate that
var result = Object.assign(r, data || {});
var name = operationOptions.name || "data";
var childProps = (_b = {}, _b[name] = result, _b);
if (operationOptions.props) {
var newResult = (_c = {},
_c[name] = result,
_c.ownProps = props,
_c);
lastResultProps = operationOptions.props(newResult, lastResultProps);
childProps = lastResultProps;
}
return (React.createElement(WrappedComponent, __assign({}, props, childProps)));
}));
};
GraphQL.displayName = graphQLDisplayName;
GraphQL.WrappedComponent = WrappedComponent;
return GraphQL;
}(GraphQLBase));
// Make sure we preserve any custom statics on the original component.
return hoistNonReactStatics(GraphQL, WrappedComponent, {});
};
}
//# sourceMappingURL=query-hoc.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,10 @@
import type * as ReactTypes from "react";
import type { DocumentNode } from "graphql";
import type { OperationOption, DataProps } from "./types.js";
/**
* @deprecated
* Official support for React Apollo higher order components ended in March 2020.
* This library is still included in the `@apollo/client` package, but it no longer receives feature updates or bug fixes.
*/
export declare function withSubscription<TProps extends TGraphQLVariables | {} = {}, TData extends object = {}, TGraphQLVariables extends object = {}, TChildProps extends object = DataProps<TData, TGraphQLVariables>>(document: DocumentNode, operationOptions?: OperationOption<TProps, TData, TGraphQLVariables, TChildProps>): (WrappedComponent: ReactTypes.ComponentType<TProps & TChildProps>) => ReactTypes.ComponentClass<TProps>;
//# sourceMappingURL=subscription-hoc.d.ts.map

View File

@@ -0,0 +1,90 @@
import { __assign, __extends, __rest } from "tslib";
import * as React from "rehackt";
import hoistNonReactStatics from "hoist-non-react-statics";
import { parser } from "../parser/index.js";
import { Subscription } from "../components/index.js";
import { getDisplayName, GraphQLBase, calculateVariablesFromProps, defaultMapPropsToOptions, defaultMapPropsToSkip, } from "./hoc-utils.js";
/**
* @deprecated
* Official support for React Apollo higher order components ended in March 2020.
* This library is still included in the `@apollo/client` package, but it no longer receives feature updates or bug fixes.
*/
export function withSubscription(document, operationOptions) {
if (operationOptions === void 0) { operationOptions = {}; }
// this is memoized so if coming from `graphql` there is nearly no extra cost
var operation = parser(document);
// extract options
var _a = operationOptions.options, options = _a === void 0 ? defaultMapPropsToOptions : _a, _b = operationOptions.skip, skip = _b === void 0 ? defaultMapPropsToSkip : _b, _c = operationOptions.alias, alias = _c === void 0 ? "Apollo" : _c, shouldResubscribe = operationOptions.shouldResubscribe;
var mapPropsToOptions = options;
if (typeof mapPropsToOptions !== "function")
mapPropsToOptions = function () { return options; };
var mapPropsToSkip = skip;
if (typeof mapPropsToSkip !== "function")
mapPropsToSkip = function () { return skip; };
// allow for advanced referential equality checks
var lastResultProps;
return function (WrappedComponent) {
var graphQLDisplayName = "".concat(alias, "(").concat(getDisplayName(WrappedComponent), ")");
var GraphQL = /** @class */ (function (_super) {
__extends(GraphQL, _super);
function GraphQL(props) {
var _this = _super.call(this, props) || this;
_this.state = { resubscribe: false };
return _this;
}
GraphQL.prototype.updateResubscribe = function (resubscribe) {
this.setState({ resubscribe: resubscribe });
};
GraphQL.prototype.componentDidUpdate = function (prevProps) {
var resubscribe = !!(shouldResubscribe && shouldResubscribe(prevProps, this.props));
if (this.state.resubscribe !== resubscribe) {
this.updateResubscribe(resubscribe);
}
};
GraphQL.prototype.render = function () {
var _this = this;
var props = this.props;
var shouldSkip = mapPropsToSkip(props);
var opts = shouldSkip ? Object.create(null) : mapPropsToOptions(props);
if (!shouldSkip && !opts.variables && operation.variables.length > 0) {
opts.variables = calculateVariablesFromProps(operation, props);
}
return (React.createElement(Subscription, __assign({}, opts, { displayName: graphQLDisplayName, skip: shouldSkip, subscription: document, shouldResubscribe: this.state.resubscribe }), function (_a) {
var _b, _c;
var data = _a.data, r = __rest(_a, ["data"]);
if (operationOptions.withRef) {
_this.withRef = true;
props = Object.assign({}, props, {
ref: _this.setWrappedInstance,
});
}
// if we have skipped, no reason to manage any reshaping
if (shouldSkip) {
return (React.createElement(WrappedComponent, __assign({}, props, {})));
}
// the HOC's historically hoisted the data from the execution result
// up onto the result since it was passed as a nested prop
// we massage the Query components shape here to replicate that
var result = Object.assign(r, data || {});
var name = operationOptions.name || "data";
var childProps = (_b = {}, _b[name] = result, _b);
if (operationOptions.props) {
var newResult = (_c = {},
_c[name] = result,
_c.ownProps = props,
_c);
lastResultProps = operationOptions.props(newResult, lastResultProps);
childProps = lastResultProps;
}
return (React.createElement(WrappedComponent, __assign({}, props, childProps)));
}));
};
GraphQL.displayName = graphQLDisplayName;
GraphQL.WrappedComponent = WrappedComponent;
return GraphQL;
}(GraphQLBase));
// Make sure we preserve any custom statics on the original component.
return hoistNonReactStatics(GraphQL, WrappedComponent, {});
};
}
//# sourceMappingURL=subscription-hoc.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,43 @@
import type { ApolloCache, ApolloClient } from "../../core/index.js";
import type { ApolloError } from "../../errors/index.js";
import type { ApolloQueryResult, OperationVariables, FetchMoreOptions, UpdateQueryOptions, FetchMoreQueryOptions, SubscribeToMoreOptions, DefaultContext } from "../../core/index.js";
import type { MutationFunction, BaseQueryOptions, BaseMutationOptions, MutationResult } from "../types/types.js";
export interface QueryControls<TData = any, TGraphQLVariables = OperationVariables> {
error?: ApolloError;
networkStatus: number;
loading: boolean;
variables: TGraphQLVariables;
fetchMore: (fetchMoreOptions: FetchMoreQueryOptions<TGraphQLVariables, TData> & FetchMoreOptions<TData, TGraphQLVariables>) => Promise<ApolloQueryResult<TData>>;
refetch: (variables?: TGraphQLVariables) => Promise<ApolloQueryResult<TData>>;
startPolling: (pollInterval: number) => void;
stopPolling: () => void;
subscribeToMore: (options: SubscribeToMoreOptions) => () => void;
updateQuery: (mapFn: (previousQueryResult: any, options: UpdateQueryOptions<any>) => any) => void;
}
export type DataValue<TData, TGraphQLVariables = OperationVariables> = QueryControls<TData, TGraphQLVariables> & Partial<TData>;
export interface DataProps<TData, TGraphQLVariables = OperationVariables> {
data: DataValue<TData, TGraphQLVariables>;
}
export interface MutateProps<TData = any, TGraphQLVariables = OperationVariables> {
mutate: MutationFunction<TData, TGraphQLVariables>;
result: MutationResult<TData>;
}
export type ChildProps<TProps = {}, TData = {}, TGraphQLVariables = OperationVariables> = TProps & Partial<DataProps<TData, TGraphQLVariables>> & Partial<MutateProps<TData, TGraphQLVariables>>;
export type ChildDataProps<TProps = {}, TData = {}, TGraphQLVariables = OperationVariables> = TProps & DataProps<TData, TGraphQLVariables>;
export type ChildMutateProps<TProps = {}, TData = {}, TGraphQLVariables = OperationVariables> = TProps & MutateProps<TData, TGraphQLVariables>;
export interface OptionProps<TProps = any, TData = any, TGraphQLVariables = OperationVariables> extends Partial<DataProps<TData, TGraphQLVariables>>, Partial<MutateProps<TData, TGraphQLVariables>> {
ownProps: TProps;
}
export interface OperationOption<TProps, TData, TGraphQLVariables extends OperationVariables = OperationVariables, TChildProps = ChildProps<TProps, TData, TGraphQLVariables>, TContext = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>> {
options?: BaseQueryOptions<TGraphQLVariables> | BaseMutationOptions<TData, TGraphQLVariables, TContext, TCache> | ((props: TProps) => BaseQueryOptions<TGraphQLVariables> | BaseMutationOptions<TData, TGraphQLVariables, TContext, TCache>);
props?: (props: OptionProps<TProps, TData, TGraphQLVariables>, lastProps?: TChildProps | void) => TChildProps;
skip?: boolean | ((props: TProps) => boolean);
name?: string;
withRef?: boolean;
shouldResubscribe?: (props: TProps, nextProps: TProps) => boolean;
alias?: string;
}
export type WithApolloClient<P> = P & {
client?: ApolloClient<any>;
};
//# sourceMappingURL=types.d.ts.map

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/react/hoc/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ApolloCache, ApolloClient } from \"../../core/index.js\";\nimport type { ApolloError } from \"../../errors/index.js\";\nimport type {\n ApolloQueryResult,\n OperationVariables,\n FetchMoreOptions,\n UpdateQueryOptions,\n FetchMoreQueryOptions,\n SubscribeToMoreOptions,\n DefaultContext,\n} from \"../../core/index.js\";\nimport type {\n MutationFunction,\n BaseQueryOptions,\n BaseMutationOptions,\n MutationResult,\n} from \"../types/types.js\";\n\nexport interface QueryControls<\n TData = any,\n TGraphQLVariables = OperationVariables,\n> {\n error?: ApolloError;\n networkStatus: number;\n loading: boolean;\n variables: TGraphQLVariables;\n fetchMore: (\n fetchMoreOptions: FetchMoreQueryOptions<TGraphQLVariables, TData> &\n FetchMoreOptions<TData, TGraphQLVariables>\n ) => Promise<ApolloQueryResult<TData>>;\n refetch: (variables?: TGraphQLVariables) => Promise<ApolloQueryResult<TData>>;\n startPolling: (pollInterval: number) => void;\n stopPolling: () => void;\n subscribeToMore: (options: SubscribeToMoreOptions) => () => void;\n updateQuery: (\n mapFn: (previousQueryResult: any, options: UpdateQueryOptions<any>) => any\n ) => void;\n}\n\nexport type DataValue<\n TData,\n TGraphQLVariables = OperationVariables,\n> = QueryControls<TData, TGraphQLVariables> &\n // data may not yet be loaded\n Partial<TData>;\n\nexport interface DataProps<TData, TGraphQLVariables = OperationVariables> {\n data: DataValue<TData, TGraphQLVariables>;\n}\n\nexport interface MutateProps<\n TData = any,\n TGraphQLVariables = OperationVariables,\n> {\n mutate: MutationFunction<TData, TGraphQLVariables>;\n result: MutationResult<TData>;\n}\n\nexport type ChildProps<\n TProps = {},\n TData = {},\n TGraphQLVariables = OperationVariables,\n> = TProps &\n Partial<DataProps<TData, TGraphQLVariables>> &\n Partial<MutateProps<TData, TGraphQLVariables>>;\n\nexport type ChildDataProps<\n TProps = {},\n TData = {},\n TGraphQLVariables = OperationVariables,\n> = TProps & DataProps<TData, TGraphQLVariables>;\n\nexport type ChildMutateProps<\n TProps = {},\n TData = {},\n TGraphQLVariables = OperationVariables,\n> = TProps & MutateProps<TData, TGraphQLVariables>;\n\nexport interface OptionProps<\n TProps = any,\n TData = any,\n TGraphQLVariables = OperationVariables,\n> extends Partial<DataProps<TData, TGraphQLVariables>>,\n Partial<MutateProps<TData, TGraphQLVariables>> {\n ownProps: TProps;\n}\n\nexport interface OperationOption<\n TProps,\n TData,\n TGraphQLVariables extends OperationVariables = OperationVariables,\n TChildProps = ChildProps<TProps, TData, TGraphQLVariables>,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> {\n options?:\n | BaseQueryOptions<TGraphQLVariables>\n | BaseMutationOptions<TData, TGraphQLVariables, TContext, TCache>\n | ((\n props: TProps\n ) =>\n | BaseQueryOptions<TGraphQLVariables>\n | BaseMutationOptions<TData, TGraphQLVariables, TContext, TCache>);\n props?: (\n props: OptionProps<TProps, TData, TGraphQLVariables>,\n lastProps?: TChildProps | void\n ) => TChildProps;\n skip?: boolean | ((props: TProps) => boolean);\n name?: string;\n withRef?: boolean;\n shouldResubscribe?: (props: TProps, nextProps: TProps) => boolean;\n alias?: string;\n}\n\nexport type WithApolloClient<P> = P & { client?: ApolloClient<any> };\n"]}

View File

@@ -0,0 +1,9 @@
import type * as ReactTypes from "react";
import type { OperationOption, WithApolloClient } from "./types.js";
/**
* @deprecated
* Official support for React Apollo higher order components ended in March 2020.
* This library is still included in the `@apollo/client` package, but it no longer receives feature updates or bug fixes.
*/
export declare function withApollo<TProps, TResult = any>(WrappedComponent: ReactTypes.ComponentType<WithApolloClient<Omit<TProps, "client">>>, operationOptions?: OperationOption<TProps, TResult>): ReactTypes.ComponentClass<Omit<TProps, "client">>;
//# sourceMappingURL=withApollo.d.ts.map

View File

@@ -0,0 +1,48 @@
import { __assign, __extends } from "tslib";
import { invariant } from "../../utilities/globals/index.js";
import * as React from "rehackt";
import hoistNonReactStatics from "hoist-non-react-statics";
import { ApolloConsumer } from "../context/index.js";
function getDisplayName(WrappedComponent) {
return WrappedComponent.displayName || WrappedComponent.name || "Component";
}
/**
* @deprecated
* Official support for React Apollo higher order components ended in March 2020.
* This library is still included in the `@apollo/client` package, but it no longer receives feature updates or bug fixes.
*/
export function withApollo(WrappedComponent, operationOptions) {
if (operationOptions === void 0) { operationOptions = {}; }
var withDisplayName = "withApollo(".concat(getDisplayName(WrappedComponent), ")");
var WithApollo = /** @class */ (function (_super) {
__extends(WithApollo, _super);
function WithApollo(props) {
var _this = _super.call(this, props) || this;
_this.setWrappedInstance = _this.setWrappedInstance.bind(_this);
return _this;
}
WithApollo.prototype.getWrappedInstance = function () {
invariant(operationOptions.withRef, 48);
return this.wrappedInstance;
};
WithApollo.prototype.setWrappedInstance = function (ref) {
this.wrappedInstance = ref;
};
WithApollo.prototype.render = function () {
var _this = this;
return (React.createElement(ApolloConsumer, null, function (client) {
var props = Object.assign({}, _this.props, {
client: client,
ref: operationOptions.withRef ? _this.setWrappedInstance : undefined,
});
return React.createElement(WrappedComponent, __assign({}, props));
}));
};
WithApollo.displayName = withDisplayName;
WithApollo.WrappedComponent = WrappedComponent;
return WithApollo;
}(React.Component));
// Make sure we preserve any custom statics on the original component.
return hoistNonReactStatics(WithApollo, WrappedComponent, {});
}
//# sourceMappingURL=withApollo.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"withApollo.js","sourceRoot":"","sources":["../../../src/react/hoc/withApollo.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,SAAS,cAAc,CAAI,gBAA6C;IACtE,OAAO,gBAAgB,CAAC,WAAW,IAAI,gBAAgB,CAAC,IAAI,IAAI,WAAW,CAAC;AAC9E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACxB,gBAEC,EACD,gBAAuD;IAAvD,iCAAA,EAAA,qBAAuD;IAEvD,IAAM,eAAe,GAAG,qBAAc,cAAc,CAAC,gBAAgB,CAAC,MAAG,CAAC;IAE1E;QAAyB,8BAAuC;QAO9D,oBAAY,KAA6B;YACvC,YAAA,MAAK,YAAC,KAAK,CAAC,SAAC;YACb,KAAI,CAAC,kBAAkB,GAAG,KAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAI,CAAC,CAAC;;QAC/D,CAAC;QAED,uCAAkB,GAAlB;YACE,SAAS,CACP,gBAAgB,CAAC,OAAO,EACxB,sDAAsD;gBACpD,kCAAkC,CACrC,CAAC;YAEF,OAAO,IAAI,CAAC,eAAe,CAAC;QAC9B,CAAC;QAED,uCAAkB,GAAlB,UACE,GAAuD;YAEvD,IAAI,CAAC,eAAe,GAAG,GAAG,CAAC;QAC7B,CAAC;QAED,2BAAM,GAAN;YAAA,iBAaC;YAZC,OAAO,CACL,oBAAC,cAAc,QACZ,UAAC,MAAM;gBACN,IAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,KAAI,CAAC,KAAK,EAAE;oBAC1C,MAAM,QAAA;oBACN,GAAG,EACD,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,KAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,SAAS;iBACjE,CAAC,CAAC;gBACH,OAAO,oBAAC,gBAAgB,eAAK,KAAK,EAAI,CAAC;YACzC,CAAC,CACc,CAClB,CAAC;QACJ,CAAC;QAxCM,sBAAW,GAAG,eAAe,CAAC;QAC9B,2BAAgB,GAAG,gBAAgB,CAAC;QAwC7C,iBAAC;KAAA,AA1CD,CAAyB,KAAK,CAAC,SAAS,GA0CvC;IAED,sEAAsE;IACtE,OAAO,oBAAoB,CAAC,UAAU,EAAE,gBAAgB,EAAE,EAAE,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import { invariant } from \"../../utilities/globals/index.js\";\nimport * as React from \"rehackt\";\nimport type * as ReactTypes from \"react\";\nimport hoistNonReactStatics from \"hoist-non-react-statics\";\n\nimport { ApolloConsumer } from \"../context/index.js\";\nimport type { OperationOption, WithApolloClient } from \"./types.js\";\n\nfunction getDisplayName<P>(WrappedComponent: ReactTypes.ComponentType<P>) {\n return WrappedComponent.displayName || WrappedComponent.name || \"Component\";\n}\n\n/**\n * @deprecated\n * Official support for React Apollo higher order components ended in March 2020.\n * This library is still included in the `@apollo/client` package, but it no longer receives feature updates or bug fixes.\n */\nexport function withApollo<TProps, TResult = any>(\n WrappedComponent: ReactTypes.ComponentType<\n WithApolloClient<Omit<TProps, \"client\">>\n >,\n operationOptions: OperationOption<TProps, TResult> = {}\n): ReactTypes.ComponentClass<Omit<TProps, \"client\">> {\n const withDisplayName = `withApollo(${getDisplayName(WrappedComponent)})`;\n\n class WithApollo extends React.Component<Omit<TProps, \"client\">> {\n static displayName = withDisplayName;\n static WrappedComponent = WrappedComponent;\n\n // wrapped instance\n private wrappedInstance: any;\n\n constructor(props: Omit<TProps, \"client\">) {\n super(props);\n this.setWrappedInstance = this.setWrappedInstance.bind(this);\n }\n\n getWrappedInstance() {\n invariant(\n operationOptions.withRef,\n `To access the wrapped instance, you need to specify ` +\n `{ withRef: true } in the options`\n );\n\n return this.wrappedInstance;\n }\n\n setWrappedInstance(\n ref: ReactTypes.ComponentType<WithApolloClient<TProps>>\n ) {\n this.wrappedInstance = ref;\n }\n\n render() {\n return (\n <ApolloConsumer>\n {(client) => {\n const props = Object.assign({}, this.props, {\n client,\n ref:\n operationOptions.withRef ? this.setWrappedInstance : undefined,\n });\n return <WrappedComponent {...props} />;\n }}\n </ApolloConsumer>\n );\n }\n }\n\n // Make sure we preserve any custom statics on the original component.\n return hoistNonReactStatics(WithApollo, WrappedComponent, {});\n}\n"]}

View File

@@ -0,0 +1,3 @@
export declare const skipToken: unique symbol;
export type SkipToken = typeof skipToken;
//# sourceMappingURL=constants.d.ts.map

View File

@@ -0,0 +1,2 @@
export var skipToken = Symbol.for("apollo.skipToken");
//# sourceMappingURL=constants.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/react/hooks/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC","sourcesContent":["export const skipToken = Symbol.for(\"apollo.skipToken\");\nexport type SkipToken = typeof skipToken;\n"]}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,21 @@
import "../../utilities/globals/index.js";
export * from "./useApolloClient.js";
export * from "./useLazyQuery.js";
export * from "./useMutation.js";
export { useQuery } from "./useQuery.js";
export * from "./useSubscription.js";
export * from "./useReactiveVar.js";
export * from "./useFragment.js";
export type { UseSuspenseQueryResult } from "./useSuspenseQuery.js";
export { useSuspenseQuery } from "./useSuspenseQuery.js";
export type { UseBackgroundQueryResult } from "./useBackgroundQuery.js";
export { useBackgroundQuery } from "./useBackgroundQuery.js";
export type { LoadQueryFunction, UseLoadableQueryResult, } from "./useLoadableQuery.js";
export { useLoadableQuery } from "./useLoadableQuery.js";
export type { UseQueryRefHandlersResult } from "./useQueryRefHandlers.js";
export { useQueryRefHandlers } from "./useQueryRefHandlers.js";
export type { UseReadQueryResult } from "./useReadQuery.js";
export { useReadQuery } from "./useReadQuery.js";
export { skipToken } from "./constants.js";
export type { SkipToken } from "./constants.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,15 @@
import "../../utilities/globals/index.js";
export * from "./useApolloClient.js";
export * from "./useLazyQuery.js";
export * from "./useMutation.js";
export { useQuery } from "./useQuery.js";
export * from "./useSubscription.js";
export * from "./useReactiveVar.js";
export * from "./useFragment.js";
export { useSuspenseQuery } from "./useSuspenseQuery.js";
export { useBackgroundQuery } from "./useBackgroundQuery.js";
export { useLoadableQuery } from "./useLoadableQuery.js";
export { useQueryRefHandlers } from "./useQueryRefHandlers.js";
export { useReadQuery } from "./useReadQuery.js";
export { skipToken } from "./constants.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAE1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAK7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["import \"../../utilities/globals/index.js\";\n\nexport * from \"./useApolloClient.js\";\nexport * from \"./useLazyQuery.js\";\nexport * from \"./useMutation.js\";\nexport { useQuery } from \"./useQuery.js\";\nexport * from \"./useSubscription.js\";\nexport * from \"./useReactiveVar.js\";\nexport * from \"./useFragment.js\";\nexport type { UseSuspenseQueryResult } from \"./useSuspenseQuery.js\";\nexport { useSuspenseQuery } from \"./useSuspenseQuery.js\";\nexport type { UseBackgroundQueryResult } from \"./useBackgroundQuery.js\";\nexport { useBackgroundQuery } from \"./useBackgroundQuery.js\";\nexport type {\n LoadQueryFunction,\n UseLoadableQueryResult,\n} from \"./useLoadableQuery.js\";\nexport { useLoadableQuery } from \"./useLoadableQuery.js\";\nexport type { UseQueryRefHandlersResult } from \"./useQueryRefHandlers.js\";\nexport { useQueryRefHandlers } from \"./useQueryRefHandlers.js\";\nexport type { UseReadQueryResult } from \"./useReadQuery.js\";\nexport { useReadQuery } from \"./useReadQuery.js\";\nexport { skipToken } from \"./constants.js\";\nexport type { SkipToken } from \"./constants.js\";\n"]}

View File

@@ -0,0 +1,4 @@
type Use = <T>(promise: Promise<T>) => T;
export declare const __use: Use;
export {};
//# sourceMappingURL=__use.d.ts.map

View File

@@ -0,0 +1,22 @@
import { wrapPromiseWithState } from "../../../utilities/index.js";
import * as React from "rehackt";
// Prevent webpack from complaining about our feature detection of the
// use property of the React namespace, which is expected not
// to exist when using current stable versions, and that's fine.
var useKey = "use";
var realHook = React[useKey];
// This is named with two underscores to allow this hook to evade typical rules of
// hooks (i.e. it can be used conditionally)
export var __use = realHook ||
function __use(promise) {
var statefulPromise = wrapPromiseWithState(promise);
switch (statefulPromise.status) {
case "pending":
throw statefulPromise;
case "rejected":
throw statefulPromise.reason;
case "fulfilled":
return statefulPromise.value;
}
};
//# sourceMappingURL=__use.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"__use.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/__use.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAGjC,sEAAsE;AACtE,6DAA6D;AAC7D,gEAAgE;AAChE,IAAM,MAAM,GAAG,KAA2B,CAAC;AAC3C,IAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAoB,CAAC;AAElD,kFAAkF;AAClF,4CAA4C;AAC5C,MAAM,CAAC,IAAM,KAAK,GAChB,QAAQ;IACR,SAAS,KAAK,CAAS,OAAwB;QAC7C,IAAM,eAAe,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAEtD,QAAQ,eAAe,CAAC,MAAM,EAAE,CAAC;YAC/B,KAAK,SAAS;gBACZ,MAAM,eAAe,CAAC;YACxB,KAAK,UAAU;gBACb,MAAM,eAAe,CAAC,MAAM,CAAC;YAC/B,KAAK,WAAW;gBACd,OAAO,eAAe,CAAC,KAAK,CAAC;QACjC,CAAC;IACH,CAAC,CAAC","sourcesContent":["import { wrapPromiseWithState } from \"../../../utilities/index.js\";\nimport * as React from \"rehackt\";\n\ntype Use = <T>(promise: Promise<T>) => T;\n// Prevent webpack from complaining about our feature detection of the\n// use property of the React namespace, which is expected not\n// to exist when using current stable versions, and that's fine.\nconst useKey = \"use\" as keyof typeof React;\nconst realHook = React[useKey] as Use | undefined;\n\n// This is named with two underscores to allow this hook to evade typical rules of\n// hooks (i.e. it can be used conditionally)\nexport const __use =\n realHook ||\n function __use<TValue>(promise: Promise<TValue>) {\n const statefulPromise = wrapPromiseWithState(promise);\n\n switch (statefulPromise.status) {\n case \"pending\":\n throw statefulPromise;\n case \"rejected\":\n throw statefulPromise.reason;\n case \"fulfilled\":\n return statefulPromise.value;\n }\n };\n"]}

View File

@@ -0,0 +1,6 @@
export { useDeepMemo } from "./useDeepMemo.js";
export { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.js";
export { useRenderGuard } from "./useRenderGuard.js";
export { useLazyRef } from "./useLazyRef.js";
export { __use } from "./__use.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,7 @@
// These hooks are used internally and are not exported publicly by the library
export { useDeepMemo } from "./useDeepMemo.js";
export { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.js";
export { useRenderGuard } from "./useRenderGuard.js";
export { useLazyRef } from "./useLazyRef.js";
export { __use } from "./__use.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC","sourcesContent":["// These hooks are used internally and are not exported publicly by the library\nexport { useDeepMemo } from \"./useDeepMemo.js\";\nexport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect.js\";\nexport { useRenderGuard } from \"./useRenderGuard.js\";\nexport { useLazyRef } from \"./useLazyRef.js\";\nexport { __use } from \"./__use.js\";\n"]}

View File

@@ -0,0 +1,3 @@
import type { DependencyList } from "react";
export declare function useDeepMemo<TValue>(memoFn: () => TValue, deps: DependencyList): TValue;
//# sourceMappingURL=useDeepMemo.d.ts.map

View File

@@ -0,0 +1,10 @@
import * as React from "rehackt";
import { equal } from "@wry/equality";
export function useDeepMemo(memoFn, deps) {
var ref = React.useRef();
if (!ref.current || !equal(ref.current.deps, deps)) {
ref.current = { value: memoFn(), deps: deps };
}
return ref.current.value;
}
//# sourceMappingURL=useDeepMemo.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useDeepMemo.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useDeepMemo.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,MAAM,UAAU,WAAW,CACzB,MAAoB,EACpB,IAAoB;IAEpB,IAAM,GAAG,GAAG,KAAK,CAAC,MAAM,EAA2C,CAAC;IAEpE,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QACnD,GAAG,CAAC,OAAO,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,MAAA,EAAE,CAAC;IAC1C,CAAC;IAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC;AAC3B,CAAC","sourcesContent":["import type { DependencyList } from \"react\";\nimport * as React from \"rehackt\";\nimport { equal } from \"@wry/equality\";\n\nexport function useDeepMemo<TValue>(\n memoFn: () => TValue,\n deps: DependencyList\n) {\n const ref = React.useRef<{ deps: DependencyList; value: TValue }>();\n\n if (!ref.current || !equal(ref.current.deps, deps)) {\n ref.current = { value: memoFn(), deps };\n }\n\n return ref.current.value;\n}\n"]}

View File

@@ -0,0 +1,4 @@
/// <reference types="react" />
import * as React from "rehackt";
export declare const useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
//# sourceMappingURL=useIsomorphicLayoutEffect.d.ts.map

View File

@@ -0,0 +1,9 @@
import * as React from "rehackt";
import { canUseDOM } from "../../../utilities/index.js";
// use canUseDOM here instead of canUseLayoutEffect because we want to be able
// to use useLayoutEffect in our jest tests. useLayoutEffect seems to work fine
// in useSuspenseQuery tests, but to honor the original comment about the
// warnings for useSyncExternalStore implementation, canUseLayoutEffect is left
// alone.
export var useIsomorphicLayoutEffect = canUseDOM ? React.useLayoutEffect : React.useEffect;
//# sourceMappingURL=useIsomorphicLayoutEffect.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useIsomorphicLayoutEffect.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExD,8EAA8E;AAC9E,+EAA+E;AAC/E,yEAAyE;AACzE,+EAA+E;AAC/E,SAAS;AACT,MAAM,CAAC,IAAM,yBAAyB,GACpC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport { canUseDOM } from \"../../../utilities/index.js\";\n\n// use canUseDOM here instead of canUseLayoutEffect because we want to be able\n// to use useLayoutEffect in our jest tests. useLayoutEffect seems to work fine\n// in useSuspenseQuery tests, but to honor the original comment about the\n// warnings for useSyncExternalStore implementation, canUseLayoutEffect is left\n// alone.\nexport const useIsomorphicLayoutEffect =\n canUseDOM ? React.useLayoutEffect : React.useEffect;\n"]}

View File

@@ -0,0 +1,4 @@
/// <reference types="react" />
import * as React from "rehackt";
export declare function useLazyRef<T>(getInitialValue: () => T): React.MutableRefObject<T>;
//# sourceMappingURL=useLazyRef.d.ts.map

View File

@@ -0,0 +1,10 @@
import * as React from "rehackt";
var INIT = {};
export function useLazyRef(getInitialValue) {
var ref = React.useRef(INIT);
if (ref.current === INIT) {
ref.current = getInitialValue();
}
return ref;
}
//# sourceMappingURL=useLazyRef.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useLazyRef.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useLazyRef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,IAAM,IAAI,GAAG,EAAE,CAAC;AAEhB,MAAM,UAAU,UAAU,CAAI,eAAwB;IACpD,IAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAI,IAAoB,CAAC,CAAC;IAElD,IAAI,GAAG,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;QACzB,GAAG,CAAC,OAAO,GAAG,eAAe,EAAE,CAAC;IAClC,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import * as React from \"rehackt\";\n\nconst INIT = {};\n\nexport function useLazyRef<T>(getInitialValue: () => T) {\n const ref = React.useRef<T>(INIT as unknown as T);\n\n if (ref.current === INIT) {\n ref.current = getInitialValue();\n }\n\n return ref;\n}\n"]}

View File

@@ -0,0 +1,2 @@
export declare function useRenderGuard(): () => boolean;
//# sourceMappingURL=useRenderGuard.d.ts.map

View File

@@ -0,0 +1,17 @@
import * as React from "rehackt";
function getRenderDispatcher() {
var _a, _b;
return (_b = (_a = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) === null || _a === void 0 ? void 0 : _a.ReactCurrentDispatcher) === null || _b === void 0 ? void 0 : _b.current;
}
var RenderDispatcher = null;
/*
Relay does this too, so we hope this is safe.
https://github.com/facebook/relay/blob/8651fbca19adbfbb79af7a3bc40834d105fd7747/packages/react-relay/relay-hooks/loadQuery.js#L90-L98
*/
export function useRenderGuard() {
RenderDispatcher = getRenderDispatcher();
return React.useCallback(function () {
return (RenderDispatcher !== null && RenderDispatcher === getRenderDispatcher());
}, []);
}
//# sourceMappingURL=useRenderGuard.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useRenderGuard.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useRenderGuard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,SAAS,mBAAmB;;IAC1B,OAAO,MAAA,MAAC,KAAa,CAAC,kDAAkD,0CACpE,sBAAsB,0CAAE,OAAO,CAAC;AACtC,CAAC;AAED,IAAI,gBAAgB,GAAY,IAAI,CAAC;AAErC;;;EAGE;AACF,MAAM,UAAU,cAAc;IAC5B,gBAAgB,GAAG,mBAAmB,EAAE,CAAC;IAEzC,OAAO,KAAK,CAAC,WAAW,CAAC;QACvB,OAAO,CACL,gBAAgB,KAAK,IAAI,IAAI,gBAAgB,KAAK,mBAAmB,EAAE,CACxE,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC","sourcesContent":["import * as React from \"rehackt\";\n\nfunction getRenderDispatcher() {\n return (React as any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED\n ?.ReactCurrentDispatcher?.current;\n}\n\nlet RenderDispatcher: unknown = null;\n\n/*\nRelay does this too, so we hope this is safe.\nhttps://github.com/facebook/relay/blob/8651fbca19adbfbb79af7a3bc40834d105fd7747/packages/react-relay/relay-hooks/loadQuery.js#L90-L98\n*/\nexport function useRenderGuard() {\n RenderDispatcher = getRenderDispatcher();\n\n return React.useCallback(() => {\n return (\n RenderDispatcher !== null && RenderDispatcher === getRenderDispatcher()\n );\n }, []);\n}\n"]}

View File

@@ -0,0 +1,8 @@
{
"name": "@apollo/client/react/hooks",
"type": "module",
"main": "hooks.cjs",
"module": "index.js",
"types": "index.d.ts",
"sideEffects": false
}

View File

@@ -0,0 +1,18 @@
import type { ApolloClient } from "../../core/index.js";
/**
* @example
* ```jsx
* import { useApolloClient } from '@apollo/client';
*
* function SomeComponent() {
* const client = useApolloClient();
* // `client` is now set to the `ApolloClient` instance being used by the
* // application (that was configured using something like `ApolloProvider`)
* }
* ```
*
* @since 3.0.0
* @returns The `ApolloClient` instance being used by the application.
*/
export declare function useApolloClient(override?: ApolloClient<object>): ApolloClient<object>;
//# sourceMappingURL=useApolloClient.d.ts.map

View File

@@ -0,0 +1,25 @@
import { invariant } from "../../utilities/globals/index.js";
import * as React from "rehackt";
import { getApolloContext } from "../context/index.js";
/**
* @example
* ```jsx
* import { useApolloClient } from '@apollo/client';
*
* function SomeComponent() {
* const client = useApolloClient();
* // `client` is now set to the `ApolloClient` instance being used by the
* // application (that was configured using something like `ApolloProvider`)
* }
* ```
*
* @since 3.0.0
* @returns The `ApolloClient` instance being used by the application.
*/
export function useApolloClient(override) {
var context = React.useContext(getApolloContext());
var client = override || context.client;
invariant(!!client, 49);
return client;
}
//# sourceMappingURL=useApolloClient.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useApolloClient.js","sourceRoot":"","sources":["../../../src/react/hooks/useApolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,eAAe,CAC7B,QAA+B;IAE/B,IAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,gBAAgB,EAAE,CAAC,CAAC;IACrD,IAAM,MAAM,GAAG,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;IAC1C,SAAS,CACP,CAAC,CAAC,MAAM,EACR,oEAAoE;QAClE,0EAA0E;QAC1E,0BAA0B,CAC7B,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { invariant } from \"../../utilities/globals/index.js\";\nimport * as React from \"rehackt\";\nimport type { ApolloClient } from \"../../core/index.js\";\nimport { getApolloContext } from \"../context/index.js\";\n\n/**\n * @example\n * ```jsx\n * import { useApolloClient } from '@apollo/client';\n *\n * function SomeComponent() {\n * const client = useApolloClient();\n * // `client` is now set to the `ApolloClient` instance being used by the\n * // application (that was configured using something like `ApolloProvider`)\n * }\n * ```\n *\n * @since 3.0.0\n * @returns The `ApolloClient` instance being used by the application.\n */\nexport function useApolloClient(\n override?: ApolloClient<object>\n): ApolloClient<object> {\n const context = React.useContext(getApolloContext());\n const client = override || context.client;\n invariant(\n !!client,\n 'Could not find \"client\" in the context or passed in as an option. ' +\n \"Wrap the root component in an <ApolloProvider>, or pass an ApolloClient \" +\n \"instance in via options.\"\n );\n\n return client;\n}\n"]}

View File

@@ -0,0 +1,64 @@
import type { DocumentNode, OperationVariables, TypedDocumentNode } from "../../core/index.js";
import type { QueryReference } from "../internal/index.js";
import type { BackgroundQueryHookOptions, NoInfer } from "../types/types.js";
import type { FetchMoreFunction, RefetchFunction } from "./useSuspenseQuery.js";
import type { DeepPartial } from "../../utilities/index.js";
import type { SkipToken } from "./constants.js";
export type UseBackgroundQueryResult<TData = unknown, TVariables extends OperationVariables = OperationVariables> = {
fetchMore: FetchMoreFunction<TData, TVariables>;
refetch: RefetchFunction<TData, TVariables>;
};
type BackgroundQueryHookOptionsNoInfer<TData, TVariables extends OperationVariables> = BackgroundQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>;
export declare function useBackgroundQuery<TData, TVariables extends OperationVariables, TOptions extends Omit<BackgroundQueryHookOptions<TData>, "variables">>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & TOptions): [
(QueryReference<TOptions["errorPolicy"] extends "ignore" | "all" ? TOptions["returnPartialData"] extends true ? DeepPartial<TData> | undefined : TData | undefined : TOptions["returnPartialData"] extends true ? DeepPartial<TData> : TData, TVariables> | (TOptions["skip"] extends boolean ? undefined : never)),
UseBackgroundQueryResult<TData, TVariables>
];
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
returnPartialData: true;
errorPolicy: "ignore" | "all";
}): [
QueryReference<DeepPartial<TData> | undefined, TVariables>,
UseBackgroundQueryResult<TData, TVariables>
];
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
errorPolicy: "ignore" | "all";
}): [
QueryReference<TData | undefined, TVariables>,
UseBackgroundQueryResult<TData, TVariables>
];
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
skip: boolean;
returnPartialData: true;
}): [
QueryReference<DeepPartial<TData>, TVariables> | undefined,
UseBackgroundQueryResult<TData, TVariables>
];
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
returnPartialData: true;
}): [
QueryReference<DeepPartial<TData>, TVariables>,
UseBackgroundQueryResult<TData, TVariables>
];
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
skip: boolean;
}): [
QueryReference<TData, TVariables> | undefined,
UseBackgroundQueryResult<TData, TVariables>
];
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables>): [
QueryReference<TData, TVariables>,
UseBackgroundQueryResult<TData, TVariables>
];
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken): [undefined, UseBackgroundQueryResult<TData, TVariables>];
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken | (BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
returnPartialData: true;
})): [
QueryReference<DeepPartial<TData>, TVariables> | undefined,
UseBackgroundQueryResult<TData, TVariables>
];
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: SkipToken | BackgroundQueryHookOptionsNoInfer<TData, TVariables>): [
QueryReference<TData, TVariables> | undefined,
UseBackgroundQueryResult<TData, TVariables>
];
export {};
//# sourceMappingURL=useBackgroundQuery.d.ts.map

View File

@@ -0,0 +1,52 @@
import { __spreadArray } from "tslib";
import * as React from "rehackt";
import { useApolloClient } from "./useApolloClient.js";
import { getSuspenseCache, unwrapQueryRef, updateWrappedQueryRef, wrapQueryRef, } from "../internal/index.js";
import { useWatchQueryOptions } from "./useSuspenseQuery.js";
import { canonicalStringify } from "../../cache/index.js";
export function useBackgroundQuery(query, options) {
if (options === void 0) { options = Object.create(null); }
var client = useApolloClient(options.client);
var suspenseCache = getSuspenseCache(client);
var watchQueryOptions = useWatchQueryOptions({ client: client, query: query, options: options });
var fetchPolicy = watchQueryOptions.fetchPolicy, variables = watchQueryOptions.variables;
var _a = options.queryKey, queryKey = _a === void 0 ? [] : _a;
// This ref tracks the first time query execution is enabled to determine
// whether to return a query ref or `undefined`. When initialized
// in a skipped state (either via `skip: true` or `skipToken`) we return
// `undefined` for the `queryRef` until the query has been enabled. Once
// enabled, a query ref is always returned regardless of whether the query is
// skipped again later.
var didFetchResult = React.useRef(fetchPolicy !== "standby");
didFetchResult.current || (didFetchResult.current = fetchPolicy !== "standby");
var cacheKey = __spreadArray([
query,
canonicalStringify(variables)
], [].concat(queryKey), true);
var queryRef = suspenseCache.getQueryRef(cacheKey, function () {
return client.watchQuery(watchQueryOptions);
});
var _b = React.useState(wrapQueryRef(queryRef)), wrappedQueryRef = _b[0], setWrappedQueryRef = _b[1];
if (unwrapQueryRef(wrappedQueryRef) !== queryRef) {
setWrappedQueryRef(wrapQueryRef(queryRef));
}
if (queryRef.didChangeOptions(watchQueryOptions)) {
var promise = queryRef.applyOptions(watchQueryOptions);
updateWrappedQueryRef(wrappedQueryRef, promise);
}
var fetchMore = React.useCallback(function (options) {
var promise = queryRef.fetchMore(options);
setWrappedQueryRef(wrapQueryRef(queryRef));
return promise;
}, [queryRef]);
var refetch = React.useCallback(function (variables) {
var promise = queryRef.refetch(variables);
setWrappedQueryRef(wrapQueryRef(queryRef));
return promise;
}, [queryRef]);
return [
didFetchResult.current ? wrappedQueryRef : void 0,
{ fetchMore: fetchMore, refetch: refetch },
];
}
//# sourceMappingURL=useBackgroundQuery.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,28 @@
import type { DeepPartial } from "../../utilities/index.js";
import type { Cache, Reference, StoreObject, MissingTree } from "../../cache/index.js";
import type { ApolloClient, OperationVariables } from "../../core/index.js";
import type { NoInfer } from "../types/types.js";
export interface UseFragmentOptions<TData, TVars> extends Omit<Cache.DiffOptions<NoInfer<TData>, NoInfer<TVars>>, "id" | "query" | "optimistic" | "previousResult" | "returnPartialData">, Omit<Cache.ReadFragmentOptions<TData, TVars>, "id" | "variables" | "returnPartialData"> {
from: StoreObject | Reference | string;
optimistic?: boolean;
/**
* The instance of {@link ApolloClient} to use to look up the fragment.
*
* By default, the instance that's passed down via context is used, but you
* can provide a different instance here.
*
* @docGroup 1. Operation options
*/
client?: ApolloClient<any>;
}
export type UseFragmentResult<TData> = {
data: TData;
complete: true;
missing?: never;
} | {
data: DeepPartial<TData>;
complete: false;
missing?: MissingTree;
};
export declare function useFragment<TData = any, TVars = OperationVariables>(options: UseFragmentOptions<TData, TVars>): UseFragmentResult<TData>;
//# sourceMappingURL=useFragment.d.ts.map

View File

@@ -0,0 +1,48 @@
import { __assign, __rest } from "tslib";
import * as React from "rehackt";
import { equal } from "@wry/equality";
import { mergeDeepArray } from "../../utilities/index.js";
import { useApolloClient } from "./useApolloClient.js";
import { useSyncExternalStore } from "./useSyncExternalStore.js";
import { useDeepMemo, useLazyRef } from "./internal/index.js";
export function useFragment(options) {
var cache = useApolloClient(options.client).cache;
var diffOptions = useDeepMemo(function () {
var fragment = options.fragment, fragmentName = options.fragmentName, from = options.from, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, rest = __rest(options, ["fragment", "fragmentName", "from", "optimistic"]);
return __assign(__assign({}, rest), { returnPartialData: true, id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
}, [options]);
var resultRef = useLazyRef(function () {
return diffToResult(cache.diff(diffOptions));
});
// Used for both getSnapshot and getServerSnapshot
var getSnapshot = React.useCallback(function () { return resultRef.current; }, []);
return useSyncExternalStore(React.useCallback(function (forceUpdate) {
var lastTimeout = 0;
var unsubscribe = cache.watch(__assign(__assign({}, diffOptions), { immediate: true, callback: function (diff) {
if (!equal(diff.result, resultRef.current.data)) {
resultRef.current = diffToResult(diff);
// If we get another update before we've re-rendered, bail out of
// the update and try again. This ensures that the relative timing
// between useQuery and useFragment stays roughly the same as
// fixed in https://github.com/apollographql/apollo-client/pull/11083
clearTimeout(lastTimeout);
lastTimeout = setTimeout(forceUpdate);
}
} }));
return function () {
unsubscribe();
clearTimeout(lastTimeout);
};
}, [cache, diffOptions]), getSnapshot, getSnapshot);
}
function diffToResult(diff) {
var result = {
data: diff.result,
complete: !!diff.complete,
};
if (diff.missing) {
result.missing = mergeDeepArray(diff.missing.map(function (error) { return error.missing; }));
}
return result;
}
//# sourceMappingURL=useFragment.js.map

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show More