Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gqty

Package Overview
Dependencies
Maintainers
1
Versions
318
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gqty - npm Package Compare versions

Comparing version 3.0.0-alpha-a9dd30c6.0 to 3.0.0-alpha-aa51f1c1.0

4

Accessor/index.d.ts

@@ -8,3 +8,3 @@ import type { BaseGeneratedSchema, SchemaContext } from '../Client';

*/
export declare const setCache: <TData extends GeneratedSchemaObject<Record<string, any>>>(accessor: TData, data: Partial<TData>) => void;
export declare const setCache: <TData extends GeneratedSchemaObject>(accessor: TData, data: Partial<TData>) => void;
/**

@@ -16,2 +16,2 @@ * Use another accessor like a fragment, this function takes all children from

*/
export declare const assignSelections: <TData extends GeneratedSchemaObject<Record<string, any>>>(source: TData | null, target: TData | null) => void;
export declare const assignSelections: <TData extends GeneratedSchemaObject>(source: TData | null, target: TData | null) => void;

@@ -9,5 +9,5 @@ import type { CacheNode } from '../Cache';

*/
export declare const resolve: (accessor: GeneratedSchemaObject, selection: Selection, __type: Type['__type']) => string | number | boolean | CacheNode[] | GeneratedSchemaObject<Record<string, any>> | {
export declare const resolve: (accessor: GeneratedSchemaObject, selection: Selection, __type: Type['__type']) => string | number | boolean | CacheNode[] | GeneratedSchemaObject | {
[k: string]: boolean;
} | GeneratedSchemaObject<Record<string, any>>[] | null | undefined;
} | GeneratedSchemaObject[] | null | undefined;
export declare const createUnionAccessor: ({ context, cache, possibleTypes, selection, }: Omit<Meta, "type"> & {

@@ -21,5 +21,5 @@ possibleTypes: readonly string[];

};
export declare const createObjectAccessor: <TSchemaType extends GeneratedSchemaObject<Record<string, any>>>(meta: Meta) => GeneratedSchemaObject<Record<string, any>>;
export declare const createObjectAccessor: <TSchemaType extends GeneratedSchemaObject>(meta: Meta) => GeneratedSchemaObject;
/** Recursively replace proxy accessors with its actual cached value. */
export declare const deepMetadata: (input: any) => any;
export declare const createArrayAccessor: <TSchemaType extends GeneratedSchemaObject<Record<string, any>>[]>(meta: Meta) => TSchemaType;
export declare const createArrayAccessor: <TSchemaType extends GeneratedSchemaObject[]>(meta: Meta) => TSchemaType;

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

import { Client } from 'graphql-ws';
import type { Client } from 'graphql-ws';
import type { Promisable } from 'type-fest';

@@ -3,0 +3,0 @@ import { GQtyError } from '../../Error';

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

const graphqlWs = require('graphql-ws');
const index = require('../../Error/index.js');

@@ -29,3 +28,3 @@

dispatchEvent("message", {
type: graphqlWs.MessageType.ConnectionAck
type: "connection_ack"
});

@@ -60,3 +59,3 @@ },

id: operationId,
type: graphqlWs.MessageType.Subscribe,
type: "subscribe",
payload

@@ -70,3 +69,3 @@ });

id: sub.operationId,
type: graphqlWs.MessageType.Subscribe,
type: "subscribe",
payload

@@ -73,0 +72,0 @@ });

@@ -1,3 +0,3 @@

import type { Client as SseClient } from 'graphql-sse';
import type { Client as WsClient } from 'graphql-ws';
import { type Client as SseClient } from 'graphql-sse';
import { type Client as WsClient } from 'graphql-ws';
import { Cache } from '../Cache';

@@ -4,0 +4,0 @@ import { Persistors } from '../Cache/persistence';

@@ -1,9 +0,9 @@

import type { BaseGeneratedSchema, FetchOptions } from '.';
import type { Cache } from '../Cache';
import type { GQtyError, RetryOptions } from '../Error';
import type { ScalarsEnumsHash, Schema } from '../Schema';
import type { Selection } from '../Selection';
import { SchemaContext } from './context';
import type { Debugger } from './debugger';
import { Unsubscribe } from './resolveSelections';
import { type BaseGeneratedSchema, type FetchOptions } from '.';
import { type Cache } from '../Cache';
import { type GQtyError, type RetryOptions } from '../Error';
import { type ScalarsEnumsHash, type Schema } from '../Schema';
import { type Selection } from '../Selection';
import { type SchemaContext } from './context';
import { type Debugger } from './debugger';
import { type Unsubscribe } from './resolveSelections';
export type CreateResolversOptions = {

@@ -69,12 +69,4 @@ cache: Cache;

export type DataResult<TData = unknown> = TData extends undefined ? TData : TData extends void ? unknown : TData;
export type ResolveOptions = {
export type CreateResolverOptions = {
/**
* Awaits resolution it the query results in a fetch. Specify `false` to
* immediately return the current cache, placeholder data will be returned on
* a partial or complete cache miss.
*
* @default true
*/
awaitsFetch?: boolean;
/**
* Defines how a query should fetch from the cache and network.

@@ -89,5 +81,3 @@ *

* GQty creates a temporary cache at query-level which immediately expires.
* - `reload`: Always fetch, updates on response.
* - `no-cache`: Same as `reload`, for GraphQL does not support conditional
* requests.
* - `no-cache`: Always fetch, updates on response.
* - `force-cache`: Serves the cached contents regardless of staleness. It

@@ -103,30 +93,20 @@ * fetches on cache miss or a stale cache, updates cache on response.

cachePolicy?: RequestCache;
/** Custom GraphQL extensions to be exposed to the query fetcher. */
extensions?: Record<string, unknown>;
retryPolicy?: RetryOptions;
onFetch?: (fetchPromise: Promise<unknown>) => void;
onSelect?: SchemaContext['select'];
operationName?: string;
};
export type SubscribeOptions = {
export type ResolveOptions = CreateResolverOptions & {
/**
* Defines how a query should fetch from the cache and network.
* Awaits resolution it the query results in a fetch. Specify `false` to
* immediately return the current cache, placeholder data will be returned on
* a partial or complete cache miss.
*
* - `default`: Serves the cached contents when it is fresh, and if they are
* stale within `staleWhileRevalidate` window, fetches in the background and
* updates the cache. Or simply fetches on cache stale or cache miss. During
* SWR, a successful fetch will not notify cache updates. New contents are
* served on next query.
* - `no-store`: Always fetch and does not update on response.
* GQty creates a temporary cache at query-level which immediately expires.
* - `no-cache`: Always fetch, updates on response.
* - `force-cache`: Serves the cached contents regardless of staleness. It
* fetches on cache miss or a stale cache, updates cache on response.
* - `only-if-cached`: Serves the cached contents regardless of staleness,
* throws a network error on cache miss.
*
* _It takes effort to make sure the above stays true for all supported
* frameworks, please consider sponsoring so we can dedicate even more time on
* this._
* @default true
*/
cachePolicy?: RequestCache;
retryPolicy?: RetryOptions;
awaitsFetch?: boolean;
onFetch?: (fetchPromise: Promise<unknown>) => void;
};
export type SubscribeOptions = CreateResolverOptions & {
/**

@@ -141,3 +121,2 @@ * Intercept errors thrown from the underlying subscription client or query

onError?: (error: unknown) => void;
onSelect?: SchemaContext['select'];
/**

@@ -149,4 +128,3 @@ * Called when a subscription is established, receives an unsubscribe

onSubscribe?: (unsubscribe: Unsubscribe) => void;
operationName?: string;
};
export declare const createResolvers: <TSchema extends BaseGeneratedSchema>({ cache: clientCache, debugger: debug, depthLimit, fetchOptions, fetchOptions: { cachePolicy: defaultCachePolicy, retryPolicy: defaultRetryPoliy, }, scalars, schema, parentContext, }: CreateResolversOptions) => Resolvers<TSchema>;

@@ -29,2 +29,3 @@ 'use strict';

cachePolicy = defaultCachePolicy,
extensions,
onSelect,

@@ -52,2 +53,10 @@ onSubscribe,

const resolve = async () => {
if (selections.size === 0) {
if (process.env.NODE_ENV !== "production") {
console.warn(
"[GQty] No selections found. If you are reading from the global accessors, try using the first argument instead."
);
}
return;
}
if (!context$1.shouldFetch)

@@ -67,29 +76,28 @@ return;

pendingSelections,
new Promise((resolve2, reject) => {
queueMicrotask(() => {
var _a;
const selections2 = new Set(
[
...(_a = batching.getSelectionsSet(clientCache, selectionsCacheKey)) != null ? _a : []
].flatMap((selections3) => [...selections3])
Promise.resolve().then(() => {
var _a;
const selections2 = new Set(
[
...(_a = batching.getSelectionsSet(clientCache, selectionsCacheKey)) != null ? _a : []
].flatMap((selections3) => [...selections3])
);
pendingQueries.delete(pendingSelections);
batching.delSelectionsSet(clientCache, selectionsCacheKey);
return resolveSelections.fetchSelections(selections2, {
cache: context$1.cache,
debugger: debug,
extensions,
fetchOptions: {
...fetchOptions,
cachePolicy,
retryPolicy
},
operationName
}).then((results) => {
updateCaches.updateCaches(
results,
cachePolicy !== "no-store" && context$1.cache !== clientCache ? [context$1.cache, clientCache] : [context$1.cache],
{ skipNotify: !context$1.notifyCacheUpdate }
);
pendingQueries.delete(pendingSelections);
batching.delSelectionsSet(clientCache, selectionsCacheKey);
resolveSelections.fetchSelections(selections2, {
cache: context$1.cache,
debugger: debug,
fetchOptions: {
...fetchOptions,
cachePolicy,
retryPolicy
},
operationName
}).then((results) => {
updateCaches.updateCaches(
results,
cachePolicy !== "no-store" && context$1.cache !== clientCache ? [context$1.cache, clientCache] : [context$1.cache],
{ skipNotify: !context$1.notifyCacheUpdate }
);
return results;
}).then(resolve2, reject);
return results;
});

@@ -106,2 +114,11 @@ })

} = {}) => {
if (selections.size === 0) {
if (process.env.NODE_ENV !== "production") {
console.warn(
"[GQty] No selections found. If you are reading from the global accessors, try using the first argument instead."
);
}
return () => {
};
}
const unsubscibers = /* @__PURE__ */ new Set();

@@ -129,3 +146,5 @@ const unsubscribe = () => {

}
promises.push(resolve());
if (selections.size > 0) {
promises.push(resolve());
}
}

@@ -139,3 +158,3 @@ for (const selection of subscriptionSelections) {

subscriptionSelections,
({ data, error, extensions }) => {
({ data, error, extensions: extensions2 }) => {
if (error) {

@@ -146,3 +165,3 @@ onError == null ? void 0 : onError(error);

updateCaches.updateCaches(
[{ data, error, extensions }],
[{ data, error, extensions: extensions2 }],
cachePolicy !== "no-store" && context$1.cache !== clientCache ? [context$1.cache, clientCache] : [context$1.cache],

@@ -156,2 +175,3 @@ { skipNotify: !context$1.notifyCacheUpdate }

debugger: debug,
extensions,
fetchOptions: {

@@ -158,0 +178,0 @@ ...fetchOptions,

@@ -1,11 +0,13 @@

import type { ExecutionResult } from 'graphql';
import { CloseEvent } from 'ws';
import type { FetchOptions } from '.';
import type { Cache } from '../Cache';
import { type ExecutionResult } from 'graphql';
import { type Constructor } from 'type-fest';
import { type CloseEvent, type WebSocket } from 'ws';
import { type FetchOptions } from '.';
import { type Cache } from '../Cache';
import { GQtyError } from '../Error';
import type { Selection } from '../Selection';
import type { Debugger } from './debugger';
import { type Selection } from '../Selection';
import { type Debugger } from './debugger';
export type FetchSelectionsOptions = {
cache?: Cache;
debugger?: Debugger;
extensions?: Record<string, unknown>;
fetchOptions: FetchOptions;

@@ -21,3 +23,3 @@ operationName?: string;

};
export declare const fetchSelections: <TData extends Record<string, unknown> = Record<string, unknown>>(selections: Set<Selection>, { cache, debugger: debug, fetchOptions, operationName, }: FetchSelectionsOptions) => Promise<FetchResult<TData>[]>;
export declare const fetchSelections: <TData extends Record<string, unknown> = Record<string, unknown>>(selections: Set<Selection>, { cache, debugger: debug, extensions: customExtensions, fetchOptions, operationName, }: FetchSelectionsOptions) => Promise<FetchResult<TData>[]>;
export type SubscribeSelectionOptions = FetchSelectionsOptions & {

@@ -29,3 +31,3 @@ onComplete?: () => void;

export type Unsubscribe = () => void;
export declare const subscribeSelections: <TData extends Record<string, unknown> = Record<string, unknown>>(selections: Set<Selection>, fn: SubscriptionCallback<TData>, { cache, debugger: debug, fetchOptions: { subscriber }, operationName, onSubscribe, onComplete, }: SubscribeSelectionOptions) => Unsubscribe;
export declare const isCloseEvent: (input: unknown) => input is CloseEvent;
export declare const subscribeSelections: <TData extends Record<string, unknown> = Record<string, unknown>>(selections: Set<Selection>, fn: SubscriptionCallback<TData>, { cache, debugger: debug, extensions: customExtensions, fetchOptions: { subscriber }, operationName, onSubscribe, onComplete, }: SubscribeSelectionOptions) => Unsubscribe;
export declare const isCloseEvent: (input: unknown, wsImpl: Constructor<WebSocket>) => input is CloseEvent;

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

const graphqlWs = require('graphql-ws');
const ws = require('ws');
const query = require('../Cache/query.js');

@@ -14,5 +12,24 @@ const index$1 = require('../Error/index.js');

function _interopNamespace(e) {
if (e && e.__esModule) return e;
const n = Object.create(null);
if (e) {
for (const k in e) {
if (k !== 'default') {
const d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
}
}
n["default"] = e;
return Object.freeze(n);
}
const fetchSelections = (selections, {
cache,
debugger: debug,
extensions: customExtensions,
fetchOptions,

@@ -36,3 +53,3 @@ operationName

operationName: operationName2,
extensions: { type, hash }
extensions: { ...customExtensions, type, hash }
};

@@ -65,2 +82,3 @@ const { data, errors, extensions } = await query.dedupePromise(

debugger: debug,
extensions: customExtensions,
fetchOptions: { subscriber },

@@ -74,3 +92,3 @@ operationName,

index.buildQuery(selections, operationName).map(
({
async ({
query: query$1,

@@ -92,3 +110,3 @@ variables,

operationName: operationName2,
extensions: { type, hash }
extensions: { ...customExtensions, type, hash }
};

@@ -100,3 +118,3 @@ let subscriptionId;

switch (message.type) {
case graphqlWs.MessageType.ConnectionAck: {
case "connection_ack": {
unsub == null ? void 0 : unsub();

@@ -113,6 +131,6 @@ onSubscribe == null ? void 0 : onSubscribe();

switch (message.type) {
case graphqlWs.MessageType.ConnectionAck: {
case "connection_ack": {
break;
}
case graphqlWs.MessageType.Subscribe: {
case "subscribe": {
if (((_a = message.payload.extensions) == null ? void 0 : _a.hash) !== hash)

@@ -171,2 +189,3 @@ return;

let dispose;
const ws = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('ws')); });
const promise = query.dedupePromise(cache, hash, () => {

@@ -181,3 +200,3 @@ return new Promise((complete) => {

error(index$1.GQtyError.fromGraphQLErrors(err));
} else if (!isCloseEvent(err)) {
} else if (!isCloseEvent(err, ws.WebSocket)) {
error(index$1.GQtyError.create(err));

@@ -261,2 +280,3 @@ }

}
const ws = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('ws')); });
return new Promise(

@@ -277,3 +297,3 @@ (resolve, reject) => {

error(error) {
if (isCloseEvent(error)) {
if (isCloseEvent(error, ws.WebSocket)) {
resolve(result);

@@ -297,5 +317,5 @@ } else if (Array.isArray(error)) {

};
const isCloseEvent = (input) => {
const isCloseEvent = (input, wsImpl) => {
const error = input;
return error.type === "close" && error.target instanceof ws.WebSocket || typeof error.code === "number" && [
return error.type === "close" && error.target instanceof wsImpl || typeof error.code === "number" && [
4004,

@@ -302,0 +322,0 @@ 4005,

{
"name": "gqty",
"version": "3.0.0-alpha-a9dd30c6.0",
"version": "3.0.0-alpha-aa51f1c1.0",
"description": "gqty client without queries",

@@ -5,0 +5,0 @@ "sideEffects": false,

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc