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 3.10.0-rc.0 to 3.10.0-rc.1

.changeset/cold-dancers-call.md

10

.changeset/pre.json

@@ -9,7 +9,15 @@ {

"chatty-llamas-switch",
"cold-dancers-call",
"green-garlics-protect",
"hungry-bobcats-battle",
"kind-foxes-float",
"old-onions-sleep",
"spotty-garlics-knock",
"strong-paws-kneel",
"stupid-bears-cheat",
"tasty-pillows-ring",
"tiny-bugs-tap",
"twelve-apples-vanish"
"twelve-apples-vanish",
"wet-plants-admire"
]
}

2

cache/index.d.ts
import "../utilities/globals/index.js";
export type { Transaction } from "./core/cache.js";
export type { Transaction, WatchFragmentOptions, WatchFragmentResult, } from "./core/cache.js";
export { ApolloCache } from "./core/cache.js";

@@ -4,0 +4,0 @@ export { Cache } from "./core/types/Cache.js";

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

this.mutate = this.mutate.bind(this);
this.watchFragment = this.watchFragment.bind(this);
this.resetStore = this.resetStore.bind(this);

@@ -86,0 +87,0 @@ this.reFetchObservableQueries = this.reFetchObservableQueries.bind(this);

@@ -10,3 +10,3 @@ export type { ApolloClientOptions, DefaultOptions } from "./ApolloClient.js";

export { isApolloError, ApolloError } from "../errors/index.js";
export type { Transaction, DataProxy, InMemoryCacheConfig, ReactiveVar, TypePolicies, TypePolicy, FieldPolicy, FieldReadFunction, FieldMergeFunction, FieldFunctionOptions, PossibleTypesMap, } from "../cache/index.js";
export type { Transaction, DataProxy, InMemoryCacheConfig, ReactiveVar, TypePolicies, TypePolicy, FieldPolicy, FieldReadFunction, FieldMergeFunction, FieldFunctionOptions, PossibleTypesMap, WatchFragmentOptions, WatchFragmentResult, } from "../cache/index.js";
export { Cache, ApolloCache, InMemoryCache, MissingFieldError, defaultDataIdFromObject, makeVar, } from "../cache/index.js";

@@ -13,0 +13,0 @@ export * from "../cache/inmemory/types.js";

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

var version = "3.10.0-rc.0";
var version = "3.10.0-rc.1";

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

{
"name": "@apollo/client",
"version": "3.10.0-rc.0",
"version": "3.10.0-rc.1",
"description": "A fully-featured caching GraphQL client.",

@@ -74,2 +74,3 @@ "private": false,

"@changesets/cli": "2.27.1",
"@graphql-tools/merge": "^9.0.3",
"@graphql-tools/schema": "10.0.3",

@@ -76,0 +77,0 @@ "@graphql-tools/utils": "10.0.13",

@@ -1026,2 +1026,8 @@ 'use strict';

function useQueryRefHandlers(queryRef) {
var unwrapped = internal.unwrapQueryRef(queryRef);
return wrapHook("useQueryRefHandlers", _useQueryRefHandlers, unwrapped ?
unwrapped["observable"]
: useApolloClient())(queryRef);
}
function _useQueryRefHandlers(queryRef) {
var _a = React__namespace.useState(queryRef), previousQueryRef = _a[0], setPreviousQueryRef = _a[1];

@@ -1051,3 +1057,6 @@ var _b = React__namespace.useState(queryRef), wrappedQueryRef = _b[0], setWrappedQueryRef = _b[1];

function useReadQuery(queryRef) {
return wrapHook("useReadQuery", _useReadQuery, internal.unwrapQueryRef(queryRef)["observable"])(queryRef);
var unwrapped = internal.unwrapQueryRef(queryRef);
return wrapHook("useReadQuery", _useReadQuery, unwrapped ?
unwrapped["observable"]
: useApolloClient())(queryRef);
}

@@ -1054,0 +1063,0 @@ function _useReadQuery(queryRef) {

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

import type { useQuery, useSuspenseQuery, useBackgroundQuery, useReadQuery, useFragment } from "../index.js";
import type { useQuery, useSuspenseQuery, useBackgroundQuery, useReadQuery, useFragment, useQueryRefHandlers } from "../index.js";
import type { ApolloClient } from "../../../core/ApolloClient.js";

@@ -10,2 +10,3 @@ import type { ObservableQuery } from "../../../core/ObservableQuery.js";

useFragment: typeof useFragment;
useQueryRefHandlers: typeof useQueryRefHandlers;
}

@@ -12,0 +13,0 @@ /**

import * as React from "rehackt";
import { getWrappedPromise, unwrapQueryRef, updateWrappedQueryRef, wrapQueryRef, } from "../internal/index.js";
import { useApolloClient } from "./useApolloClient.js";
import { wrapHook } from "./internal/index.js";
/**

@@ -23,2 +25,12 @@ * A React hook that returns a `refetch` and `fetchMore` function for a given

export function useQueryRefHandlers(queryRef) {
var unwrapped = unwrapQueryRef(queryRef);
return wrapHook("useQueryRefHandlers", _useQueryRefHandlers, unwrapped ?
unwrapped["observable"]
// in the case of a "transported" queryRef object, we need to use the
// client that's available to us at the current position in the React tree
// that ApolloClient will then have the job to recreate a real queryRef from
// the transported object
: useApolloClient())(queryRef);
}
function _useQueryRefHandlers(queryRef) {
var _a = React.useState(queryRef), previousQueryRef = _a[0], setPreviousQueryRef = _a[1];

@@ -25,0 +37,0 @@ var _b = React.useState(queryRef), wrappedQueryRef = _b[0], setWrappedQueryRef = _b[1];

@@ -6,4 +6,12 @@ import * as React from "rehackt";

import { useSyncExternalStore } from "./useSyncExternalStore.js";
import { useApolloClient } from "./useApolloClient.js";
export function useReadQuery(queryRef) {
return wrapHook("useReadQuery", _useReadQuery, unwrapQueryRef(queryRef)["observable"])(queryRef);
var unwrapped = unwrapQueryRef(queryRef);
return wrapHook("useReadQuery", _useReadQuery, unwrapped ?
unwrapped["observable"]
// in the case of a "transported" queryRef object, we need to use the
// client that's available to us at the current position in the React tree
// that ApolloClient will then have the job to recreate a real queryRef from
// the transported object
: useApolloClient())(queryRef);
}

@@ -10,0 +18,0 @@ function _useReadQuery(queryRef) {

@@ -98,12 +98,13 @@ import { __assign } from "tslib";

var originalFetchPolicy = this.watchQueryOptions.fetchPolicy;
var avoidNetworkRequests = originalFetchPolicy === "no-cache" || originalFetchPolicy === "standby";
try {
if (originalFetchPolicy !== "no-cache") {
if (avoidNetworkRequests) {
observable.silentSetOptions({ fetchPolicy: "standby" });
}
else {
observable.resetLastResults();
observable.silentSetOptions({ fetchPolicy: "cache-first" });
}
else {
observable.silentSetOptions({ fetchPolicy: "standby" });
}
this.subscribeToQuery();
if (originalFetchPolicy === "no-cache") {
if (avoidNetworkRequests) {
return;

@@ -110,0 +111,0 @@ }

@@ -85,12 +85,13 @@ 'use strict';

var originalFetchPolicy = this.watchQueryOptions.fetchPolicy;
var avoidNetworkRequests = originalFetchPolicy === "no-cache" || originalFetchPolicy === "standby";
try {
if (originalFetchPolicy !== "no-cache") {
if (avoidNetworkRequests) {
observable.silentSetOptions({ fetchPolicy: "standby" });
}
else {
observable.resetLastResults();
observable.silentSetOptions({ fetchPolicy: "cache-first" });
}
else {
observable.silentSetOptions({ fetchPolicy: "standby" });
}
this.subscribeToQuery();
if (originalFetchPolicy === "no-cache") {
if (avoidNetworkRequests) {
return;

@@ -97,0 +98,0 @@ }

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

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

@@ -302,101 +300,2 @@ function requestToKey(request, addTypename) {

var createProxiedSchema = function (schemaWithMocks, resolvers) {
var targetResolvers = tslib.__assign({}, resolvers);
var targetSchema = schema.addResolversToSchema({
schema: schemaWithMocks,
resolvers: targetResolvers,
});
var fns = {
add: function (_a) {
var newResolvers = _a.resolvers;
targetResolvers = tslib.__assign(tslib.__assign({}, targetResolvers), newResolvers);
targetSchema = schema.addResolversToSchema({
schema: targetSchema,
resolvers: targetResolvers,
});
return targetSchema;
},
fork: function (_a) {
var _b = _a === void 0 ? {} : _a, newResolvers = _b.resolvers;
return createProxiedSchema(targetSchema, newResolvers !== null && newResolvers !== void 0 ? newResolvers : targetResolvers);
},
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);
}
var property = Reflect.get(targetSchema, p);
if (typeof property === "function") {
return property.bind(targetSchema);
}
return property;
},
});
return schema$1;
};
function withCleanup(item, cleanup) {
var _a;
return tslib.__assign(tslib.__assign({}, item), (_a = {}, _a[Symbol.dispose] = function () {
cleanup(item);
if (Symbol.dispose in item) {
item[Symbol.dispose]();
}
}, _a));
}
var createMockFetch = function (schema, mockFetchOpts) {
if (mockFetchOpts === void 0) { mockFetchOpts = { validate: true }; }
var prevFetch = window.fetch;
var mockFetch = function (_uri, options) {
return new Promise(function (resolve) { return tslib.__awaiter(void 0, void 0, void 0, function () {
var body, document, validationErrors, result, stringifiedResult;
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0:
body = JSON.parse(options.body);
document = core$1.gql(body.query);
if (mockFetchOpts.validate) {
validationErrors = [];
try {
validationErrors = graphql.validate(schema, document);
}
catch (e) {
validationErrors = [
new core$1.ApolloError({ graphQLErrors: [e] }),
];
}
if ((validationErrors === null || validationErrors === void 0 ? void 0 : validationErrors.length) > 0) {
return [2 , resolve(new Response(JSON.stringify({ errors: validationErrors })))];
}
}
return [4 , graphql.execute({
schema: schema,
document: document,
variableValues: body.variables,
operationName: body.operationName,
})];
case 1:
result = _a.sent();
stringifiedResult = JSON.stringify(result);
resolve(new Response(stringifiedResult));
return [2 ];
}
});
}); });
};
window.fetch = mockFetch;
var restore = function () {
window.fetch = prevFetch;
};
return withCleanup({ mock: mockFetch, restore: restore }, restore);
};
function wrapTestFunction(fn, consoleMethodName) {

@@ -447,4 +346,2 @@ return function () {

exports.createMockClient = createMockClient;
exports.createMockFetch = createMockFetch;
exports.createProxiedSchema = createProxiedSchema;
exports.itAsync = itAsync;

@@ -451,0 +348,0 @@ exports.mockObservableLink = mockObservableLink;

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

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

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

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

@@ -5,3 +5,2 @@ 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,2 +40,5 @@ var _a, _b;

var rejectNextRender;
function resetNextRender() {
nextRender = resolveNextRender = rejectNextRender = undefined;
}
var snapshotRef = { current: initialSnapshot };

@@ -100,3 +103,3 @@ var replaceSnapshot = function (snap) {

finally {
nextRender = resolveNextRender = rejectNextRender = undefined;
resetNextRender();
}

@@ -208,3 +211,4 @@ };

return setTimeout(function () {
return reject(applyStackTrace(new WaitForRenderTimeoutError(), stackTrace));
reject(applyStackTrace(new WaitForRenderTimeoutError(), stackTrace));
resetNextRender();
}, timeout);

@@ -211,0 +215,0 @@ }),

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

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

@@ -64,134 +61,3 @@ 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) {

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

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

var version = "3.10.0-rc.0";
var version = "3.10.0-rc.1";

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

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

export var version = "3.10.0-rc.0";
export var version = "3.10.0-rc.1";
//# 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 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

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