@graphql-ez/client
Advanced tools
+20
-93
| /// <reference types="node" /> | ||
| /// <reference types="eventsource" /> | ||
| import type { TypedDocumentNode } from '@graphql-typed-document-node/core'; | ||
| import type { ExecutionResult } from 'graphql'; | ||
| import type { IncomingHttpHeaders } from 'http'; | ||
| import { Client, Dispatcher } from 'undici'; | ||
| import { Dispatcher, Pool } from 'undici'; | ||
| import { SubscribeSSE } from './sse'; | ||
| import { Stream } from './stream'; | ||
| import type { SubscribeFunction } from './types'; | ||
| import { GraphQLWSClientOptions } from './websockets/graphql-ws'; | ||
| import { SubscriptionsTransportClientOptions } from './websockets/subscriptions-transport'; | ||
| import { GraphQLWSClient, GraphQLWSClientOptions } from './websockets/graphql-ws'; | ||
| import { SubscriptionsTransportClient, SubscriptionsTransportClientOptions } from './websockets/subscriptions-transport'; | ||
| export interface EZClientOptions { | ||
@@ -15,5 +16,5 @@ endpoint: string | URL; | ||
| subscriptionsTransportClientOptions?: SubscriptionsTransportClientOptions; | ||
| unidiClientOptions?: Client.Options; | ||
| undiciOptions?: Pool.Options; | ||
| } | ||
| export interface QueryOptions<TVariables = {}> { | ||
| export interface QueryOptions<TVariables extends Record<string, any>> { | ||
| variables?: TVariables; | ||
@@ -32,6 +33,7 @@ headers?: IncomingHttpHeaders; | ||
| } | ||
| export declare type QueryFunctionPostGet = <TData, TVariables = {}, TExtensions = {}>(document: TypedDocumentNode<TData, TVariables> | string, options?: QueryOptions) => Promise<ExecutionResult<TData, TExtensions>>; | ||
| export declare type QueryFunctionPost = <TData, TVariables = {}, TExtensions = {}>(document: TypedDocumentNode<TData, TVariables> | string, options?: Omit<QueryOptions, 'method'>) => Promise<ExecutionResult<TData, TExtensions>>; | ||
| export declare type AssertedQuery = <TData = any, TVariables = {}>(document: TypedDocumentNode<TData, TVariables> | string, options?: QueryOptions) => Promise<TData>; | ||
| export declare function EZClient(options: EZClientOptions): { | ||
| export declare type QueryFunctionPostGet = <TData, TVariables extends Record<string, any> = {}, TExtensions = {}>(document: TypedDocumentNode<TData, TVariables> | string, options?: QueryOptions<TVariables>) => Promise<ExecutionResult<TData, TExtensions>>; | ||
| export declare type QueryFunctionPost = <TData, TVariables extends Record<string, any> = {}, TExtensions = {}>(document: TypedDocumentNode<TData, TVariables> | string, options?: Omit<QueryOptions<TVariables>, 'method'>) => Promise<ExecutionResult<TData, TExtensions>>; | ||
| export declare type AssertedQuery = <TData = any, TVariables extends Record<string, any> = Record<string, unknown>>(document: TypedDocumentNode<TData, TVariables> | string, options?: QueryOptions<TVariables>) => Promise<TData>; | ||
| export declare function EZClient(options: EZClientOptions): EZClientInstance; | ||
| export interface EZClientInstance { | ||
| query: QueryFunctionPostGet; | ||
@@ -42,89 +44,14 @@ mutation: QueryFunctionPost; | ||
| subscribe: SubscribeFunction<{}>; | ||
| client: Promise<import("graphql-ws").Client>; | ||
| client: Promise<GraphQLWSClient>; | ||
| legacy: { | ||
| subscribe: SubscribeFunction<{}>; | ||
| client: Promise<import("subscriptions-transport-ws-envelop/client").SubscriptionClient>; | ||
| client: Promise<SubscriptionsTransportClient>; | ||
| }; | ||
| }; | ||
| stream: <TData, TVariables extends Record<string, unknown> = {}>(document: string | TypedDocumentNode<TData, TVariables>, { variables, headers: headersArg, extensions, operationName, }?: { | ||
| variables?: TVariables | undefined; | ||
| headers?: IncomingHttpHeaders | undefined; | ||
| extensions?: Record<string, unknown> | undefined; | ||
| operationName?: string | undefined; | ||
| }) => { | ||
| iterator: AsyncGenerator<string, void, unknown>; | ||
| opaque: import("stream").PassThrough; | ||
| done: Promise<Dispatcher.StreamData>; | ||
| stop: () => void; | ||
| }; | ||
| sseSubscribe: SubscribeFunction<import("eventsource").EventSourceInitDict>; | ||
| client: Client; | ||
| headers: Partial<{ | ||
| [x: string]: any; | ||
| accept: string; | ||
| 'accept-language': string; | ||
| 'accept-patch': string; | ||
| 'accept-ranges': string; | ||
| 'access-control-allow-credentials': string; | ||
| 'access-control-allow-headers': string; | ||
| 'access-control-allow-methods': string; | ||
| 'access-control-allow-origin': string; | ||
| 'access-control-expose-headers': string; | ||
| 'access-control-max-age': string; | ||
| 'access-control-request-headers': string; | ||
| 'access-control-request-method': string; | ||
| age: string; | ||
| allow: string; | ||
| 'alt-svc': string; | ||
| authorization: string; | ||
| 'cache-control': string; | ||
| connection: string; | ||
| 'content-disposition': string; | ||
| 'content-encoding': string; | ||
| 'content-language': string; | ||
| 'content-length': string; | ||
| 'content-location': string; | ||
| 'content-range': string; | ||
| 'content-type': string; | ||
| cookie: string; | ||
| date: string; | ||
| etag: string; | ||
| expect: string; | ||
| expires: string; | ||
| forwarded: string; | ||
| from: string; | ||
| host: string; | ||
| 'if-match': string; | ||
| 'if-modified-since': string; | ||
| 'if-none-match': string; | ||
| 'if-unmodified-since': string; | ||
| 'last-modified': string; | ||
| location: string; | ||
| origin: string; | ||
| pragma: string; | ||
| 'proxy-authenticate': string; | ||
| 'proxy-authorization': string; | ||
| 'public-key-pins': string; | ||
| range: string; | ||
| referer: string; | ||
| 'retry-after': string; | ||
| 'sec-websocket-accept': string; | ||
| 'sec-websocket-extensions': string; | ||
| 'sec-websocket-key': string; | ||
| 'sec-websocket-protocol': string; | ||
| 'sec-websocket-version': string; | ||
| 'set-cookie': string[]; | ||
| 'strict-transport-security': string; | ||
| tk: string; | ||
| trailer: string; | ||
| 'transfer-encoding': string; | ||
| upgrade: string; | ||
| 'user-agent': string; | ||
| vary: string; | ||
| via: string; | ||
| warning: string; | ||
| 'www-authenticate': string; | ||
| }>; | ||
| setHeaders(headersToAssign: IncomingHttpHeaders): void; | ||
| stream: Stream; | ||
| sseSubscribe: SubscribeSSE; | ||
| client: Pool; | ||
| headers: Partial<IncomingHttpHeaders>; | ||
| setHeaders(headersToAssign: Partial<IncomingHttpHeaders>): void; | ||
| uploadQuery: QueryFunctionPost; | ||
| }; | ||
| } |
+4
-13
@@ -50,3 +50,3 @@ 'use strict'; | ||
| const endpointPathname = endpoint.pathname; | ||
| const client = new undici.Client(endpointOrigin, options.unidiClientOptions); | ||
| const client = new undici.Pool(endpointOrigin, __spreadValues({}, options.undiciOptions)); | ||
| const graphqlWS = graphqlWs.createGraphQLWSWebsocketsClient(websocketEndpoint, options.graphQLWSClientOptions); | ||
@@ -73,9 +73,3 @@ const legacyTransport = subscriptionsTransport.createSubscriptionsTransportWebsocketsClient(websocketEndpoint, options.subscriptionsTransportClientOptions); | ||
| if (!((_a = headers2["content-type"]) == null ? void 0 : _a.startsWith("application/json"))) { | ||
| const errorBody = await body.text().catch((err) => { | ||
| console.error(err); | ||
| }) || "No body"; | ||
| console.error({ | ||
| body: errorBody, | ||
| headers: headers2 | ||
| }); | ||
| const errorBody = await body.text().catch(() => null) || "No body"; | ||
| throw Error(`Unexpected content type received: ${headers2["content-type"]}, BodyText: ${errorBody}`); | ||
@@ -95,5 +89,2 @@ } | ||
| if (errors.length > 1) { | ||
| for (const err2 of errors) { | ||
| console.error(err2); | ||
| } | ||
| const err = Error("Multiple GraphQL Errors"); | ||
@@ -118,6 +109,6 @@ Object.assign(err, { errors }); | ||
| const subscribe = function subscribe2(document, options2) { | ||
| return graphqlWS.subscribe(document, __spreadProps(__spreadValues({}, options2), { headers: getHeaders(options2 == null ? void 0 : options2.headers) })); | ||
| return graphqlWS.subscribe(document, options2); | ||
| }; | ||
| const legacySubscribe = function subscribe2(document, options2) { | ||
| return legacyTransport.subscribe(document, __spreadProps(__spreadValues({}, options2), { headers: getHeaders(options2 == null ? void 0 : options2.headers) })); | ||
| return legacyTransport.subscribe(document, options2); | ||
| }; | ||
@@ -124,0 +115,0 @@ return { |
+5
-14
| import { documentParamsToURIParams } from '@graphql-ez/utils/clientURI'; | ||
| import { cleanObject } from '@graphql-ez/utils/object'; | ||
| import { getURLWebsocketVersion } from '@graphql-ez/utils/url'; | ||
| import { Client } from 'undici'; | ||
| import { Pool } from 'undici'; | ||
| import { createSSESubscription } from './sse.mjs'; | ||
@@ -46,3 +46,3 @@ import { createStreamHelper } from './stream.mjs'; | ||
| const endpointPathname = endpoint.pathname; | ||
| const client = new Client(endpointOrigin, options.unidiClientOptions); | ||
| const client = new Pool(endpointOrigin, __spreadValues({}, options.undiciOptions)); | ||
| const graphqlWS = createGraphQLWSWebsocketsClient(websocketEndpoint, options.graphQLWSClientOptions); | ||
@@ -69,9 +69,3 @@ const legacyTransport = createSubscriptionsTransportWebsocketsClient(websocketEndpoint, options.subscriptionsTransportClientOptions); | ||
| if (!((_a = headers2["content-type"]) == null ? void 0 : _a.startsWith("application/json"))) { | ||
| const errorBody = await body.text().catch((err) => { | ||
| console.error(err); | ||
| }) || "No body"; | ||
| console.error({ | ||
| body: errorBody, | ||
| headers: headers2 | ||
| }); | ||
| const errorBody = await body.text().catch(() => null) || "No body"; | ||
| throw Error(`Unexpected content type received: ${headers2["content-type"]}, BodyText: ${errorBody}`); | ||
@@ -91,5 +85,2 @@ } | ||
| if (errors.length > 1) { | ||
| for (const err2 of errors) { | ||
| console.error(err2); | ||
| } | ||
| const err = Error("Multiple GraphQL Errors"); | ||
@@ -114,6 +105,6 @@ Object.assign(err, { errors }); | ||
| const subscribe = function subscribe2(document, options2) { | ||
| return graphqlWS.subscribe(document, __spreadProps(__spreadValues({}, options2), { headers: getHeaders(options2 == null ? void 0 : options2.headers) })); | ||
| return graphqlWS.subscribe(document, options2); | ||
| }; | ||
| const legacySubscribe = function subscribe2(document, options2) { | ||
| return legacyTransport.subscribe(document, __spreadProps(__spreadValues({}, options2), { headers: getHeaders(options2 == null ? void 0 : options2.headers) })); | ||
| return legacyTransport.subscribe(document, options2); | ||
| }; | ||
@@ -120,0 +111,0 @@ return { |
+1
-1
| { | ||
| "name": "@graphql-ez/client", | ||
| "version": "0.5.0", | ||
| "version": "0.6.0", | ||
| "sideEffects": false, | ||
@@ -5,0 +5,0 @@ "peerDependencies": { |
+5
-2
@@ -0,6 +1,9 @@ | ||
| /// <reference types="eventsource" /> | ||
| /// <reference types="node" /> | ||
| /// <reference types="eventsource" /> | ||
| import type { IncomingHttpHeaders } from 'http'; | ||
| import type { EventSourceInitDict } from './deps.js'; | ||
| import type { SubscribeFunction } from './types'; | ||
| export declare function createSSESubscription(href: string, getHeaders: (headers: IncomingHttpHeaders | undefined) => IncomingHttpHeaders): SubscribeFunction<EventSourceInitDict>; | ||
| export declare type SubscribeSSE = SubscribeFunction<EventSourceInitDict & { | ||
| headers?: Partial<IncomingHttpHeaders>; | ||
| }>; | ||
| export declare function createSSESubscription(href: string, getHeaders: (headers: IncomingHttpHeaders | undefined) => IncomingHttpHeaders): SubscribeSSE; |
+8
-7
@@ -5,13 +5,14 @@ /// <reference types="node" /> | ||
| import { PassThrough } from 'stream'; | ||
| import type { Client } from 'undici'; | ||
| export declare function createStreamHelper(client: Client, path: string, getHeaders: (headers: IncomingHttpHeaders | undefined) => IncomingHttpHeaders): <TData, TVariables extends Record<string, unknown> = {}>(document: string | TypedDocumentNode<TData, TVariables>, { variables, headers: headersArg, extensions, operationName, }?: { | ||
| variables?: TVariables | undefined; | ||
| headers?: IncomingHttpHeaders | undefined; | ||
| extensions?: Record<string, unknown> | undefined; | ||
| operationName?: string | undefined; | ||
| import type { Pool, Dispatcher } from 'undici'; | ||
| export declare type Stream = <TData, TVariables extends Record<string, unknown> = {}>(document: TypedDocumentNode<TData, TVariables> | string, options?: { | ||
| variables?: TVariables; | ||
| headers?: IncomingHttpHeaders; | ||
| extensions?: Record<string, unknown>; | ||
| operationName?: string; | ||
| }) => { | ||
| iterator: AsyncGenerator<string, void, unknown>; | ||
| opaque: PassThrough; | ||
| done: Promise<import("undici/types/dispatcher").StreamData>; | ||
| done: Promise<Dispatcher.StreamData>; | ||
| stop: () => void; | ||
| }; | ||
| export declare function createStreamHelper(pool: Pool, path: string, getHeaders: (headers: IncomingHttpHeaders | undefined) => IncomingHttpHeaders): Stream; |
+2
-2
@@ -26,3 +26,3 @@ 'use strict'; | ||
| }; | ||
| function createStreamHelper(client, path, getHeaders) { | ||
| function createStreamHelper(pool, path, getHeaders) { | ||
| return function stream$1(document, { | ||
@@ -50,3 +50,3 @@ variables, | ||
| }; | ||
| const done = client.stream({ | ||
| const done = pool.stream({ | ||
| path, | ||
@@ -53,0 +53,0 @@ method: "POST", |
+2
-2
@@ -22,3 +22,3 @@ import { createDeferredPromise } from '@graphql-ez/utils/promise'; | ||
| }; | ||
| function createStreamHelper(client, path, getHeaders) { | ||
| function createStreamHelper(pool, path, getHeaders) { | ||
| return function stream(document, { | ||
@@ -46,3 +46,3 @@ variables, | ||
| }; | ||
| const done = client.stream({ | ||
| const done = pool.stream({ | ||
| path, | ||
@@ -49,0 +49,0 @@ method: "POST", |
+0
-3
@@ -1,5 +0,3 @@ | ||
| /// <reference types="node" /> | ||
| import type { ExecutionResult } from 'graphql'; | ||
| import type { TypedDocumentNode } from '@graphql-typed-document-node/core'; | ||
| import type { IncomingHttpHeaders } from 'http'; | ||
| export declare type SubscribeOptions<TResult, TVariables extends Record<string, unknown>, TExtensions extends Record<string, unknown> = Record<string, unknown>, TExtra extends {} = {}> = { | ||
@@ -10,3 +8,2 @@ onData?: (data: ExecutionResult<TResult>) => void; | ||
| extensions?: TExtensions | null; | ||
| headers?: IncomingHttpHeaders; | ||
| } & Partial<TExtra>; | ||
@@ -13,0 +10,0 @@ export interface SubscribeFunction<TExtra extends Record<string, any> = {}> { |
| import type { GraphQLWSClient, GraphQLWSClientOptions } from '../deps.js'; | ||
| import type { SubscribeFunction } from '../types'; | ||
| export type { GraphQLWSClientOptions }; | ||
| export type { GraphQLWSClientOptions, GraphQLWSClient }; | ||
| export declare function createGraphQLWSWebsocketsClient(wsEndpoint: string, options?: Partial<GraphQLWSClientOptions>): { | ||
@@ -5,0 +5,0 @@ subscribe: SubscribeFunction<{}>; |
@@ -1,7 +0,7 @@ | ||
| import type { SubscriptionsTransportClientOptions } from '../deps.js'; | ||
| import type { SubscriptionsTransportClientOptions, SubscriptionsTransportClient } from '../deps.js'; | ||
| import type { SubscribeFunction } from '../types'; | ||
| export type { SubscriptionsTransportClientOptions }; | ||
| export type { SubscriptionsTransportClientOptions, SubscriptionsTransportClient }; | ||
| export declare function createSubscriptionsTransportWebsocketsClient(wsEndpoint: string, options?: SubscriptionsTransportClientOptions): { | ||
| client: Promise<import("subscriptions-transport-ws-envelop/client").SubscriptionClient>; | ||
| client: Promise<SubscriptionsTransportClient>; | ||
| subscribe: SubscribeFunction<{}>; | ||
| }; |
Network access
Supply chain riskThis module accesses the network.
Found 5 instances in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 5 instances in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
585078
-0.57%3299
-2.68%