Socket
Socket
Sign inDemoInstall

@apollo/client

Package Overview
Dependencies
19
Maintainers
4
Versions
552
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.0-pr-11594-20240213203418 to 0.0.0-pr-11605-20240321163144

dev/setErrorMessageHandler.d.ts

84

cache/core/cache.d.ts
import type { DocumentNode } from "graphql";
import type { StoreObject, Reference } from "../../utilities/index.js";
import type { StoreObject, Reference, DeepPartial } from "../../utilities/index.js";
import { Observable } from "../../utilities/index.js";
import type { DataProxy } from "./types/DataProxy.js";
import type { Cache } from "./types/Cache.js";
import { getApolloCacheMemoryInternals } from "../../utilities/caching/getMemoryInternals.js";
import type { OperationVariables, TypedDocumentNode } from "../../core/types.js";
import type { MissingTree } from "./types/common.js";
export type Transaction<T> = (c: ApolloCache<T>) => void;
/**
* Watched fragment options.
*/
export interface WatchFragmentOptions<TData, TVars> {
/**
* A GraphQL fragment document parsed into an AST with the `gql`
* template literal.
*
* @docGroup 1. Required options
*/
fragment: DocumentNode | TypedDocumentNode<TData, TVars>;
/**
* An object containing a `__typename` and primary key fields
* (such as `id`) identifying the entity object from which the fragment will
* be retrieved, or a `{ __ref: "..." }` reference, or a `string` ID
* (uncommon).
*
* @docGroup 1. Required options
*/
from: StoreObject | Reference | string;
/**
* Any variables that the GraphQL fragment may depend on.
*
* @docGroup 2. Cache options
*/
variables?: TVars;
/**
* The name of the fragment defined in the fragment document.
*
* Required if the fragment document includes more than one fragment,
* optional otherwise.
*
* @docGroup 2. Cache options
*/
fragmentName?: string;
/**
* If `true`, `watchFragment` returns optimistic results.
*
* The default value is `true`.
*
* @docGroup 2. Cache options
*/
optimistic?: boolean;
/**
* @deprecated
* Using `canonizeResults` can result in memory leaks so we generally do not
* recommend using this option anymore.
* A future version of Apollo Client will contain a similar feature.
*
* Whether to canonize cache results before returning them. Canonization
* takes some extra time, but it speeds up future deep equality comparisons.
* Defaults to false.
*/
canonizeResults?: boolean;
}
/**
* Watched fragment results.
*/
export type WatchFragmentResult<TData> = {
data: TData;
complete: true;
missing?: never;
} | {
data: DeepPartial<TData>;
complete: false;
missing: MissingTree;
};
export declare abstract class ApolloCache<TSerialized> implements DataProxy {

@@ -37,2 +107,14 @@ readonly assumeImmutableResults: boolean;

readQuery<QueryType, TVariables = any>(options: Cache.ReadQueryOptions<QueryType, TVariables>, optimistic?: boolean): QueryType | null;
/**
* Watches the cache store of the fragment according to the options specified and returns an `Observable`. We can subscribe to this `Observable` and receive updated results through an observer when the cache store changes.
*
* You must pass in a GraphQL document with a single fragment or a document with multiple fragments that represent what you are reading. If you pass in a document with multiple fragments then you must also specify a `fragmentName`.
*
* @param options - An object of type `WatchFragmentOptions` that allows the cache to identify the fragment and optionally specify whether to react to optimistic updates.
*
* @since
*
* 3.10.0
*/
watchFragment<TData = any, TVars = OperationVariables>(options: WatchFragmentOptions<TData, TVars>): Observable<WatchFragmentResult<TData>>;
private getFragmentDoc;

@@ -39,0 +121,0 @@ readFragment<FragmentType, TVariables = any>(options: Cache.ReadFragmentOptions<FragmentType, TVariables>, optimistic?: boolean): FragmentType | null;

import { __assign, __rest } from "tslib";
import { wrap } from "optimism";
import { cacheSizes, getFragmentQueryDocument, } from "../../utilities/index.js";
import { Observable, cacheSizes, getFragmentQueryDocument, mergeDeepArray, } from "../../utilities/index.js";
import { WeakCache } from "@wry/caches";
import { getApolloCacheMemoryInternals } from "../../utilities/caching/getMemoryInternals.js";
import { equal } from "@wry/equality";
var ApolloCache = /** @class */ (function () {

@@ -60,2 +61,30 @@ function ApolloCache() {

};
/** {@inheritDoc @apollo/client!ApolloClient#watchFragment:member(1)} */
ApolloCache.prototype.watchFragment = function (options) {
var _this = this;
var fragment = options.fragment, fragmentName = options.fragmentName, from = options.from, _a = options.optimistic, optimistic = _a === void 0 ? true : _a;
var diffOptions = {
returnPartialData: true,
id: typeof from === "string" ? from : this.identify(from),
query: this.getFragmentDoc(fragment, fragmentName),
optimistic: optimistic,
};
var latestDiff;
return new Observable(function (observer) {
return _this.watch(__assign(__assign({}, diffOptions), { immediate: true, query: _this.getFragmentDoc(fragment, fragmentName), callback: function (diff) {
if (equal(diff, latestDiff)) {
return;
}
var result = {
data: diff.result,
complete: !!diff.complete,
};
if (diff.missing) {
result.missing = mergeDeepArray(diff.missing.map(function (error) { return error.missing; }));
}
latestDiff = diff;
observer.next(result);
} }));
});
};
ApolloCache.prototype.readFragment = function (options, optimistic) {

@@ -62,0 +91,0 @@ if (optimistic === void 0) { optimistic = !!options.optimistic; }

34

core/ApolloClient.d.ts

@@ -31,3 +31,3 @@ import type { ExecutionResult, DocumentNode } from "graphql";

/**
* You can provide an {@link ApolloLink} instance to serve as Apollo Client's network layer. For more information, see [Advanced HTTP networking](https://www.apollographql.com/docs/react/networking/advanced-http-networking/).
* You can provide an `ApolloLink` instance to serve as Apollo Client's network layer. For more information, see [Advanced HTTP networking](https://www.apollographql.com/docs/react/networking/advanced-http-networking/).
*

@@ -97,8 +97,9 @@ * One of `uri` or `link` is **required**. If you provide both, `link` takes precedence.

import { getApolloClientMemoryInternals } from "../utilities/caching/getMemoryInternals.js";
import type { WatchFragmentOptions, WatchFragmentResult } from "../cache/core/cache.js";
export { mergeOptions };
/**
* This is the primary Apollo Client class. It is used to send GraphQL documents (i.e. queries
* and mutations) to a GraphQL spec-compliant server over an {@link ApolloLink} instance,
* and mutations) to a GraphQL spec-compliant server over an `ApolloLink` instance,
* receive results from the server and cache the results in a store. It also delivers updates
* to GraphQL queries through {@link Observable} instances.
* to GraphQL queries through `Observable` instances.
*/

@@ -119,3 +120,3 @@ export declare class ApolloClient<TCacheShape> implements DataProxy {

/**
* Constructs an instance of {@link ApolloClient}.
* Constructs an instance of `ApolloClient`.
*

@@ -160,4 +161,4 @@ * @example

* This watches the cache store of the query according to the options specified and
* returns an {@link ObservableQuery}. We can subscribe to this {@link ObservableQuery} and
* receive updated results through a GraphQL observer when the cache store changes.
* returns an `ObservableQuery`. We can subscribe to this `ObservableQuery` and
* receive updated results through an observer when the cache store changes.
*

@@ -184,3 +185,3 @@ * Note that this method is not an implementation of GraphQL subscriptions. Rather,

*
* @param options - An object of type {@link QueryOptions} that allows us to
* @param options - An object of type `QueryOptions` that allows us to
* describe how this query should be treated e.g. whether it should hit the

@@ -201,3 +202,3 @@ * server at all or just resolve from the cache, etc.

* This subscribes to a graphql subscription according to the options specified and returns an
* {@link Observable} which either emits received data or an error.
* `Observable` which either emits received data or an error.
*/

@@ -216,2 +217,19 @@ subscribe<T = any, TVariables extends OperationVariables = OperationVariables>(options: SubscriptionOptions<TVariables, T>): Observable<FetchResult<T>>;

/**
* Watches the cache store of the fragment according to the options specified
* and returns an `Observable`. We can subscribe to this
* `Observable` and receive updated results through an
* observer when the cache store changes.
*
* You must pass in a GraphQL document with a single fragment or a document
* with multiple fragments that represent what you are reading. If you pass
* in a document with multiple fragments then you must also specify a
* `fragmentName`.
*
* @since 3.10.0
* @param options - An object of type `WatchFragmentOptions` that allows
* the cache to identify the fragment and optionally specify whether to react
* to optimistic updates.
*/
watchFragment<TFragmentData = unknown, TVariables = OperationVariables>(options: WatchFragmentOptions<TFragmentData, TVariables>): Observable<WatchFragmentResult<TFragmentData>>;
/**
* Tries to read some data from the store in the shape of the provided

@@ -218,0 +236,0 @@ * GraphQL fragment without making a network request. This method will read a

@@ -18,9 +18,9 @@ import { __assign } from "tslib";

* This is the primary Apollo Client class. It is used to send GraphQL documents (i.e. queries
* and mutations) to a GraphQL spec-compliant server over an {@link ApolloLink} instance,
* and mutations) to a GraphQL spec-compliant server over an `ApolloLink` instance,
* receive results from the server and cache the results in a store. It also delivers updates
* to GraphQL queries through {@link Observable} instances.
* to GraphQL queries through `Observable` instances.
*/
var ApolloClient = /** @class */ (function () {
/**
* Constructs an instance of {@link ApolloClient}.
* Constructs an instance of `ApolloClient`.
*

@@ -187,4 +187,4 @@ * @example

* This watches the cache store of the query according to the options specified and
* returns an {@link ObservableQuery}. We can subscribe to this {@link ObservableQuery} and
* receive updated results through a GraphQL observer when the cache store changes.
* returns an `ObservableQuery`. We can subscribe to this `ObservableQuery` and
* receive updated results through an observer when the cache store changes.
*

@@ -222,3 +222,3 @@ * Note that this method is not an implementation of GraphQL subscriptions. Rather,

*
* @param options - An object of type {@link QueryOptions} that allows us to
* @param options - An object of type `QueryOptions` that allows us to
* describe how this query should be treated e.g. whether it should hit the

@@ -253,3 +253,3 @@ * server at all or just resolve from the cache, etc.

* This subscribes to a graphql subscription according to the options specified and returns an
* {@link Observable} which either emits received data or an error.
* `Observable` which either emits received data or an error.
*/

@@ -273,2 +273,21 @@ ApolloClient.prototype.subscribe = function (options) {

/**
* Watches the cache store of the fragment according to the options specified
* and returns an `Observable`. We can subscribe to this
* `Observable` and receive updated results through an
* observer when the cache store changes.
*
* You must pass in a GraphQL document with a single fragment or a document
* with multiple fragments that represent what you are reading. If you pass
* in a document with multiple fragments then you must also specify a
* `fragmentName`.
*
* @since 3.10.0
* @param options - An object of type `WatchFragmentOptions` that allows
* the cache to identify the fragment and optionally specify whether to react
* to optimistic updates.
*/
ApolloClient.prototype.watchFragment = function (options) {
return this.cache.watchFragment(options);
};
/**
* Tries to read some data from the store in the shape of the provided

@@ -275,0 +294,0 @@ * GraphQL fragment without making a network request. This method will read a

@@ -45,5 +45,5 @@ import { __assign, __awaiter, __generator } from "tslib";

LocalState.prototype.runResolvers = function (_a) {
var document = _a.document, remoteResult = _a.remoteResult, context = _a.context, variables = _a.variables, _b = _a.onlyRunForcedResolvers, onlyRunForcedResolvers = _b === void 0 ? false : _b;
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_c) {
return __awaiter(this, arguments, void 0, function (_b) {
var document = _b.document, remoteResult = _b.remoteResult, context = _b.context, variables = _b.variables, _c = _b.onlyRunForcedResolvers, onlyRunForcedResolvers = _c === void 0 ? false : _c;
return __generator(this, function (_d) {
if (document) {

@@ -87,6 +87,6 @@ return [2 /*return*/, this.resolveDocument(document, remoteResult.data, context, variables, this.fragmentMatcher, onlyRunForcedResolvers).then(function (localResult) { return (__assign(__assign({}, remoteResult), { data: localResult.result })); })];

// used alongside the original operation variables.
LocalState.prototype.addExportedVariables = function (document, variables, context) {
if (variables === void 0) { variables = {}; }
if (context === void 0) { context = {}; }
return __awaiter(this, void 0, void 0, function () {
LocalState.prototype.addExportedVariables = function (document_1) {
return __awaiter(this, arguments, void 0, function (document, variables, context) {
if (variables === void 0) { variables = {}; }
if (context === void 0) { context = {}; }
return __generator(this, function (_a) {

@@ -129,9 +129,9 @@ if (document) {

};
LocalState.prototype.resolveDocument = function (document, rootValue, context, variables, fragmentMatcher, onlyRunForcedResolvers) {
if (context === void 0) { context = {}; }
if (variables === void 0) { variables = {}; }
if (fragmentMatcher === void 0) { fragmentMatcher = function () { return true; }; }
if (onlyRunForcedResolvers === void 0) { onlyRunForcedResolvers = false; }
return __awaiter(this, void 0, void 0, function () {
LocalState.prototype.resolveDocument = function (document_1, rootValue_1) {
return __awaiter(this, arguments, void 0, function (document, rootValue, context, variables, fragmentMatcher, onlyRunForcedResolvers) {
var mainDefinition, fragments, fragmentMap, selectionsToResolve, definitionOperation, defaultOperationType, _a, cache, client, execContext, isClientFieldDescendant;
if (context === void 0) { context = {}; }
if (variables === void 0) { variables = {}; }
if (fragmentMatcher === void 0) { fragmentMatcher = function () { return true; }; }
if (onlyRunForcedResolvers === void 0) { onlyRunForcedResolvers = false; }
return __generator(this, function (_b) {

@@ -138,0 +138,0 @@ mainDefinition = getMainDefinition(document);

@@ -134,3 +134,20 @@ import { __assign } from "tslib";

var _this = this;
var _a;
var oldDiff = this.lastDiff && this.lastDiff.diff;
// If we do not tolerate partial results, skip this update to prevent it
// from being reported. This prevents a situtuation where a query that
// errors and another succeeds with overlapping data does not report the
// partial data result to the errored query.
//
// See https://github.com/apollographql/apollo-client/issues/11400 for more
// information on this issue.
if (diff &&
!diff.complete &&
!((_a = this.observableQuery) === null || _a === void 0 ? void 0 : _a.options.returnPartialData) &&
// In the case of a cache eviction, the diff will become partial so we
// schedule a notification to send a network request (this.oqListener) to
// go and fetch the missing data.
!(oldDiff && oldDiff.complete)) {
return;
}
this.updateLastDiff(diff);

@@ -137,0 +154,0 @@ if (!this.dirty && !equal(oldDiff && oldDiff.result, diff && diff.result)) {

@@ -83,8 +83,8 @@ import { __assign, __awaiter, __generator } from "tslib";

QueryManager.prototype.mutate = function (_a) {
var _b, _c;
var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries, _d = _a.refetchQueries, refetchQueries = _d === void 0 ? [] : _d, _e = _a.awaitRefetchQueries, awaitRefetchQueries = _e === void 0 ? false : _e, updateWithProxyFn = _a.update, onQueryUpdated = _a.onQueryUpdated, _f = _a.fetchPolicy, fetchPolicy = _f === void 0 ? ((_b = this.defaultOptions.mutate) === null || _b === void 0 ? void 0 : _b.fetchPolicy) || "network-only" : _f, _g = _a.errorPolicy, errorPolicy = _g === void 0 ? ((_c = this.defaultOptions.mutate) === null || _c === void 0 ? void 0 : _c.errorPolicy) || "none" : _g, keepRootFields = _a.keepRootFields, context = _a.context;
return __awaiter(this, void 0, void 0, function () {
return __awaiter(this, arguments, void 0, function (_b) {
var mutationId, hasClientExports, mutationStoreValue, isOptimistic, self;
return __generator(this, function (_h) {
switch (_h.label) {
var _c, _d;
var mutation = _b.mutation, variables = _b.variables, optimisticResponse = _b.optimisticResponse, updateQueries = _b.updateQueries, _e = _b.refetchQueries, refetchQueries = _e === void 0 ? [] : _e, _f = _b.awaitRefetchQueries, awaitRefetchQueries = _f === void 0 ? false : _f, updateWithProxyFn = _b.update, onQueryUpdated = _b.onQueryUpdated, _g = _b.fetchPolicy, fetchPolicy = _g === void 0 ? ((_c = this.defaultOptions.mutate) === null || _c === void 0 ? void 0 : _c.fetchPolicy) || "network-only" : _g, _h = _b.errorPolicy, errorPolicy = _h === void 0 ? ((_d = this.defaultOptions.mutate) === null || _d === void 0 ? void 0 : _d.errorPolicy) || "none" : _h, keepRootFields = _b.keepRootFields, context = _b.context;
return __generator(this, function (_j) {
switch (_j.label) {
case 0:

@@ -100,4 +100,4 @@ invariant(mutation, 26);

case 1:
variables = (_h.sent());
_h.label = 2;
variables = (_j.sent());
_j.label = 2;
case 2:

@@ -104,0 +104,0 @@ mutationStoreValue = this.mutationStore &&

@@ -158,3 +158,3 @@ import type { DocumentNode } from "graphql";

/**
* Specifies the {@link FetchPolicy} to be used after this query has completed.
* Specifies the `FetchPolicy` to be used after this query has completed.
*

@@ -323,3 +323,3 @@ * @docGroup

/**
* Specifies the {@link ErrorPolicy} to be used for this operation
* Specifies the `ErrorPolicy` to be used for this operation
*/

@@ -346,3 +346,3 @@ errorPolicy?: ErrorPolicy;

/**
* A {@link MutationQueryReducersMap}, which is map from query names to mutation query reducers. Briefly, this map defines how to incorporate the results of the mutation into the results of queries that are currently being watched by your application.
* A `MutationQueryReducersMap`, which is map from query names to mutation query reducers. Briefly, this map defines how to incorporate the results of the mutation into the results of queries that are currently being watched by your application.
*/

@@ -349,0 +349,0 @@ updateQueries?: MutationQueryReducersMap<TData>;

@@ -431,3 +431,3 @@ 'use strict';

var version = "0.0.0-pr-11594-20240213203418";
var version = "0.0.0-pr-11605-20240321163144";

@@ -519,2 +519,6 @@ function maybe(thunk) {

function setErrorMessageHandler(handler) {
globals.global[ApolloErrorMessageHandler] = handler;
}
function loadErrorMessageHandler() {

@@ -525,20 +529,18 @@ var errorCodes = [];

}
if (!globals.global[ApolloErrorMessageHandler]) {
globals.global[ApolloErrorMessageHandler] = handler;
}
setErrorMessageHandler(handler);
for (var _a = 0, errorCodes_1 = errorCodes; _a < errorCodes_1.length; _a++) {
var codes = errorCodes_1[_a];
Object.assign(globals.global[ApolloErrorMessageHandler], codes);
Object.assign(handler, codes);
}
return globals.global[ApolloErrorMessageHandler];
function handler(message, args) {
if (typeof message === "number") {
var definition = globals.global[ApolloErrorMessageHandler][message];
if (!message || !(definition === null || definition === void 0 ? void 0 : definition.message))
return;
message = definition.message;
}
return args.reduce(function (msg, arg) { return msg.replace(/%[sdfo]/, String(arg)); }, String(message));
return handler;
}
var handler = (function (message, args) {
if (typeof message === "number") {
var definition = globals.global[ApolloErrorMessageHandler][message];
if (!message || !(definition === null || definition === void 0 ? void 0 : definition.message))
return;
message = definition.message;
}
}
return args.reduce(function (msg, arg) { return msg.replace(/%[sdfo]/, String(arg)); }, String(message));
});

@@ -556,2 +558,3 @@ function loadDevMessages() {

exports.loadErrorMessages = loadErrorMessages;
exports.setErrorMessageHandler = setErrorMessageHandler;
//# sourceMappingURL=dev.cjs.map
export { loadDevMessages } from "./loadDevMessages.js";
export { loadErrorMessageHandler } from "./loadErrorMessageHandler.js";
export { loadErrorMessages } from "./loadErrorMessages.js";
export { setErrorMessageHandler } from "./setErrorMessageHandler.js";
export type { ErrorMessageHandler } from "./setErrorMessageHandler.js";
//# sourceMappingURL=index.d.ts.map
export { loadDevMessages } from "./loadDevMessages.js";
export { loadErrorMessageHandler } from "./loadErrorMessageHandler.js";
export { loadErrorMessages } from "./loadErrorMessages.js";
export { setErrorMessageHandler } from "./setErrorMessageHandler.js";
//# sourceMappingURL=index.js.map
import type { ErrorCodes } from "../invariantErrorCodes.js";
export declare function loadErrorMessageHandler(...errorCodes: ErrorCodes[]): ((message: string | number, args: unknown[]) => string | undefined) & ErrorCodes;
import type { ErrorMessageHandler } from "./setErrorMessageHandler.js";
/**
* Injects Apollo Client's default error message handler into the application and
* also loads the error codes that are passed in as arguments.
*/
export declare function loadErrorMessageHandler(...errorCodes: ErrorCodes[]): ErrorMessageHandler & ErrorCodes;
//# sourceMappingURL=loadErrorMessageHandler.d.ts.map
import { global } from "../utilities/globals/index.js";
import { ApolloErrorMessageHandler } from "../utilities/globals/invariantWrappers.js";
import { setErrorMessageHandler } from "./setErrorMessageHandler.js";
/**
* Injects Apollo Client's default error message handler into the application and
* also loads the error codes that are passed in as arguments.
*/
export function loadErrorMessageHandler() {

@@ -8,20 +13,18 @@ var errorCodes = [];

}
if (!global[ApolloErrorMessageHandler]) {
global[ApolloErrorMessageHandler] = handler;
}
setErrorMessageHandler(handler);
for (var _a = 0, errorCodes_1 = errorCodes; _a < errorCodes_1.length; _a++) {
var codes = errorCodes_1[_a];
Object.assign(global[ApolloErrorMessageHandler], codes);
Object.assign(handler, codes);
}
return global[ApolloErrorMessageHandler];
function handler(message, args) {
if (typeof message === "number") {
var definition = global[ApolloErrorMessageHandler][message];
if (!message || !(definition === null || definition === void 0 ? void 0 : definition.message))
return;
message = definition.message;
}
return args.reduce(function (msg, arg) { return msg.replace(/%[sdfo]/, String(arg)); }, String(message));
return handler;
}
var handler = (function (message, args) {
if (typeof message === "number") {
var definition = global[ApolloErrorMessageHandler][message];
if (!message || !(definition === null || definition === void 0 ? void 0 : definition.message))
return;
message = definition.message;
}
}
return args.reduce(function (msg, arg) { return msg.replace(/%[sdfo]/, String(arg)); }, String(message));
});
//# sourceMappingURL=loadErrorMessageHandler.js.map

@@ -119,2 +119,6 @@ import { __assign, __rest } from "tslib";

}
if (globalThis.__DEV__ !== false) {
options.context = context;
options.operation = operation;
}
return new Observable(function (observer) {

@@ -121,0 +125,0 @@ // Prefer linkOptions.fetch (preferredFetch) if provided, and otherwise

@@ -184,6 +184,6 @@ 'use strict';

function readMultipartBody(response, nextValue) {
var _a;
return tslib.__awaiter(this, void 0, void 0, function () {
var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _b, value, done, chunk, searchFrom, bi, message, i, headers, contentType_1, body, result, next;
var _c, _d;
var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _a, value, done, chunk, searchFrom, bi, message, i, headers, contentType_1, body, result, next;
var _b, _c;
var _d;
return tslib.__generator(this, function (_e) {

@@ -196,3 +196,3 @@ switch (_e.label) {

decoder = new TextDecoder("utf-8");
contentType = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("content-type");
contentType = (_d = response.headers) === null || _d === void 0 ? void 0 : _d.get("content-type");
delimiter = "boundary=";

@@ -211,3 +211,3 @@ boundaryVal = (contentType === null || contentType === void 0 ? void 0 : contentType.includes(delimiter)) ?

case 2:
_b = _e.sent(), value = _b.value, done = _b.done;
_a = _e.sent(), value = _a.value, done = _a.done;
chunk = typeof value === "string" ? value : decoder.decode(value);

@@ -220,6 +220,6 @@ searchFrom = buffer.length - boundary.length + 1;

message = void 0;
_c = [
_b = [
buffer.slice(0, bi),
buffer.slice(bi + boundary.length),
], message = _c[0], buffer = _c[1];
], message = _b[0], buffer = _b[1];
i = message.indexOf("\r\n\r\n");

@@ -249,3 +249,3 @@ headers = parseHeaders(message.slice(0, i));

if ("errors" in result) {
next = tslib.__assign(tslib.__assign({}, next), { extensions: tslib.__assign(tslib.__assign({}, ("extensions" in next ? next.extensions : null)), (_d = {}, _d[errors.PROTOCOL_ERRORS_SYMBOL] = result.errors, _d)) });
next = tslib.__assign(tslib.__assign({}, next), { extensions: tslib.__assign(tslib.__assign({}, ("extensions" in next ? next.extensions : null)), (_c = {}, _c[errors.PROTOCOL_ERRORS_SYMBOL] = result.errors, _c)) });
}

@@ -585,2 +585,6 @@ nextValue(next);

}
if (globalThis.__DEV__ !== false) {
options.context = context;
options.operation = operation;
}
return new utilities.Observable(function (observer) {

@@ -587,0 +591,0 @@ var currentFetch = preferredFetch || utilities.maybe(function () { return fetch; }) || backupFetch;

@@ -8,6 +8,6 @@ import { __assign, __awaiter, __generator } from "tslib";

export function readMultipartBody(response, nextValue) {
var _a;
return __awaiter(this, void 0, void 0, function () {
var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _b, value, done, chunk, searchFrom, bi, message, i, headers, contentType_1, body, result, next;
var _c, _d;
var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _a, value, done, chunk, searchFrom, bi, message, i, headers, contentType_1, body, result, next;
var _b, _c;
var _d;
return __generator(this, function (_e) {

@@ -20,3 +20,3 @@ switch (_e.label) {

decoder = new TextDecoder("utf-8");
contentType = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("content-type");
contentType = (_d = response.headers) === null || _d === void 0 ? void 0 : _d.get("content-type");
delimiter = "boundary=";

@@ -35,3 +35,3 @@ boundaryVal = (contentType === null || contentType === void 0 ? void 0 : contentType.includes(delimiter)) ?

case 2:
_b = _e.sent(), value = _b.value, done = _b.done;
_a = _e.sent(), value = _a.value, done = _a.done;
chunk = typeof value === "string" ? value : decoder.decode(value);

@@ -44,6 +44,6 @@ searchFrom = buffer.length - boundary.length + 1;

message = void 0;
_c = [
_b = [
buffer.slice(0, bi),
buffer.slice(bi + boundary.length),
], message = _c[0], buffer = _c[1];
], message = _b[0], buffer = _b[1];
i = message.indexOf("\r\n\r\n");

@@ -73,3 +73,3 @@ headers = parseHeaders(message.slice(0, i));

if ("errors" in result) {
next = __assign(__assign({}, next), { extensions: __assign(__assign({}, ("extensions" in next ? next.extensions : null)), (_d = {}, _d[PROTOCOL_ERRORS_SYMBOL] = result.errors, _d)) });
next = __assign(__assign({}, next), { extensions: __assign(__assign({}, ("extensions" in next ? next.extensions : null)), (_c = {}, _c[PROTOCOL_ERRORS_SYMBOL] = result.errors, _c)) });
}

@@ -76,0 +76,0 @@ nextValue(next);

{
"name": "@apollo/client",
"version": "0.0.0-pr-11594-20240213203418",
"version": "0.0.0-pr-11605-20240321163144",
"description": "A fully-featured caching GraphQL client.",

@@ -62,3 +62,3 @@ "private": false,

"prop-types": "^15.7.2",
"rehackt": "0.0.4",
"rehackt": "0.0.6",
"response-iterator": "^0.2.6",

@@ -71,11 +71,12 @@ "symbol-observable": "^4.0.0",

"devDependencies": {
"@arethetypeswrong/cli": "0.13.8",
"@babel/parser": "7.23.9",
"@arethetypeswrong/cli": "0.15.2",
"@babel/parser": "7.24.0",
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.1",
"@graphql-tools/schema": "10.0.2",
"@microsoft/api-extractor": "7.40.1",
"@graphql-tools/schema": "10.0.3",
"@graphql-tools/utils": "10.0.13",
"@microsoft/api-extractor": "7.42.3",
"@rollup/plugin-node-resolve": "11.2.1",
"@size-limit/esbuild-why": "11.0.2",
"@size-limit/preset-small-lib": "11.0.2",
"@size-limit/esbuild-why": "11.1.1",
"@size-limit/preset-small-lib": "11.1.1",
"@testing-library/jest-dom": "6.4.2",

@@ -91,14 +92,14 @@ "@testing-library/react": "14.2.1",

"@types/jest": "29.5.12",
"@types/lodash": "4.14.202",
"@types/node": "20.11.17",
"@types/lodash": "4.17.0",
"@types/node": "20.11.28",
"@types/node-fetch": "2.6.11",
"@types/react": "18.2.55",
"@types/react-dom": "18.2.19",
"@types/react": "18.2.67",
"@types/react-dom": "18.2.22",
"@types/relay-runtime": "14.1.23",
"@types/use-sync-external-store": "0.0.6",
"@typescript-eslint/eslint-plugin": "6.21.0",
"@typescript-eslint/parser": "6.21.0",
"@typescript-eslint/rule-tester": "6.21.0",
"@typescript-eslint/types": "6.21.0",
"@typescript-eslint/utils": "6.21.0",
"@typescript-eslint/eslint-plugin": "7.3.0",
"@typescript-eslint/parser": "7.3.0",
"@typescript-eslint/rule-tester": "7.3.0",
"@typescript-eslint/types": "7.3.0",
"@typescript-eslint/utils": "7.3.0",
"acorn": "8.11.3",

@@ -108,3 +109,3 @@ "blob-polyfill": "7.0.20220408",

"cross-fetch": "4.0.0",
"eslint": "8.56.0",
"eslint": "8.57.0",
"eslint-import-resolver-typescript": "3.6.1",

@@ -114,3 +115,3 @@ "eslint-plugin-import": "npm:@phryneas/eslint-plugin-import@2.27.5-pr.2813.2817.199971c",

"eslint-plugin-testing-library": "6.2.0",
"expect-type": "0.17.3",
"expect-type": "0.18.0",
"fetch-mock": "9.11.0",

@@ -130,4 +131,4 @@ "glob": "8.1.0",

"react-dom-17": "npm:react-dom@^17",
"react-error-boundary": "4.0.12",
"recast": "0.23.4",
"react-error-boundary": "4.0.13",
"recast": "0.23.6",
"resolve": "1.22.8",

@@ -139,14 +140,14 @@ "rimraf": "5.0.5",

"rxjs": "7.8.1",
"size-limit": "11.0.2",
"size-limit": "11.1.1",
"subscriptions-transport-ws": "0.11.0",
"terser": "5.27.0",
"ts-api-utils": "1.2.1",
"terser": "5.29.2",
"ts-api-utils": "1.3.0",
"ts-jest": "29.1.2",
"ts-jest-resolver": "2.0.1",
"ts-morph": "21.0.1",
"ts-morph": "22.0.0",
"ts-node": "10.9.2",
"typedoc": "0.25.0",
"typescript": "5.3.3",
"typescript": "5.4.2",
"wait-for-observables": "1.0.3",
"web-streams-polyfill": "3.3.2",
"web-streams-polyfill": "4.0.0",
"whatwg-fetch": "3.6.20"

@@ -153,0 +154,0 @@ },

@@ -10,3 +10,3 @@ 'use strict';

var utilities = require('../../utilities');
var equality = require('@wry/equality');
var equal = require('@wry/equality');
var errors = require('../../errors');

@@ -18,2 +18,4 @@ var core = require('../../core');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
function _interopNamespace(e) {

@@ -32,2 +34,3 @@ if (e && e.__esModule) return e;

var React__namespace = /*#__PURE__*/_interopNamespace(React);
var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);

@@ -90,5 +93,60 @@ function useApolloClient(override) {

function useDeepMemo(memoFn, deps) {
var ref = React__namespace.useRef();
if (!ref.current || !equal.equal(ref.current.deps, deps)) {
ref.current = { value: memoFn(), deps: deps };
}
return ref.current.value;
}
function getRenderDispatcher() {
var _a, _b;
return (_b = (_a = React__namespace.__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;
function useRenderGuard() {
RenderDispatcher = getRenderDispatcher();
return React__namespace.useCallback(function () {
return (RenderDispatcher != null && RenderDispatcher === getRenderDispatcher());
}, []);
}
var INIT = {};
function useLazyRef(getInitialValue) {
var ref = React__namespace.useRef(INIT);
if (ref.current === INIT) {
ref.current = getInitialValue();
}
return ref;
}
var useKey = "use";
var realHook = React__namespace[useKey];
var __use = realHook ||
function __use(promise) {
var statefulPromise = utilities.wrapPromiseWithState(promise);
switch (statefulPromise.status) {
case "pending":
throw statefulPromise;
case "rejected":
throw statefulPromise.reason;
case "fulfilled":
return statefulPromise.value;
}
};
var wrapperSymbol = Symbol.for("apollo.hook.wrappers");
function wrapHook(hookName, useHook, clientOrObsQuery) {
var queryManager = clientOrObsQuery["queryManager"];
var wrappers = queryManager && queryManager[wrapperSymbol];
var wrapper = wrappers && wrappers[hookName];
return wrapper ? wrapper(useHook) : useHook;
}
var hasOwnProperty = Object.prototype.hasOwnProperty;
function useQuery(query, options) {
if (options === void 0) { options = Object.create(null); }
return wrapHook("useQuery", _useQuery, useApolloClient(options && options.client))(query, options);
}
function _useQuery(query, options) {
return useInternalState(useApolloClient(options.client), query).useQuery(options);

@@ -178,3 +236,3 @@ }

previousResult.networkStatus === result.networkStatus &&
equality.equal(previousResult.data, result.data)) {
equal.equal(previousResult.data, result.data)) {
return;

@@ -193,3 +251,3 @@ }

(previousResult && previousResult.loading) ||
!equality.equal(error, previousResult.error)) {
!equal.equal(error, previousResult.error)) {
_this.setResult({

@@ -220,3 +278,3 @@ data: (previousResult && previousResult.data),

var currentWatchQueryOptions = this.watchQueryOptions;
if (!equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
if (!equal.equal(watchQueryOptions, currentWatchQueryOptions)) {
this.watchQueryOptions = watchQueryOptions;

@@ -500,3 +558,3 @@ if (currentWatchQueryOptions && this.observable) {

};
if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
if (ref.current.isMounted && !equal.equal(ref.current.result, result_1)) {
setResult((ref.current.result = result_1));

@@ -521,3 +579,3 @@ }

};
if (!equality.equal(ref.current.result, result_2)) {
if (!equal.equal(ref.current.result, result_2)) {
setResult((ref.current.result = result_2));

@@ -611,3 +669,3 @@ }

!(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
!equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
!equal.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) ||
canResetObservableRef.current) {

@@ -704,47 +762,6 @@ setResult({

function useDeepMemo(memoFn, deps) {
var ref = React__namespace.useRef();
if (!ref.current || !equality.equal(ref.current.deps, deps)) {
ref.current = { value: memoFn(), deps: deps };
}
return ref.current.value;
function useFragment(options) {
return wrapHook("useFragment", _useFragment, useApolloClient(options.client))(options);
}
function getRenderDispatcher() {
var _a, _b;
return (_b = (_a = React__namespace.__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;
function useRenderGuard() {
RenderDispatcher = getRenderDispatcher();
return React__namespace.useCallback(function () {
return (RenderDispatcher !== null && RenderDispatcher === getRenderDispatcher());
}, []);
}
var INIT = {};
function useLazyRef(getInitialValue) {
var ref = React__namespace.useRef(INIT);
if (ref.current === INIT) {
ref.current = getInitialValue();
}
return ref;
}
var useKey = "use";
var realHook = React__namespace[useKey];
var __use = realHook ||
function __use(promise) {
var statefulPromise = utilities.wrapPromiseWithState(promise);
switch (statefulPromise.status) {
case "pending":
throw statefulPromise;
case "rejected":
throw statefulPromise.reason;
case "fulfilled":
return statefulPromise.value;
}
};
function useFragment(options) {
function _useFragment(options) {
var cache = useApolloClient(options.client).cache;

@@ -758,17 +775,23 @@ var diffOptions = useDeepMemo(function () {

});
var stableOptions = useDeepMemo(function () { return options; }, [options]);
React__namespace.useMemo(function () {
resultRef.current = diffToResult(cache.diff(diffOptions));
}, [diffOptions, cache]);
var getSnapshot = React__namespace.useCallback(function () { return resultRef.current; }, []);
return useSyncExternalStore(React__namespace.useCallback(function (forceUpdate) {
var lastTimeout = 0;
var unsubscribe = cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
if (!equality.equal(diff.result, resultRef.current.data)) {
resultRef.current = diffToResult(diff);
clearTimeout(lastTimeout);
lastTimeout = setTimeout(forceUpdate);
}
} }));
var subscription = cache.watchFragment(stableOptions).subscribe({
next: function (result) {
if (equal__default(result, resultRef.current))
return;
resultRef.current = result;
clearTimeout(lastTimeout);
lastTimeout = setTimeout(forceUpdate);
},
});
return function () {
unsubscribe();
subscription.unsubscribe();
clearTimeout(lastTimeout);
};
}, [cache, diffOptions]), getSnapshot, getSnapshot);
}, [cache, stableOptions]), getSnapshot, getSnapshot);
}

@@ -790,2 +813,5 @@ function diffToResult(diff) {

if (options === void 0) { options = Object.create(null); }
return wrapHook("useSuspenseQuery", _useSuspenseQuery, useApolloClient(typeof options === "object" ? options.client : undefined))(query, options);
}
function _useSuspenseQuery(query, options) {
var client = useApolloClient(options.client);

@@ -908,2 +934,5 @@ var suspenseCache = internal.getSuspenseCache(client);

if (options === void 0) { options = Object.create(null); }
return wrapHook("useBackgroundQuery", _useBackgroundQuery, useApolloClient(typeof options === "object" ? options.client : undefined))(query, options);
}
function _useBackgroundQuery(query, options) {
var client = useApolloClient(options.client);

@@ -1023,2 +1052,5 @@ var suspenseCache = internal.getSuspenseCache(client);

function useReadQuery(queryRef) {
return wrapHook("useReadQuery", _useReadQuery, internal.unwrapQueryRef(queryRef)["observable"])(queryRef);
}
function _useReadQuery(queryRef) {
var internalQueryRef = React__namespace.useMemo(function () { return internal.unwrapQueryRef(queryRef); }, [queryRef]);

@@ -1025,0 +1057,0 @@ var getPromise = React__namespace.useCallback(function () { return internal.getWrappedPromise(queryRef); }, [queryRef]);

@@ -6,2 +6,3 @@ export { useDeepMemo } from "./useDeepMemo.js";

export { __use } from "./__use.js";
export { wrapHook } from "./wrapHook.js";
//# sourceMappingURL=index.d.ts.map

@@ -7,2 +7,3 @@ // These hooks are used internally and are not exported publicly by the library

export { __use } from "./__use.js";
export { wrapHook } from "./wrapHook.js";
//# sourceMappingURL=index.js.map

@@ -14,5 +14,5 @@ import * as React from "rehackt";

return React.useCallback(function () {
return (RenderDispatcher !== null && RenderDispatcher === getRenderDispatcher());
return (RenderDispatcher != null && RenderDispatcher === getRenderDispatcher());
}, []);
}
//# sourceMappingURL=useRenderGuard.js.map

@@ -5,2 +5,3 @@ import { __spreadArray } from "tslib";

import { getSuspenseCache, unwrapQueryRef, updateWrappedQueryRef, wrapQueryRef, } from "../internal/index.js";
import { wrapHook } from "./internal/index.js";
import { useWatchQueryOptions } from "./useSuspenseQuery.js";

@@ -10,2 +11,5 @@ import { canonicalStringify } from "../../cache/index.js";

if (options === void 0) { options = Object.create(null); }
return wrapHook("useBackgroundQuery", _useBackgroundQuery, useApolloClient(typeof options === "object" ? options.client : undefined))(query, options);
}
function _useBackgroundQuery(query, options) {
var client = useApolloClient(options.client);

@@ -12,0 +16,0 @@ var suspenseCache = getSuspenseCache(client);

@@ -9,3 +9,3 @@ import type { DeepPartial } from "../../utilities/index.js";

/**
* The instance of {@link ApolloClient} to use to look up the fragment.
* The instance of `ApolloClient` to use to look up the fragment.
*

@@ -12,0 +12,0 @@ * By default, the instance that's passed down via context is used, but you

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";
import { useDeepMemo, useLazyRef, wrapHook } from "./internal/index.js";
import equal from "@wry/equality";
export function useFragment(options) {
return wrapHook("useFragment", _useFragment, useApolloClient(options.client))(options);
}
function _useFragment(options) {
var cache = useApolloClient(options.client).cache;

@@ -17,2 +20,8 @@ var diffOptions = useDeepMemo(function () {

});
var stableOptions = useDeepMemo(function () { return options; }, [options]);
// Since .next is async, we need to make sure that we
// get the correct diff on the next render given new diffOptions
React.useMemo(function () {
resultRef.current = diffToResult(cache.diff(diffOptions));
}, [diffOptions, cache]);
// Used for both getSnapshot and getServerSnapshot

@@ -22,18 +31,20 @@ var getSnapshot = React.useCallback(function () { return resultRef.current; }, []);

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);
}
} }));
var subscription = cache.watchFragment(stableOptions).subscribe({
next: function (result) {
if (equal(result, resultRef.current))
return;
resultRef.current = result;
// 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();
subscription.unsubscribe();
clearTimeout(lastTimeout);
};
}, [cache, diffOptions]), getSnapshot, getSnapshot);
}, [cache, stableOptions]), getSnapshot, getSnapshot);
}

@@ -40,0 +51,0 @@ function diffToResult(diff) {

@@ -13,2 +13,3 @@ import { __assign, __rest } from "tslib";

import { canUseWeakMap, compact, isNonEmptyArray, maybeDeepFreeze, } from "../../utilities/index.js";
import { wrapHook } from "./internal/index.js";
var hasOwnProperty = Object.prototype.hasOwnProperty;

@@ -51,2 +52,5 @@ /**

if (options === void 0) { options = Object.create(null); }
return wrapHook("useQuery", _useQuery, useApolloClient(options && options.client))(query, options);
}
function _useQuery(query, options) {
return useInternalState(useApolloClient(options.client), query).useQuery(options);

@@ -53,0 +57,0 @@ }

import * as React from "rehackt";
import { getWrappedPromise, unwrapQueryRef, updateWrappedQueryRef, } from "../internal/index.js";
import { __use } from "./internal/index.js";
import { __use, wrapHook } from "./internal/index.js";
import { toApolloError } from "./useSuspenseQuery.js";
import { useSyncExternalStore } from "./useSyncExternalStore.js";
export function useReadQuery(queryRef) {
return wrapHook("useReadQuery", _useReadQuery, unwrapQueryRef(queryRef)["observable"])(queryRef);
}
function _useReadQuery(queryRef) {
var internalQueryRef = React.useMemo(function () { return unwrapQueryRef(queryRef); }, [queryRef]);

@@ -8,0 +11,0 @@ var getPromise = React.useCallback(function () { return getWrappedPromise(queryRef); }, [queryRef]);

@@ -8,3 +8,3 @@ import { __assign, __spreadArray } from "tslib";

import { DocumentType, verifyDocumentType } from "../parser/index.js";
import { __use, useDeepMemo } from "./internal/index.js";
import { __use, useDeepMemo, wrapHook } from "./internal/index.js";
import { getSuspenseCache } from "../internal/index.js";

@@ -15,2 +15,5 @@ import { canonicalStringify } from "../../cache/index.js";

if (options === void 0) { options = Object.create(null); }
return wrapHook("useSuspenseQuery", _useSuspenseQuery, useApolloClient(typeof options === "object" ? options.client : undefined))(query, options);
}
function _useSuspenseQuery(query, options) {
var client = useApolloClient(options.client);

@@ -17,0 +20,0 @@ var suspenseCache = getSuspenseCache(client);

@@ -10,4 +10,4 @@ import type { ApolloQueryResult, ObservableQuery, OperationVariables, WatchQueryOptions } from "../../../core/index.js";

/**
* A `QueryReference` is an opaque object returned by {@link useBackgroundQuery}.
* A child component reading the `QueryReference` via {@link useReadQuery} will
* A `QueryReference` is an opaque object returned by `useBackgroundQuery`.
* A child component reading the `QueryReference` via `useReadQuery` will
* suspend until the promise resolves.

@@ -14,0 +14,0 @@ */

@@ -240,7 +240,19 @@ import { __assign } from "tslib";

.then(function (result) {
var _a;
if (_this.promise.status === "pending") {
_this.result = result;
(_a = _this.resolve) === null || _a === void 0 ? void 0 : _a.call(_this, result);
}
// In the case of `fetchMore`, this promise is resolved before a cache
// result is emitted due to the fact that `fetchMore` sets a `no-cache`
// fetch policy and runs `cache.batch` in its `.then` handler. Because
// the timing is different, we accidentally run this update twice
// causing an additional re-render with the `fetchMore` result by
// itself. By wrapping in `setTimeout`, this should provide a short
// delay to allow the `QueryInfo.notify` handler to run before this
// promise is checked.
// See https://github.com/apollographql/apollo-client/issues/11315 for
// more information
setTimeout(function () {
var _a;
if (_this.promise.status === "pending") {
_this.result = result;
(_a = _this.resolve) === null || _a === void 0 ? void 0 : _a.call(_this, result);
}
});
})

@@ -247,0 +259,0 @@ .catch(function () { });

@@ -6,2 +6,3 @@ export { getSuspenseCache } from "./cache/getSuspenseCache.js";

export type { SuspenseCacheOptions } from "./cache/SuspenseCache.js";
export type { HookWrappers } from "../hooks/internal/wrapHook.js";
//# sourceMappingURL=index.d.ts.map

@@ -211,7 +211,9 @@ 'use strict';

.then(function (result) {
var _a;
if (_this.promise.status === "pending") {
_this.result = result;
(_a = _this.resolve) === null || _a === void 0 ? void 0 : _a.call(_this, result);
}
setTimeout(function () {
var _a;
if (_this.promise.status === "pending") {
_this.result = result;
(_a = _this.resolve) === null || _a === void 0 ? void 0 : _a.call(_this, result);
}
});
})

@@ -218,0 +220,0 @@ .catch(function () { });

@@ -111,3 +111,3 @@ import type { ApolloClient, DefaultContext, DocumentNode, ErrorPolicy, OperationVariables, RefetchWritePolicy, TypedDocumentNode, WatchQueryFetchPolicy } from "../../core/index.js";

* A function that will begin loading a query when called. It's result can be
* read by {@link useReadQuery} which will suspend until the query is loaded.
* read by `useReadQuery` which will suspend until the query is loaded.
* This is useful when you want to start loading a query as early as possible

@@ -138,3 +138,3 @@ * outside of a React component.

/**
* A function that will begin loading a query when called. It's result can be read by {@link useReadQuery} which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
* A function that will begin loading a query when called. It's result can be read by `useReadQuery` which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
*

@@ -163,3 +163,3 @@ * @example

/**
* A function that will begin loading a query when called. It's result can be read by {@link useReadQuery} which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
* A function that will begin loading a query when called. It's result can be read by `useReadQuery` which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
*

@@ -191,3 +191,3 @@ * @example

/**
* A function that will begin loading a query when called. It's result can be read by {@link useReadQuery} which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
* A function that will begin loading a query when called. It's result can be read by `useReadQuery` which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
*

@@ -218,3 +218,3 @@ * @example

/**
* A function that will begin loading a query when called. It's result can be read by {@link useReadQuery} which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
* A function that will begin loading a query when called. It's result can be read by `useReadQuery` which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
*

@@ -245,3 +245,3 @@ * @example

/**
* A function that will begin loading a query when called. It's result can be read by {@link useReadQuery} which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
* A function that will begin loading a query when called. It's result can be read by `useReadQuery` which will suspend until the query is loaded. This is useful when you want to start loading a query as early as possible outside of a React component.
*

@@ -248,0 +248,0 @@ * @example

@@ -24,3 +24,3 @@ import type * as ReactTypes from "react";

/**
* The instance of {@link ApolloClient} to use to execute the query.
* The instance of `ApolloClient` to use to execute the query.
*

@@ -270,3 +270,3 @@ * By default, the instance that's passed down via context is used, but you can provide a different instance here.

/**
* The instance of {@link ApolloClient} to use to execute the query.
* The instance of `ApolloClient` to use to execute the query.
*

@@ -421,3 +421,3 @@ * By default, the instance that's passed down via context is used, but you can provide a different instance here.

/**
* The instance of {@link ApolloClient} to use to execute the query.
* The instance of `ApolloClient` to use to execute the query.
*

@@ -424,0 +424,0 @@ * By default, the instance that's passed down via context is used, but you can provide a different instance here.

@@ -43,3 +43,3 @@ export interface QueryOptionsDocumentation {

/**
* Specifies the {@link FetchPolicy} to be used after this query has completed.
* Specifies the `FetchPolicy` to be used after this query has completed.
*

@@ -155,3 +155,3 @@ * @docGroup 3. Caching options

/**
* The instance of {@link ApolloClient} to use to execute the query.
* The instance of `ApolloClient` to use to execute the query.
*

@@ -345,3 +345,3 @@ * By default, the instance that's passed down via context is used, but you

/**
* A {@link MutationQueryReducersMap}, which is map from query names to
* A `MutationQueryReducersMap`, which is map from query names to
* mutation query reducers. Briefly, this map defines how to incorporate the

@@ -494,3 +494,3 @@ * results of the mutation into the results of queries that are currently

/**
* Specifies the {@link ErrorPolicy} to be used for this operation
* Specifies the `ErrorPolicy` to be used for this operation
*/

@@ -497,0 +497,0 @@ errorPolicy: unknown;

@@ -12,2 +12,5 @@ 'use strict';

var cache = require('../../cache');
var schema = require('@graphql-tools/schema');
var nodeFetch = require('node-fetch');
var graphql = require('graphql');

@@ -300,2 +303,60 @@ function requestToKey(request, addTypename) {

var proxiedSchema = function (schemaWithMocks, resolvers) {
var targetSchema = schema.addResolversToSchema({
schema: schemaWithMocks,
resolvers: resolvers,
});
var fns = {
addResolvers: function (newResolvers) {
return (targetSchema = schema.addResolversToSchema({
schema: targetSchema,
resolvers: tslib.__assign(tslib.__assign({}, resolvers), newResolvers),
}));
},
forkWithResolvers: function (newResolvers) {
return proxiedSchema(targetSchema, newResolvers);
},
reset: function () {
targetSchema = schema.addResolversToSchema({
schema: schemaWithMocks,
resolvers: resolvers,
});
},
};
var schema$1 = new Proxy(targetSchema, {
get: function (_target, p) {
if (p in fns) {
return Reflect.get(fns, p);
}
return Reflect.get(targetSchema, p);
},
});
return schema$1;
};
var createMockFetch = function (schema) {
var mockFetch = function (uri, options) {
return new Promise(function (resolve) { return tslib.__awaiter(void 0, void 0, void 0, function () {
var result, stringifiedResult;
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 , graphql.execute({
schema: schema,
contextValue: options.context,
document: options.operation.query,
variableValues: options.operation.variables,
operationName: options.operation.operationName,
})];
case 1:
result = _a.sent();
stringifiedResult = JSON.stringify(result);
resolve(new nodeFetch.Response(stringifiedResult));
return [2 ];
}
});
}); });
};
return mockFetch;
};
function wrapTestFunction(fn, consoleMethodName) {

@@ -346,5 +407,7 @@ return function () {

exports.createMockClient = createMockClient;
exports.createMockFetch = createMockFetch;
exports.itAsync = itAsync;
exports.mockObservableLink = mockObservableLink;
exports.mockSingleLink = mockSingleLink;
exports.proxiedSchema = proxiedSchema;
exports.subscribeAndCount = subscribeAndCount;

@@ -351,0 +414,0 @@ exports.tick = tick;

@@ -8,3 +8,5 @@ export type { MockedResponse, MockLinkOptions, ResultFunction, } from "./mocking/mockLink.js";

export { wait, tick } from "./wait.js";
export { proxiedSchema } from "./schemaProxy.js";
export { createMockFetch } from "./mockFetchWithSchema.js";
export * from "./withConsoleSpy.js";
//# sourceMappingURL=index.d.ts.map

@@ -7,3 +7,5 @@ export { MockLink, mockSingleLink } from "./mocking/mockLink.js";

export { wait, tick } from "./wait.js";
export { proxiedSchema } from "./schemaProxy.js";
export { createMockFetch } from "./mockFetchWithSchema.js";
export * from "./withConsoleSpy.js";
//# sourceMappingURL=index.js.map

@@ -13,3 +13,3 @@ import type { Operation, GraphQLRequest, FetchResult } from "../../../link/core/index.js";

variableMatcher?: VariableMatcher<TVariables>;
newData?: ResultFunction<FetchResult>;
newData?: ResultFunction<FetchResult<TData>, TVariables>;
}

@@ -16,0 +16,0 @@ export interface MockLinkOptions {

@@ -5,2 +5,3 @@ import "../utilities/globals/index.js";

export * from "./core/index.js";
export { createMockSchema } from "./graphql-tools/utils.js";
//# sourceMappingURL=index.d.ts.map
import "../utilities/globals/index.js";
export { MockedProvider } from "./react/MockedProvider.js";
export * from "./core/index.js";
export { createMockSchema } from "./graphql-tools/utils.js";
//# sourceMappingURL=index.js.map

@@ -40,5 +40,5 @@ import { __asyncGenerator, __await, __awaiter, __extends, __generator } from "tslib";

}
IteratorStream.prototype.take = function (_a) {
var _b = _a === void 0 ? {} : _a, _c = _b.timeout, timeout = _c === void 0 ? 100 : _c;
return __awaiter(this, void 0, void 0, function () {
IteratorStream.prototype.take = function () {
return __awaiter(this, arguments, void 0, function (_a) {
var _b = _a === void 0 ? {} : _a, _c = _b.timeout, timeout = _c === void 0 ? 100 : _c;
return __generator(this, function (_d) {

@@ -45,0 +45,0 @@ return [2 /*return*/, Promise.race([

@@ -115,7 +115,7 @@ var _a, _b;

},
peekRender: function (options) {
if (options === void 0) { options = {}; }
return __awaiter(this, void 0, void 0, function () {
peekRender: function () {
return __awaiter(this, arguments, void 0, function (options) {
var render;
var _a;
if (options === void 0) { options = {}; }
return __generator(this, function (_b) {

@@ -133,7 +133,7 @@ if (iteratorPosition < Profiler.renders.length) {

},
takeRender: function (options) {
if (options === void 0) { options = {}; }
return __awaiter(this, void 0, void 0, function () {
takeRender: function () {
return __awaiter(this, arguments, void 0, function (options) {
var env_1, _disabledActWarnings, error, e_1, e_2;
var _a;
if (options === void 0) { options = {}; }
return __generator(this, function (_b) {

@@ -140,0 +140,0 @@ switch (_b.label) {

@@ -29,3 +29,3 @@ import { __makeTemplateObject, __spreadArray } from "tslib";

export function setupPaginatedCase() {
var query = gql(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n query letters($limit: Int, $offset: Int) {\n letters(limit: $limit) {\n letter\n position\n }\n }\n "], ["\n query letters($limit: Int, $offset: Int) {\n letters(limit: $limit) {\n letter\n position\n }\n }\n "])));
var query = gql(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n query LettersQuery($limit: Int, $offset: Int) {\n letters(limit: $limit, offset: $offset) {\n letter\n position\n }\n }\n "], ["\n query LettersQuery($limit: Int, $offset: Int) {\n letters(limit: $limit, offset: $offset) {\n letter\n position\n }\n }\n "])));
var data = "ABCDEFGHIJKLMNOPQRSTUV".split("").map(function (letter, index) { return ({

@@ -32,0 +32,0 @@ __typename: "Letter",

@@ -12,2 +12,5 @@ 'use strict';

var core = require('./core');
var graphql = require('graphql');
var utilities = require('../utilities');
var utils = require('@graphql-tools/utils');

@@ -61,3 +64,134 @@ function _interopNamespace(e) {

var takeRandom = function (arr) { return arr[Math.floor(Math.random() * arr.length)]; };
var createMockSchema = function (staticSchema, mocks) {
var _a;
var getType = function (typeName) {
var type = staticSchema.getType(typeName);
if (!type || !(graphql.isObjectType(type) || graphql.isInterfaceType(type))) {
throw new Error("".concat(typeName, " does not exist on schema or is not an object or interface"));
}
return type;
};
var getFieldType = function (typeName, fieldName) {
if (fieldName === "__typename") {
return graphql.GraphQLString;
}
var type = getType(typeName);
var field = type.getFields()[fieldName];
if (!field) {
throw new Error("".concat(fieldName, " does not exist on type ").concat(typeName));
}
return field.type;
};
var generateValueFromType = function (fieldType) {
var nullableType = graphql.getNullableType(fieldType);
if (graphql.isScalarType(nullableType)) {
var mockFn = mocks[nullableType.name];
if (typeof mockFn !== "function") {
throw new Error("No mock defined for type \"".concat(nullableType.name, "\""));
}
return mockFn();
}
else if (graphql.isEnumType(nullableType)) {
var mockFn = mocks[nullableType.name];
if (typeof mockFn === "function")
return mockFn();
var values = nullableType.getValues().map(function (v) { return v.value; });
return takeRandom(values);
}
else if (graphql.isObjectType(nullableType)) {
return {};
}
else if (graphql.isListType(nullableType)) {
return tslib.__spreadArray([], new Array(2), true).map(function () {
return generateValueFromType(nullableType.ofType);
});
}
else if (graphql.isAbstractType(nullableType)) {
var mock = mocks[nullableType.name];
var typeName = void 0;
var values = {};
if (!mock) {
typeName = takeRandom(staticSchema.getPossibleTypes(nullableType).map(function (t) { return t.name; }));
}
else if (typeof mock === "function") {
var mockRes = mock();
if (mockRes === null)
return null;
if (!utilities.isNonNullObject(mockRes)) {
throw new Error("Value returned by the mock for ".concat(nullableType.name, " is not an object or null"));
}
values = mockRes;
if (typeof values["__typename"] !== "string") {
throw new Error("Please return a __typename in \"".concat(nullableType.name, "\""));
}
typeName = values["__typename"];
}
else if (utilities.isNonNullObject(mock) &&
typeof mock["__typename"] === "function") {
var mockRes = mock["__typename"]();
if (typeof mockRes !== "string") {
throw new Error("'__typename' returned by the mock for abstract type ".concat(nullableType.name, " is not a string"));
}
typeName = mockRes;
}
else {
throw new Error("Please return a __typename in \"".concat(nullableType.name, "\""));
}
return typeName;
}
else {
throw new Error("".concat(nullableType, " not implemented"));
}
};
var isRootType = function (type, schema) {
var rootTypeNames = utils.getRootTypeNames(schema);
return rootTypeNames.has(type.name);
};
var mockResolver = function (source, args, contex, info) {
var defaultResolvedValue = graphql.defaultFieldResolver(source, args, contex, info);
if (defaultResolvedValue !== undefined)
return defaultResolvedValue;
if (isRootType(info.parentType, info.schema)) {
return {
typeName: info.parentType.name,
key: "ROOT",
fieldName: info.fieldName,
fieldArgs: args,
};
}
if (defaultResolvedValue === undefined) {
var fieldType = getFieldType(info.parentType.name, info.fieldName);
return generateValueFromType(fieldType);
}
return undefined;
};
return utils.mapSchema(staticSchema, (_a = {},
_a[utils.MapperKind.OBJECT_FIELD] = function (fieldConfig) {
var newFieldConfig = tslib.__assign({}, fieldConfig);
var oldResolver = fieldConfig.resolve;
if (!oldResolver) {
newFieldConfig.resolve = mockResolver;
}
return newFieldConfig;
},
_a[utils.MapperKind.ABSTRACT_TYPE] = function (type) {
if (type.resolveType != null && type.resolveType.length) {
return;
}
var typeResolver = function (typename) {
return typename;
};
if (graphql.isUnionType(type)) {
return new graphql.GraphQLUnionType(tslib.__assign(tslib.__assign({}, type.toConfig()), { resolveType: typeResolver }));
}
else {
return new graphql.GraphQLInterfaceType(tslib.__assign(tslib.__assign({}, type.toConfig()), { resolveType: typeResolver }));
}
},
_a));
};
exports.MockedProvider = MockedProvider;
exports.createMockSchema = createMockSchema;
for (var k in core) {

@@ -64,0 +198,0 @@ if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = core[k];

@@ -7,3 +7,3 @@ 'use strict';

var version = "0.0.0-pr-11594-20240213203418";
var version = "0.0.0-pr-11605-20240321163144";

@@ -10,0 +10,0 @@ function maybe(thunk) {

@@ -59,3 +59,3 @@ import { InvariantError } from "ts-invariant";

[ApolloErrorMessageHandler]?: {
(message: string | number, args: unknown[]): string | undefined;
(message: string | number, args: string[]): string | undefined;
} & ErrorCodes;

@@ -62,0 +62,0 @@ }

@@ -183,6 +183,6 @@ 'use strict';

function readMultipartBody(response, nextValue) {
var _a;
return tslib.__awaiter(this, void 0, void 0, function () {
var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _b, value, done, chunk, searchFrom, bi, message, i, headers, contentType_1, body, result, next;
var _c, _d;
var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _a, value, done, chunk, searchFrom, bi, message, i, headers, contentType_1, body, result, next;
var _b, _c;
var _d;
return tslib.__generator(this, function (_e) {

@@ -195,3 +195,3 @@ switch (_e.label) {

decoder = new TextDecoder("utf-8");
contentType = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("content-type");
contentType = (_d = response.headers) === null || _d === void 0 ? void 0 : _d.get("content-type");
delimiter = "boundary=";

@@ -210,3 +210,3 @@ boundaryVal = (contentType === null || contentType === void 0 ? void 0 : contentType.includes(delimiter)) ?

case 2:
_b = _e.sent(), value = _b.value, done = _b.done;
_a = _e.sent(), value = _a.value, done = _a.done;
chunk = typeof value === "string" ? value : decoder.decode(value);

@@ -219,6 +219,6 @@ searchFrom = buffer.length - boundary.length + 1;

message = void 0;
_c = [
_b = [
buffer.slice(0, bi),
buffer.slice(bi + boundary.length),
], message = _c[0], buffer = _c[1];
], message = _b[0], buffer = _b[1];
i = message.indexOf("\r\n\r\n");

@@ -248,3 +248,3 @@ headers = parseHeaders(message.slice(0, i));

if ("errors" in result) {
next = tslib.__assign(tslib.__assign({}, next), { extensions: tslib.__assign(tslib.__assign({}, ("extensions" in next ? next.extensions : null)), (_d = {}, _d[errors.PROTOCOL_ERRORS_SYMBOL] = result.errors, _d)) });
next = tslib.__assign(tslib.__assign({}, next), { extensions: tslib.__assign(tslib.__assign({}, ("extensions" in next ? next.extensions : null)), (_c = {}, _c[errors.PROTOCOL_ERRORS_SYMBOL] = result.errors, _c)) });
}

@@ -251,0 +251,0 @@ nextValue(next);

@@ -182,6 +182,6 @@ 'use strict';

function readMultipartBody(response, nextValue) {
var _a;
return tslib.__awaiter(this, void 0, void 0, function () {
var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _b, value, done, chunk, searchFrom, bi, message, i, headers, contentType_1, body, result, next;
var _c, _d;
var decoder, contentType, delimiter, boundaryVal, boundary, buffer, iterator, running, _a, value, done, chunk, searchFrom, bi, message, i, headers, contentType_1, body, result, next;
var _b, _c;
var _d;
return tslib.__generator(this, function (_e) {

@@ -194,3 +194,3 @@ switch (_e.label) {

decoder = new TextDecoder("utf-8");
contentType = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("content-type");
contentType = (_d = response.headers) === null || _d === void 0 ? void 0 : _d.get("content-type");
delimiter = "boundary=";

@@ -209,3 +209,3 @@ boundaryVal = (contentType === null || contentType === void 0 ? void 0 : contentType.includes(delimiter)) ?

case 2:
_b = _e.sent(), value = _b.value, done = _b.done;
_a = _e.sent(), value = _a.value, done = _a.done;
chunk = typeof value === "string" ? value : decoder.decode(value);

@@ -218,6 +218,6 @@ searchFrom = buffer.length - boundary.length + 1;

message = void 0;
_c = [
_b = [
buffer.slice(0, bi),
buffer.slice(bi + boundary.length),
], message = _c[0], buffer = _c[1];
], message = _b[0], buffer = _b[1];
i = message.indexOf("\r\n\r\n");

@@ -247,3 +247,3 @@ headers = parseHeaders(message.slice(0, i));

if ("errors" in result) {
next = tslib.__assign(tslib.__assign({}, next), { extensions: tslib.__assign(tslib.__assign({}, ("extensions" in next ? next.extensions : null)), (_d = {}, _d[errors.PROTOCOL_ERRORS_SYMBOL] = result.errors, _d)) });
next = tslib.__assign(tslib.__assign({}, next), { extensions: tslib.__assign(tslib.__assign({}, ("extensions" in next ? next.extensions : null)), (_c = {}, _c[errors.PROTOCOL_ERRORS_SYMBOL] = result.errors, _c)) });
}

@@ -250,0 +250,0 @@ nextValue(next);

@@ -1,2 +0,2 @@

export var version = "0.0.0-pr-11594-20240213203418";
export var version = "0.0.0-pr-11605-20240321163144";
//# sourceMappingURL=version.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc