@graphql-ez/client
Advanced tools
| export { default as EventSource, EventSourceInitDict } from 'eventsource'; | ||
| export { default as ws } from 'ws'; | ||
| export { default as nodeFetch } from 'node-fetch'; | ||
| export { extractFiles } from 'extract-files'; | ||
| export { default as FormData } from 'form-data'; | ||
| export { ClientOptions as SubscriptionsTransportClientOptions, SubscriptionClient as SubscriptionsTransportClient, } from 'subscriptions-transport-ws-envelop/client'; | ||
| export { Client as GraphQLWSClient, ClientOptions as GraphQLWSClientOptions, createClient as createGraphQLWSClient, } from 'graphql-ws'; |
Sorry, the diff of this file is too big to display
+125
| # @graphql-ez/client | ||
| Fully feature GraphQL Client for Node.js | ||
| ## Features | ||
| - [x] [@graphql-typed-document-node](https://www.npmjs.com/package/@graphql-typed-document-node/core) support | ||
| - [x] High performance HTTP/s using [undici](https://github.com/nodejs/undici) | ||
| - [x] [graphql-ws](https://github.com/enisdenjo/graphql-ws) support | ||
| - [x] Legacy [subscriptions-transport-ws](https://github.com/apollographql/subscriptions-transport-ws) support | ||
| - [x] [Defer and Stream](https://github.com/graphql/graphql-js/pull/2319) support | ||
| - [x] [graphql-helix](https://github.com/contra/graphql-helix) SSE support | ||
| - [x] [GraphQL Upload](https://github.com/jaydenseric/graphql-upload) support | ||
| > By default if you only use the traditional GraphQL over HTTP, any other external dependency is not imported | ||
| ## Usage | ||
| ```ts | ||
| import { EZClient } from '@graphql-ez/client'; | ||
| export const ezClient = EZClient({ | ||
| endpoint: 'http://localhost:8080/api/graphql', | ||
| }); | ||
| ``` | ||
| ### HTTP | ||
| ```ts | ||
| await ezClient.query('query($n: Int!) { hello(n: $n) }', { | ||
| variables: { | ||
| n: 10, | ||
| }, | ||
| // "POST" by default | ||
| method: 'GET', | ||
| }); | ||
| await ezClient.mutation('mutation { hello }', { | ||
| headers: { | ||
| authorization: 'foo', | ||
| }, | ||
| }); | ||
| // Automatically throw if any error is returned | ||
| await ezClient.assertedQuery('mutation { hello }', { | ||
| // ... | ||
| }); | ||
| ``` | ||
| ### Websockets | ||
| #### graphql-ws | ||
| ```ts | ||
| const { iterator, unsubscribe } = ezClient.websockets.subscribe('subscription{ping}'); | ||
| for await (const value of iterator) { | ||
| console.log(value); | ||
| } | ||
| await unsubscribe(); | ||
| (await ezClient.websockets.client).dispose(); | ||
| ``` | ||
| #### Legacy subscriptions-transport-ws | ||
| ```ts | ||
| const { iterator, unsubscribe } = ezClient.websockets.legacy.subscribe('subscription{ping}'); | ||
| for await (const value of iterator) { | ||
| console.log(value); | ||
| } | ||
| await unsubscribe(); | ||
| (await ezClient.websockets.legacy.client).close(); | ||
| ``` | ||
| ### Defer and Stream | ||
| ```ts | ||
| const { iterator } = ezClient.stream('{stream @stream(initialCount: 1)}'); | ||
| let i = 0; | ||
| for await (const value of iterator) { | ||
| switch (++i) { | ||
| case 1: | ||
| expect(value).toContain(`{"data":{"stream":["A"]},"hasNext":true}`); | ||
| break; | ||
| case 2: | ||
| expect(value).toContain(`{"data":"B","path":["stream",1],"hasNext":true}`); | ||
| break; | ||
| case 3: | ||
| expect(value).toContain(`{"data":"C","path":["stream",2],"hasNext":true}`); | ||
| break; | ||
| } | ||
| } | ||
| ``` | ||
| ### SSE | ||
| ```ts | ||
| const { iterator, unsubscribe } = ezClient.sseSubscribe('subscription{ping}'); | ||
| for await (const value of iterator) { | ||
| console.log(value); | ||
| } | ||
| await unsubscribe(); | ||
| ``` | ||
| ### GraphQL Upload | ||
| ```ts | ||
| const { data, errors } = await ezClient.uploadQuery('mutation($file: Upload!) { uploadFile(file:$file) }', { | ||
| variables: { | ||
| file: Buffer.from('hello-world'), | ||
| }, | ||
| }); | ||
| ``` | ||
| ## LICENSE | ||
| MIT |
| export declare const lazyDeps: Promise<typeof import("./deps.js")>; |
+9
| 'use strict'; | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| const promise = require('@graphql-ez/utils/promise'); | ||
| const lazyDeps = promise.LazyPromise(() => Promise.resolve().then(function () { return require('./deps.js'); })); | ||
| exports.lazyDeps = lazyDeps; |
| import { LazyPromise } from '@graphql-ez/utils/promise'; | ||
| const lazyDeps = LazyPromise(() => import('./deps.js')); | ||
| export { lazyDeps }; |
+10
-18
@@ -7,7 +7,7 @@ /// <reference types="node" /> | ||
| import { Client } from 'undici'; | ||
| import type { SubscribeOptions } from './types'; | ||
| import type { GraphQLWSClientOptions } from './websockets/graphql-ws'; | ||
| import type { SubscriptionsTransportClientOptions } from './websockets/subscriptions-transport'; | ||
| import type { SubscribeFunction } from './types'; | ||
| import { GraphQLWSClientOptions } from './websockets/graphql-ws'; | ||
| import { SubscriptionsTransportClientOptions } from './websockets/subscriptions-transport'; | ||
| export interface EZClientOptions { | ||
| endpoint: string; | ||
| endpoint: string | URL; | ||
| headers?: IncomingHttpHeaders; | ||
@@ -48,19 +48,11 @@ graphQLWSClientOptions?: Partial<GraphQLWSClientOptions>; | ||
| websockets: { | ||
| subscribe<TData, TVariables extends Record<string, unknown> = {}>(document: string | TypedDocumentNode<TData, TVariables>, options?: SubscribeOptions<TData, TVariables, Record<string, unknown>, {}> | undefined): Promise<{ | ||
| done: Promise<void>; | ||
| unsubscribe: () => void; | ||
| iterator: AsyncGenerator<ExecutionResult<TData, import("graphql/jsutils/ObjMap").ObjMap<unknown>>, void, unknown>; | ||
| }>; | ||
| subscribe: SubscribeFunction<{}>; | ||
| client: Promise<import("graphql-ws").Client>; | ||
| legacy: { | ||
| subscribe<TData_1, TVariables_1 extends Record<string, unknown> = {}>(document: string | TypedDocumentNode<TData_1, TVariables_1>, options?: SubscribeOptions<TData_1, TVariables_1, Record<string, unknown>, {}> | undefined): Promise<{ | ||
| done: Promise<void>; | ||
| unsubscribe: () => void; | ||
| iterator: AsyncGenerator<ExecutionResult<TData_1, import("graphql/jsutils/ObjMap").ObjMap<unknown>>, void, unknown>; | ||
| }>; | ||
| client: Promise<import("subscriptions-transport-ws-envelop").SubscriptionClient>; | ||
| subscribe: SubscribeFunction<{}>; | ||
| client: Promise<import("subscriptions-transport-ws-envelop/client").SubscriptionClient>; | ||
| }; | ||
| }; | ||
| stream: <TData_2, TVariables_2 extends Record<string, unknown> = {}>(document: string | TypedDocumentNode<TData_2, TVariables_2>, { variables, headers: headersArg, extensions, operationName, }?: { | ||
| variables?: TVariables_2 | undefined; | ||
| stream: <TData, TVariables extends Record<string, unknown> = {}>(document: string | TypedDocumentNode<TData, TVariables>, { variables, headers: headersArg, extensions, operationName, }?: { | ||
| variables?: TVariables | undefined; | ||
| headers?: IncomingHttpHeaders | undefined; | ||
@@ -75,3 +67,3 @@ extensions?: Record<string, unknown> | undefined; | ||
| }; | ||
| sseSubscribe: import("./types").SubscribeFunction<import("eventsource").EventSourceInitDict>; | ||
| sseSubscribe: SubscribeFunction<import("eventsource").EventSourceInitDict>; | ||
| client: Client; | ||
@@ -78,0 +70,0 @@ headers: Partial<{ |
+41
-32
@@ -7,3 +7,2 @@ 'use strict'; | ||
| const object = require('@graphql-ez/utils/object'); | ||
| const promise = require('@graphql-ez/utils/promise'); | ||
| const url = require('@graphql-ez/utils/url'); | ||
@@ -15,3 +14,24 @@ const graphql = require('graphql'); | ||
| const upload = require('./upload.js'); | ||
| const graphqlWs = require('./websockets/graphql-ws.js'); | ||
| const subscriptionsTransport = require('./websockets/subscriptions-transport.js'); | ||
| var __defProp = Object.defineProperty; | ||
| var __defProps = Object.defineProperties; | ||
| var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| return a; | ||
| }; | ||
| var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
| class GraphQLErrorJSON extends Error { | ||
@@ -26,3 +46,3 @@ constructor(message, locations, extensions) { | ||
| const endpoint = new URL(options.endpoint); | ||
| const websocketEndpoint = url.getURLWebsocketVersion(options.endpoint).href; | ||
| const websocketEndpoint = url.getURLWebsocketVersion(typeof options.endpoint === "string" ? options.endpoint : options.endpoint.href).href; | ||
| const endpointHref = endpoint.href; | ||
@@ -32,16 +52,7 @@ const endpointOrigin = endpoint.origin; | ||
| const client = new undici.Client(endpointOrigin); | ||
| const graphqlWS = promise.LazyPromise(async () => { | ||
| const { createGraphQLWSWebsocketsClient } = await Promise.resolve().then(function () { return require('./websockets/graphql-ws.js'); }); | ||
| return createGraphQLWSWebsocketsClient(websocketEndpoint, options.graphQLWSClientOptions); | ||
| }); | ||
| const legacyTransport = promise.LazyPromise(async () => { | ||
| const { createSubscriptionsTransportWebsocketsClient } = await Promise.resolve().then(function () { return require('./websockets/subscriptions-transport.js'); }); | ||
| return createSubscriptionsTransportWebsocketsClient(websocketEndpoint, options.subscriptionsTransportClientOptions); | ||
| }); | ||
| const graphqlWS = graphqlWs.createGraphQLWSWebsocketsClient(websocketEndpoint, options.graphQLWSClientOptions); | ||
| const legacyTransport = subscriptionsTransport.createSubscriptionsTransportWebsocketsClient(websocketEndpoint, options.subscriptionsTransportClientOptions); | ||
| const headers = object.cleanObject(options.headers); | ||
| function getHeaders(headersArg) { | ||
| return object.cleanObject({ | ||
| ...headers, | ||
| ...headersArg | ||
| }); | ||
| return object.cleanObject(__spreadValues(__spreadValues({}, headers), headersArg)); | ||
| } | ||
@@ -57,6 +68,5 @@ const query = async function query2(document, { variables, headers: headersArg, method = "POST", extensions, operationName } = {}) { | ||
| method: "POST", | ||
| headers: { | ||
| "content-type": "application/json", | ||
| ...getHeaders(headersArg) | ||
| }, | ||
| headers: __spreadValues({ | ||
| "content-type": "application/json" | ||
| }, getHeaders(headersArg)), | ||
| body: JSON.stringify({ query: queryString, variables }), | ||
@@ -80,6 +90,5 @@ path: endpointPathname | ||
| method: "POST", | ||
| headers: { | ||
| "content-type": "application/json", | ||
| ...getHeaders(headersArg) | ||
| }, | ||
| headers: __spreadValues({ | ||
| "content-type": "application/json" | ||
| }, getHeaders(headersArg)), | ||
| body: JSON.stringify({ query: queryString, variables, operationName, extensions }), | ||
@@ -125,2 +134,8 @@ path: endpointPathname | ||
| }; | ||
| const subscribe = function subscribe2(document, options2) { | ||
| return graphqlWS.subscribe(document, __spreadProps(__spreadValues({}, options2), { headers: getHeaders(options2 == null ? void 0 : options2.headers) })); | ||
| }; | ||
| const legacySubscribe = function subscribe2(document, options2) { | ||
| return legacyTransport.subscribe(document, __spreadProps(__spreadValues({}, options2), { headers: getHeaders(options2 == null ? void 0 : options2.headers) })); | ||
| }; | ||
| return { | ||
@@ -131,13 +146,7 @@ query, | ||
| websockets: { | ||
| async subscribe(document, options2) { | ||
| const { subscribe } = await graphqlWS; | ||
| return subscribe(document, { ...options2, headers: getHeaders(options2 == null ? void 0 : options2.headers) }); | ||
| }, | ||
| client: promise.LazyPromise(() => graphqlWS.then((v) => v.client)), | ||
| subscribe, | ||
| client: graphqlWS.client, | ||
| legacy: { | ||
| async subscribe(document, options2) { | ||
| const { subscribe } = await legacyTransport; | ||
| return subscribe(document, { ...options2, headers: getHeaders(options2 == null ? void 0 : options2.headers) }); | ||
| }, | ||
| client: promise.LazyPromise(() => legacyTransport.then((v) => v.client)) | ||
| subscribe: legacySubscribe, | ||
| client: legacyTransport.client | ||
| } | ||
@@ -144,0 +153,0 @@ }, |
+41
-32
| import { documentParamsToURIParams } from '@graphql-ez/utils/clientURI'; | ||
| import { cleanObject } from '@graphql-ez/utils/object'; | ||
| import { LazyPromise } from '@graphql-ez/utils/promise'; | ||
| import { getURLWebsocketVersion } from '@graphql-ez/utils/url'; | ||
@@ -10,3 +9,24 @@ import { print } from 'graphql'; | ||
| import { createUploadQuery } from './upload.mjs'; | ||
| import { createGraphQLWSWebsocketsClient } from './websockets/graphql-ws.mjs'; | ||
| import { createSubscriptionsTransportWebsocketsClient } from './websockets/subscriptions-transport.mjs'; | ||
| var __defProp = Object.defineProperty; | ||
| var __defProps = Object.defineProperties; | ||
| var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| return a; | ||
| }; | ||
| var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
| class GraphQLErrorJSON extends Error { | ||
@@ -21,3 +41,3 @@ constructor(message, locations, extensions) { | ||
| const endpoint = new URL(options.endpoint); | ||
| const websocketEndpoint = getURLWebsocketVersion(options.endpoint).href; | ||
| const websocketEndpoint = getURLWebsocketVersion(typeof options.endpoint === "string" ? options.endpoint : options.endpoint.href).href; | ||
| const endpointHref = endpoint.href; | ||
@@ -27,16 +47,7 @@ const endpointOrigin = endpoint.origin; | ||
| const client = new Client(endpointOrigin); | ||
| const graphqlWS = LazyPromise(async () => { | ||
| const { createGraphQLWSWebsocketsClient } = await import('./websockets/graphql-ws.mjs'); | ||
| return createGraphQLWSWebsocketsClient(websocketEndpoint, options.graphQLWSClientOptions); | ||
| }); | ||
| const legacyTransport = LazyPromise(async () => { | ||
| const { createSubscriptionsTransportWebsocketsClient } = await import('./websockets/subscriptions-transport.mjs'); | ||
| return createSubscriptionsTransportWebsocketsClient(websocketEndpoint, options.subscriptionsTransportClientOptions); | ||
| }); | ||
| const graphqlWS = createGraphQLWSWebsocketsClient(websocketEndpoint, options.graphQLWSClientOptions); | ||
| const legacyTransport = createSubscriptionsTransportWebsocketsClient(websocketEndpoint, options.subscriptionsTransportClientOptions); | ||
| const headers = cleanObject(options.headers); | ||
| function getHeaders(headersArg) { | ||
| return cleanObject({ | ||
| ...headers, | ||
| ...headersArg | ||
| }); | ||
| return cleanObject(__spreadValues(__spreadValues({}, headers), headersArg)); | ||
| } | ||
@@ -52,6 +63,5 @@ const query = async function query2(document, { variables, headers: headersArg, method = "POST", extensions, operationName } = {}) { | ||
| method: "POST", | ||
| headers: { | ||
| "content-type": "application/json", | ||
| ...getHeaders(headersArg) | ||
| }, | ||
| headers: __spreadValues({ | ||
| "content-type": "application/json" | ||
| }, getHeaders(headersArg)), | ||
| body: JSON.stringify({ query: queryString, variables }), | ||
@@ -75,6 +85,5 @@ path: endpointPathname | ||
| method: "POST", | ||
| headers: { | ||
| "content-type": "application/json", | ||
| ...getHeaders(headersArg) | ||
| }, | ||
| headers: __spreadValues({ | ||
| "content-type": "application/json" | ||
| }, getHeaders(headersArg)), | ||
| body: JSON.stringify({ query: queryString, variables, operationName, extensions }), | ||
@@ -120,2 +129,8 @@ path: endpointPathname | ||
| }; | ||
| const subscribe = function subscribe2(document, options2) { | ||
| return graphqlWS.subscribe(document, __spreadProps(__spreadValues({}, options2), { headers: getHeaders(options2 == null ? void 0 : options2.headers) })); | ||
| }; | ||
| const legacySubscribe = function subscribe2(document, options2) { | ||
| return legacyTransport.subscribe(document, __spreadProps(__spreadValues({}, options2), { headers: getHeaders(options2 == null ? void 0 : options2.headers) })); | ||
| }; | ||
| return { | ||
@@ -126,13 +141,7 @@ query, | ||
| websockets: { | ||
| async subscribe(document, options2) { | ||
| const { subscribe } = await graphqlWS; | ||
| return subscribe(document, { ...options2, headers: getHeaders(options2 == null ? void 0 : options2.headers) }); | ||
| }, | ||
| client: LazyPromise(() => graphqlWS.then((v) => v.client)), | ||
| subscribe, | ||
| client: graphqlWS.client, | ||
| legacy: { | ||
| async subscribe(document, options2) { | ||
| const { subscribe } = await legacyTransport; | ||
| return subscribe(document, { ...options2, headers: getHeaders(options2 == null ? void 0 : options2.headers) }); | ||
| }, | ||
| client: LazyPromise(() => legacyTransport.then((v) => v.client)) | ||
| subscribe: legacySubscribe, | ||
| client: legacyTransport.client | ||
| } | ||
@@ -139,0 +148,0 @@ }, |
+2
-2
@@ -1,2 +0,2 @@ | ||
| MIT License Copyright (c) 2021 Pablo Sáez | ||
| MIT License Copyright (c) 2022 Pablo Sáez | ||
@@ -21,2 +21,2 @@ Permission is hereby granted, free of | ||
| FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| THE SOFTWARE. | ||
| THE SOFTWARE. |
+11
-14
| { | ||
| "name": "@graphql-ez/client", | ||
| "version": "0.3.1", | ||
| "version": "0.4.0", | ||
| "sideEffects": false, | ||
| "peerDependencies": { | ||
| "@graphql-typed-document-node/core": "*", | ||
| "@types/node": "*", | ||
| "graphql": "*" | ||
| }, | ||
| "peerDependenciesMeta": { | ||
| "@graphql-typed-document-node/core": { | ||
| "optional": true | ||
| } | ||
| }, | ||
| "dependencies": { | ||
| "@graphql-ez/utils": "^0.1.3", | ||
| "@graphql-tools/utils": "^8.6.0", | ||
| "@types/eventsource": "^1.1.8", | ||
| "eventsource": "^1.1.0", | ||
| "extract-files": "^11.0.0", | ||
| "form-data": "^4.0.0", | ||
| "graphql-ws": "^5.5.5", | ||
| "isomorphic-ws": "^4.0.1", | ||
| "node-fetch": "^2.6.6", | ||
| "subscriptions-transport-ws-envelop": "^2.0.2", | ||
| "undici": "^4.12.1", | ||
| "ws": "^8.4.0" | ||
| "@graphql-ez/utils": "^0.1.4", | ||
| "undici": "^4.12.2" | ||
| }, | ||
@@ -44,3 +40,4 @@ "repository": { | ||
| "./package.json": "./package.json" | ||
| } | ||
| }, | ||
| "readme": "# @graphql-ez/client\n\nFully feature GraphQL Client for Node.js\n\n## Features\n\n- [x] [@graphql-typed-document-node](https://www.npmjs.com/package/@graphql-typed-document-node/core) support\n- [x] High performance HTTP/s using [undici](https://github.com/nodejs/undici)\n- [x] [graphql-ws](https://github.com/enisdenjo/graphql-ws) support\n- [x] Legacy [subscriptions-transport-ws](https://github.com/apollographql/subscriptions-transport-ws) support\n- [x] [Defer and Stream](https://github.com/graphql/graphql-js/pull/2319) support\n- [x] [graphql-helix](https://github.com/contra/graphql-helix) SSE support\n- [x] [GraphQL Upload](https://github.com/jaydenseric/graphql-upload) support\n\n> By default if you only use the traditional GraphQL over HTTP, any other external dependency is not imported\n\n## Usage\n\n```ts\nimport { EZClient } from '@graphql-ez/client';\n\nexport const ezClient = EZClient({\n endpoint: 'http://localhost:8080/api/graphql',\n});\n```\n\n### HTTP\n\n```ts\nawait ezClient.query('query($n: Int!) { hello(n: $n) }', {\n variables: {\n n: 10,\n },\n // \"POST\" by default\n method: 'GET',\n});\n\nawait ezClient.mutation('mutation { hello }', {\n headers: {\n authorization: 'foo',\n },\n});\n\n// Automatically throw if any error is returned\nawait ezClient.assertedQuery('mutation { hello }', {\n // ...\n});\n```\n\n### Websockets\n\n#### graphql-ws\n\n```ts\nconst { iterator, unsubscribe } = ezClient.websockets.subscribe('subscription{ping}');\n\nfor await (const value of iterator) {\n console.log(value);\n}\n\nawait unsubscribe();\n\n(await ezClient.websockets.client).dispose();\n```\n\n#### Legacy subscriptions-transport-ws\n\n```ts\nconst { iterator, unsubscribe } = ezClient.websockets.legacy.subscribe('subscription{ping}');\n\nfor await (const value of iterator) {\n console.log(value);\n}\n\nawait unsubscribe();\n\n(await ezClient.websockets.legacy.client).close();\n```\n\n### Defer and Stream\n\n```ts\nconst { iterator } = ezClient.stream('{stream @stream(initialCount: 1)}');\n\nlet i = 0;\nfor await (const value of iterator) {\n switch (++i) {\n case 1:\n expect(value).toContain(`{\"data\":{\"stream\":[\"A\"]},\"hasNext\":true}`);\n break;\n case 2:\n expect(value).toContain(`{\"data\":\"B\",\"path\":[\"stream\",1],\"hasNext\":true}`);\n break;\n case 3:\n expect(value).toContain(`{\"data\":\"C\",\"path\":[\"stream\",2],\"hasNext\":true}`);\n break;\n }\n}\n```\n\n### SSE\n\n```ts\nconst { iterator, unsubscribe } = ezClient.sseSubscribe('subscription{ping}');\n\nfor await (const value of iterator) {\n console.log(value);\n}\n\nawait unsubscribe();\n```\n\n### GraphQL Upload\n\n```ts\nconst { data, errors } = await ezClient.uploadQuery('mutation($file: Upload!) { uploadFile(file:$file) }', {\n variables: {\n file: Buffer.from('hello-world'),\n },\n});\n```\n\n## LICENSE\n\nMIT\n" | ||
| } |
+4
-3
| /// <reference types="node" /> | ||
| import EventSource from 'eventsource'; | ||
| /// <reference types="eventsource" /> | ||
| import type { IncomingHttpHeaders } from 'http'; | ||
| import type { EventSourceInitDict } from './deps.js'; | ||
| import type { SubscribeFunction } from './types'; | ||
| import type { IncomingHttpHeaders } from 'http'; | ||
| export declare function createSSESubscription(href: string, getHeaders: (headers: IncomingHttpHeaders | undefined) => IncomingHttpHeaders): SubscribeFunction<EventSource.EventSourceInitDict>; | ||
| export declare function createSSESubscription(href: string, getHeaders: (headers: IncomingHttpHeaders | undefined) => IncomingHttpHeaders): SubscribeFunction<EventSourceInitDict>; |
+72
-32
@@ -5,37 +5,75 @@ 'use strict'; | ||
| const EventSource = require('eventsource'); | ||
| const promise = require('@graphql-ez/utils/promise'); | ||
| const graphql = require('graphql'); | ||
| const promise = require('@graphql-ez/utils/promise'); | ||
| const utils = require('./utils.js'); | ||
| function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; } | ||
| const EventSource__default = /*#__PURE__*/_interopDefault(EventSource); | ||
| var __defProp = Object.defineProperty; | ||
| var __defProps = Object.defineProperties; | ||
| var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| return a; | ||
| }; | ||
| var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
| var __objRest = (source, exclude) => { | ||
| var target = {}; | ||
| for (var prop in source) | ||
| if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) | ||
| target[prop] = source[prop]; | ||
| if (source != null && __getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(source)) { | ||
| if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) | ||
| target[prop] = source[prop]; | ||
| } | ||
| return target; | ||
| }; | ||
| function createSSESubscription(href, getHeaders) { | ||
| const subscribe = function subscribe2(document, { | ||
| variables, | ||
| extensions, | ||
| operationName, | ||
| onData, | ||
| headers, | ||
| ...rest | ||
| } = {}) { | ||
| const subscribe = function subscribe2(document, _a = {}) { | ||
| var _b = _a, { | ||
| variables, | ||
| extensions, | ||
| operationName, | ||
| onData, | ||
| headers | ||
| } = _b, rest = __objRest(_b, [ | ||
| "variables", | ||
| "extensions", | ||
| "operationName", | ||
| "onData", | ||
| "headers" | ||
| ]); | ||
| const queryString = typeof document === "string" ? document : graphql.print(document); | ||
| const eventSource = new EventSource__default["default"](`${href}?query=${encodeURIComponent(graphql.stripIgnoredCharacters(queryString))}${variables ? "&variables=" + encodeURIComponent(JSON.stringify(variables)) : ""}${extensions ? "&extensions=" + encodeURIComponent(JSON.stringify(extensions)) : ""}${operationName ? "&operationName=" + encodeURIComponent(operationName) : ""}`, { | ||
| ...rest, | ||
| headers: getHeaders(headers) | ||
| }); | ||
| let deferValuePromise = promise.createDeferredPromise(); | ||
| const done = new Promise((resolve, reject) => { | ||
| eventSource.onerror = (evt) => { | ||
| console.error(evt); | ||
| reject(evt.data); | ||
| }; | ||
| eventSource.onmessage = (evt) => { | ||
| const value = JSON.parse(evt.data); | ||
| onData == null ? void 0 : onData(value); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(value); | ||
| deferValuePromise = promise.createDeferredPromise(); | ||
| resolve(); | ||
| }; | ||
| let eventSource; | ||
| const done = new Promise(async (resolve, reject) => { | ||
| const { EventSource } = await utils.lazyDeps; | ||
| eventSource = new EventSource(`${href}?query=${encodeURIComponent(graphql.stripIgnoredCharacters(queryString))}${variables ? "&variables=" + encodeURIComponent(JSON.stringify(variables)) : ""}${extensions ? "&extensions=" + encodeURIComponent(JSON.stringify(extensions)) : ""}${operationName ? "&operationName=" + encodeURIComponent(operationName) : ""}`, __spreadProps(__spreadValues({}, rest), { | ||
| headers: getHeaders(headers) | ||
| })); | ||
| try { | ||
| eventSource.onerror = (evt) => { | ||
| console.error(evt); | ||
| reject(evt.data); | ||
| }; | ||
| eventSource.onmessage = (evt) => { | ||
| const value = JSON.parse(evt.data); | ||
| onData == null ? void 0 : onData(value); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(value); | ||
| deferValuePromise = promise.createDeferredPromise(); | ||
| resolve(); | ||
| }; | ||
| } catch (err) { | ||
| reject(err); | ||
| } | ||
| }); | ||
@@ -52,4 +90,6 @@ async function* iteratorGenerator() { | ||
| return { | ||
| unsubscribe() { | ||
| eventSource.close(); | ||
| async unsubscribe() { | ||
| if (!eventSource) | ||
| await done; | ||
| eventSource == null ? void 0 : eventSource.close(); | ||
| }, | ||
@@ -56,0 +96,0 @@ done, |
+72
-28
@@ -1,32 +0,74 @@ | ||
| import EventSource from 'eventsource'; | ||
| import { createDeferredPromise } from '@graphql-ez/utils/promise'; | ||
| import { print, stripIgnoredCharacters } from 'graphql'; | ||
| import { createDeferredPromise } from '@graphql-ez/utils/promise'; | ||
| import { lazyDeps } from './utils.mjs'; | ||
| var __defProp = Object.defineProperty; | ||
| var __defProps = Object.defineProperties; | ||
| var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| return a; | ||
| }; | ||
| var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
| var __objRest = (source, exclude) => { | ||
| var target = {}; | ||
| for (var prop in source) | ||
| if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) | ||
| target[prop] = source[prop]; | ||
| if (source != null && __getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(source)) { | ||
| if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) | ||
| target[prop] = source[prop]; | ||
| } | ||
| return target; | ||
| }; | ||
| function createSSESubscription(href, getHeaders) { | ||
| const subscribe = function subscribe2(document, { | ||
| variables, | ||
| extensions, | ||
| operationName, | ||
| onData, | ||
| headers, | ||
| ...rest | ||
| } = {}) { | ||
| const subscribe = function subscribe2(document, _a = {}) { | ||
| var _b = _a, { | ||
| variables, | ||
| extensions, | ||
| operationName, | ||
| onData, | ||
| headers | ||
| } = _b, rest = __objRest(_b, [ | ||
| "variables", | ||
| "extensions", | ||
| "operationName", | ||
| "onData", | ||
| "headers" | ||
| ]); | ||
| const queryString = typeof document === "string" ? document : print(document); | ||
| const eventSource = new EventSource(`${href}?query=${encodeURIComponent(stripIgnoredCharacters(queryString))}${variables ? "&variables=" + encodeURIComponent(JSON.stringify(variables)) : ""}${extensions ? "&extensions=" + encodeURIComponent(JSON.stringify(extensions)) : ""}${operationName ? "&operationName=" + encodeURIComponent(operationName) : ""}`, { | ||
| ...rest, | ||
| headers: getHeaders(headers) | ||
| }); | ||
| let deferValuePromise = createDeferredPromise(); | ||
| const done = new Promise((resolve, reject) => { | ||
| eventSource.onerror = (evt) => { | ||
| console.error(evt); | ||
| reject(evt.data); | ||
| }; | ||
| eventSource.onmessage = (evt) => { | ||
| const value = JSON.parse(evt.data); | ||
| onData == null ? void 0 : onData(value); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(value); | ||
| deferValuePromise = createDeferredPromise(); | ||
| resolve(); | ||
| }; | ||
| let eventSource; | ||
| const done = new Promise(async (resolve, reject) => { | ||
| const { EventSource } = await lazyDeps; | ||
| eventSource = new EventSource(`${href}?query=${encodeURIComponent(stripIgnoredCharacters(queryString))}${variables ? "&variables=" + encodeURIComponent(JSON.stringify(variables)) : ""}${extensions ? "&extensions=" + encodeURIComponent(JSON.stringify(extensions)) : ""}${operationName ? "&operationName=" + encodeURIComponent(operationName) : ""}`, __spreadProps(__spreadValues({}, rest), { | ||
| headers: getHeaders(headers) | ||
| })); | ||
| try { | ||
| eventSource.onerror = (evt) => { | ||
| console.error(evt); | ||
| reject(evt.data); | ||
| }; | ||
| eventSource.onmessage = (evt) => { | ||
| const value = JSON.parse(evt.data); | ||
| onData == null ? void 0 : onData(value); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(value); | ||
| deferValuePromise = createDeferredPromise(); | ||
| resolve(); | ||
| }; | ||
| } catch (err) { | ||
| reject(err); | ||
| } | ||
| }); | ||
@@ -43,4 +85,6 @@ async function* iteratorGenerator() { | ||
| return { | ||
| unsubscribe() { | ||
| eventSource.close(); | ||
| async unsubscribe() { | ||
| if (!eventSource) | ||
| await done; | ||
| eventSource == null ? void 0 : eventSource.close(); | ||
| }, | ||
@@ -47,0 +91,0 @@ done, |
+2
-2
| /// <reference types="node" /> | ||
| import type { TypedDocumentNode } from '@graphql-typed-document-node/core'; | ||
| import type { IncomingHttpHeaders } from 'http'; | ||
| import { PassThrough } from 'stream'; | ||
| import type { Client } from 'undici'; | ||
| import type { TypedDocumentNode } from '@graphql-typed-document-node/core'; | ||
| import type { IncomingHttpHeaders } from 'http'; | ||
| 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, }?: { | ||
@@ -7,0 +7,0 @@ variables?: TVariables | undefined; |
+22
-11
@@ -5,11 +5,23 @@ 'use strict'; | ||
| const promise = require('@graphql-ez/utils/promise'); | ||
| const assert = require('assert'); | ||
| const graphql = require('graphql'); | ||
| const stream = require('stream'); | ||
| const promise = require('@graphql-ez/utils/promise'); | ||
| function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; } | ||
| const assert__default = /*#__PURE__*/_interopDefault(assert); | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| return a; | ||
| }; | ||
| function createStreamHelper(client, path, getHeaders) { | ||
@@ -43,9 +55,8 @@ return function stream$1(document, { | ||
| body: JSON.stringify({ query: queryString, variables, extensions, operationName }), | ||
| headers: { | ||
| "content-type": "application/json", | ||
| ...getHeaders(headersArg) | ||
| }, | ||
| headers: __spreadValues({ | ||
| "content-type": "application/json" | ||
| }, getHeaders(headersArg)), | ||
| opaque | ||
| }, ({ opaque: opaque2 }) => { | ||
| assert__default["default"](opaque2 instanceof stream.PassThrough); | ||
| assert["default"](opaque2 instanceof stream.PassThrough); | ||
| (async () => { | ||
@@ -66,3 +77,3 @@ try { | ||
| }); | ||
| assert__default["default"](opaque instanceof stream.PassThrough); | ||
| assert["default"](opaque instanceof stream.PassThrough); | ||
| return { | ||
@@ -69,0 +80,0 @@ iterator, |
+20
-5
@@ -0,6 +1,22 @@ | ||
| import { createDeferredPromise } from '@graphql-ez/utils/promise'; | ||
| import assert from 'assert'; | ||
| import { print } from 'graphql'; | ||
| import { PassThrough } from 'stream'; | ||
| import { createDeferredPromise } from '@graphql-ez/utils/promise'; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| return a; | ||
| }; | ||
| function createStreamHelper(client, path, getHeaders) { | ||
@@ -34,6 +50,5 @@ return function stream(document, { | ||
| body: JSON.stringify({ query: queryString, variables, extensions, operationName }), | ||
| headers: { | ||
| "content-type": "application/json", | ||
| ...getHeaders(headersArg) | ||
| }, | ||
| headers: __spreadValues({ | ||
| "content-type": "application/json" | ||
| }, getHeaders(headersArg)), | ||
| opaque | ||
@@ -40,0 +55,0 @@ }, ({ opaque: opaque2 }) => { |
+1
-1
@@ -17,5 +17,5 @@ /// <reference types="node" /> | ||
| done: Promise<void>; | ||
| unsubscribe: () => void; | ||
| unsubscribe: () => Promise<void>; | ||
| iterator: AsyncGenerator<ExecutionResult<TResult>, void>; | ||
| }; | ||
| } |
+23
-34
@@ -5,39 +5,28 @@ 'use strict'; | ||
| const utils = require('@graphql-ez/utils'); | ||
| const fs = require('fs'); | ||
| const graphql = require('graphql'); | ||
| const utils = require('./utils.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]; } | ||
| }); | ||
| } | ||
| var __defProp = Object.defineProperty; | ||
| var __defProps = Object.defineProperties; | ||
| var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| } | ||
| n["default"] = e; | ||
| return Object.freeze(n); | ||
| } | ||
| return a; | ||
| }; | ||
| var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
| function createUploadQuery(endpoint, getHeaders, defaultQuery) { | ||
| const deps = utils.LazyPromise(async () => { | ||
| const [{ default: fetch }, { extractFiles }, { default: FormData }] = await Promise.all([ | ||
| Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('node-fetch')); }), | ||
| Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('extract-files')); }), | ||
| Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('form-data')); }) | ||
| ]); | ||
| return { | ||
| fetch, | ||
| extractFiles, | ||
| FormData | ||
| }; | ||
| }); | ||
| return async function(document, { variables, headers: headersArg, extensions, operationName } = {}) { | ||
| const { FormData, extractFiles, fetch } = await deps; | ||
| const { extractFiles, FormData, nodeFetch } = await utils.lazyDeps; | ||
| const queryString = typeof document === "string" ? document : graphql.print(document); | ||
@@ -54,3 +43,3 @@ const mainBody = { | ||
| const form = new FormData(); | ||
| form.append("operations", JSON.stringify({ ...extracted.clone, extensions })); | ||
| form.append("operations", JSON.stringify(__spreadProps(__spreadValues({}, extracted.clone), { extensions }))); | ||
| const map = {}; | ||
@@ -66,5 +55,5 @@ let i = 0; | ||
| }); | ||
| const response = await fetch(endpoint, { | ||
| const response = await nodeFetch(endpoint, { | ||
| method: "POST", | ||
| headers: { ...getHeaders(headersArg), ...form.getHeaders() }, | ||
| headers: __spreadValues(__spreadValues({}, getHeaders(headersArg)), form.getHeaders()), | ||
| body: form | ||
@@ -71,0 +60,0 @@ }); |
+24
-17
@@ -1,20 +0,27 @@ | ||
| import { LazyPromise } from '@graphql-ez/utils'; | ||
| import { ReadStream } from 'fs'; | ||
| import { print } from 'graphql'; | ||
| import { lazyDeps } from './utils.mjs'; | ||
| var __defProp = Object.defineProperty; | ||
| var __defProps = Object.defineProperties; | ||
| var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| return a; | ||
| }; | ||
| var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
| function createUploadQuery(endpoint, getHeaders, defaultQuery) { | ||
| const deps = LazyPromise(async () => { | ||
| const [{ default: fetch }, { extractFiles }, { default: FormData }] = await Promise.all([ | ||
| import('node-fetch'), | ||
| import('extract-files'), | ||
| import('form-data') | ||
| ]); | ||
| return { | ||
| fetch, | ||
| extractFiles, | ||
| FormData | ||
| }; | ||
| }); | ||
| return async function(document, { variables, headers: headersArg, extensions, operationName } = {}) { | ||
| const { FormData, extractFiles, fetch } = await deps; | ||
| const { extractFiles, FormData, nodeFetch } = await lazyDeps; | ||
| const queryString = typeof document === "string" ? document : print(document); | ||
@@ -31,3 +38,3 @@ const mainBody = { | ||
| const form = new FormData(); | ||
| form.append("operations", JSON.stringify({ ...extracted.clone, extensions })); | ||
| form.append("operations", JSON.stringify(__spreadProps(__spreadValues({}, extracted.clone), { extensions }))); | ||
| const map = {}; | ||
@@ -43,5 +50,5 @@ let i = 0; | ||
| }); | ||
| const response = await fetch(endpoint, { | ||
| const response = await nodeFetch(endpoint, { | ||
| method: "POST", | ||
| headers: { ...getHeaders(headersArg), ...form.getHeaders() }, | ||
| headers: __spreadValues(__spreadValues({}, getHeaders(headersArg)), form.getHeaders()), | ||
| body: form | ||
@@ -48,0 +55,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
| import { Client as GraphQLWSClient, ClientOptions as GraphQLWSClientOptions } from 'graphql-ws'; | ||
| import type { GraphQLWSClient, GraphQLWSClientOptions } from '../deps.js'; | ||
| import type { SubscribeFunction } from '../types'; | ||
@@ -6,3 +6,3 @@ export type { GraphQLWSClientOptions }; | ||
| subscribe: SubscribeFunction<{}>; | ||
| client: GraphQLWSClient; | ||
| client: Promise<GraphQLWSClient>; | ||
| }; |
+58
-37
@@ -5,21 +5,38 @@ 'use strict'; | ||
| const document = require('@graphql-ez/utils/document'); | ||
| const promise = require('@graphql-ez/utils/promise'); | ||
| const graphql = require('graphql'); | ||
| const graphqlWs = require('graphql-ws'); | ||
| const ws = require('isomorphic-ws'); | ||
| const promise = require('@graphql-ez/utils/promise'); | ||
| const utils = require('@graphql-tools/utils'); | ||
| const utils = require('../utils.js'); | ||
| function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; } | ||
| const ws__default = /*#__PURE__*/_interopDefault(ws); | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| return a; | ||
| }; | ||
| function createGraphQLWSWebsocketsClient(wsEndpoint, options = {}) { | ||
| const client = graphqlWs.createClient({ | ||
| url: wsEndpoint, | ||
| webSocketImpl: ws__default["default"], | ||
| lazy: true, | ||
| ...options | ||
| const client = promise.LazyPromise(async () => { | ||
| const { ws, createGraphQLWSClient } = await utils.lazyDeps; | ||
| return createGraphQLWSClient(__spreadValues({ | ||
| url: wsEndpoint, | ||
| webSocketImpl: ws, | ||
| lazy: true | ||
| }, options)); | ||
| }); | ||
| const subscribe = function subscribe2(query, { onData, variables, operationName, extensions } = {}) { | ||
| let unsubscribe = () => { | ||
| let unsubscribeFn; | ||
| const unsubscribe = async () => { | ||
| if (!unsubscribeFn) | ||
| await done; | ||
| unsubscribeFn == null ? void 0 : unsubscribeFn(); | ||
| }; | ||
@@ -36,25 +53,29 @@ let deferValuePromise = promise.createDeferredPromise(); | ||
| const iterator = iteratorGenerator(); | ||
| const done = new Promise((resolve, reject) => { | ||
| unsubscribe = client.subscribe({ | ||
| query: utils.isDocumentNode(query) ? graphql.print(query) : query, | ||
| variables, | ||
| operationName, | ||
| extensions | ||
| }, { | ||
| next(value) { | ||
| onData == null ? void 0 : onData(value); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(value); | ||
| deferValuePromise = promise.createDeferredPromise(); | ||
| }, | ||
| error(err) { | ||
| reject(err); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.reject(err); | ||
| deferValuePromise = null; | ||
| }, | ||
| complete() { | ||
| resolve(); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(null); | ||
| deferValuePromise = null; | ||
| } | ||
| }); | ||
| const done = new Promise(async (resolve, reject) => { | ||
| try { | ||
| unsubscribeFn = (await client).subscribe({ | ||
| query: document.isDocumentNode(query) ? graphql.print(query) : query, | ||
| variables, | ||
| operationName, | ||
| extensions | ||
| }, { | ||
| next(value) { | ||
| onData == null ? void 0 : onData(value); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(value); | ||
| deferValuePromise = promise.createDeferredPromise(); | ||
| }, | ||
| error(err) { | ||
| reject(err); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.reject(err); | ||
| deferValuePromise = null; | ||
| }, | ||
| complete() { | ||
| resolve(); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(null); | ||
| deferValuePromise = null; | ||
| } | ||
| }); | ||
| } catch (err) { | ||
| reject(err); | ||
| } | ||
| }); | ||
@@ -61,0 +82,0 @@ return { |
@@ -0,16 +1,37 @@ | ||
| import { isDocumentNode } from '@graphql-ez/utils/document'; | ||
| import { LazyPromise, createDeferredPromise } from '@graphql-ez/utils/promise'; | ||
| import { print } from 'graphql'; | ||
| import { createClient } from 'graphql-ws'; | ||
| import ws from 'isomorphic-ws'; | ||
| import { createDeferredPromise } from '@graphql-ez/utils/promise'; | ||
| import { isDocumentNode } from '@graphql-tools/utils'; | ||
| import { lazyDeps } from '../utils.mjs'; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| return a; | ||
| }; | ||
| function createGraphQLWSWebsocketsClient(wsEndpoint, options = {}) { | ||
| const client = createClient({ | ||
| url: wsEndpoint, | ||
| webSocketImpl: ws, | ||
| lazy: true, | ||
| ...options | ||
| const client = LazyPromise(async () => { | ||
| const { ws, createGraphQLWSClient } = await lazyDeps; | ||
| return createGraphQLWSClient(__spreadValues({ | ||
| url: wsEndpoint, | ||
| webSocketImpl: ws, | ||
| lazy: true | ||
| }, options)); | ||
| }); | ||
| const subscribe = function subscribe2(query, { onData, variables, operationName, extensions } = {}) { | ||
| let unsubscribe = () => { | ||
| let unsubscribeFn; | ||
| const unsubscribe = async () => { | ||
| if (!unsubscribeFn) | ||
| await done; | ||
| unsubscribeFn == null ? void 0 : unsubscribeFn(); | ||
| }; | ||
@@ -27,25 +48,29 @@ let deferValuePromise = createDeferredPromise(); | ||
| const iterator = iteratorGenerator(); | ||
| const done = new Promise((resolve, reject) => { | ||
| unsubscribe = client.subscribe({ | ||
| query: isDocumentNode(query) ? print(query) : query, | ||
| variables, | ||
| operationName, | ||
| extensions | ||
| }, { | ||
| next(value) { | ||
| onData == null ? void 0 : onData(value); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(value); | ||
| deferValuePromise = createDeferredPromise(); | ||
| }, | ||
| error(err) { | ||
| reject(err); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.reject(err); | ||
| deferValuePromise = null; | ||
| }, | ||
| complete() { | ||
| resolve(); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(null); | ||
| deferValuePromise = null; | ||
| } | ||
| }); | ||
| const done = new Promise(async (resolve, reject) => { | ||
| try { | ||
| unsubscribeFn = (await client).subscribe({ | ||
| query: isDocumentNode(query) ? print(query) : query, | ||
| variables, | ||
| operationName, | ||
| extensions | ||
| }, { | ||
| next(value) { | ||
| onData == null ? void 0 : onData(value); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(value); | ||
| deferValuePromise = createDeferredPromise(); | ||
| }, | ||
| error(err) { | ||
| reject(err); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.reject(err); | ||
| deferValuePromise = null; | ||
| }, | ||
| complete() { | ||
| resolve(); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(null); | ||
| deferValuePromise = null; | ||
| } | ||
| }); | ||
| } catch (err) { | ||
| reject(err); | ||
| } | ||
| }); | ||
@@ -52,0 +77,0 @@ return { |
@@ -1,7 +0,7 @@ | ||
| import { ClientOptions as SubscriptionsTransportClientOptions, SubscriptionClient as SubscriptionsTransportClient } from 'subscriptions-transport-ws-envelop/client'; | ||
| import type { SubscriptionsTransportClientOptions } from '../deps.js'; | ||
| import type { SubscribeFunction } from '../types'; | ||
| export type { SubscriptionsTransportClientOptions }; | ||
| export declare function createSubscriptionsTransportWebsocketsClient(wsEndpoint: string, options?: SubscriptionsTransportClientOptions): { | ||
| client: SubscriptionsTransportClient; | ||
| client: Promise<import("subscriptions-transport-ws-envelop/client").SubscriptionClient>; | ||
| subscribe: SubscribeFunction<{}>; | ||
| }; |
@@ -5,19 +5,36 @@ 'use strict'; | ||
| const document = require('@graphql-ez/utils/document'); | ||
| const promise = require('@graphql-ez/utils/promise'); | ||
| const graphql = require('graphql'); | ||
| const client = require('subscriptions-transport-ws-envelop/client'); | ||
| const utils = require('@graphql-tools/utils'); | ||
| const ws = require('isomorphic-ws'); | ||
| const promise = require('@graphql-ez/utils/promise'); | ||
| const utils = require('../utils.js'); | ||
| function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; } | ||
| const ws__default = /*#__PURE__*/_interopDefault(ws); | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| return a; | ||
| }; | ||
| function createSubscriptionsTransportWebsocketsClient(wsEndpoint, options = {}) { | ||
| const client$1 = new client.SubscriptionClient(wsEndpoint, { | ||
| lazy: true, | ||
| ...options | ||
| }, ws__default["default"]); | ||
| const client = promise.LazyPromise(async () => { | ||
| const { SubscriptionsTransportClient, ws } = await utils.lazyDeps; | ||
| return new SubscriptionsTransportClient(wsEndpoint, __spreadValues({ | ||
| lazy: true | ||
| }, options), ws); | ||
| }); | ||
| const subscribe = function subscribe2(query, { onData, variables, operationName, extensions } = {}) { | ||
| let unsubscribe = () => { | ||
| let unsubscribeFn; | ||
| const unsubscribe = async () => { | ||
| if (!unsubscribeFn) | ||
| await done; | ||
| unsubscribeFn == null ? void 0 : unsubscribeFn(); | ||
| }; | ||
@@ -34,30 +51,34 @@ let deferValuePromise = promise.createDeferredPromise(); | ||
| const iterator = iteratorGenerator(); | ||
| const done = new Promise((resolve, reject) => { | ||
| const { subscribe: subscribe3 } = client$1.request({ | ||
| query: utils.isDocumentNode(query) ? graphql.print(query) : query, | ||
| variables, | ||
| operationName, | ||
| extensions | ||
| }); | ||
| client$1.onError((err) => { | ||
| const done = new Promise(async (resolve, reject) => { | ||
| try { | ||
| const { subscribe: subscribe3 } = (await client).request({ | ||
| query: document.isDocumentNode(query) ? graphql.print(query) : query, | ||
| variables, | ||
| operationName, | ||
| extensions | ||
| }); | ||
| (await client).onError((err) => { | ||
| reject(err); | ||
| }); | ||
| const result = subscribe3({ | ||
| next(value) { | ||
| onData == null ? void 0 : onData(value); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(value); | ||
| deferValuePromise = promise.createDeferredPromise(); | ||
| }, | ||
| error(err) { | ||
| reject(err); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.reject(err); | ||
| deferValuePromise = null; | ||
| }, | ||
| complete() { | ||
| resolve(); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(null); | ||
| deferValuePromise = null; | ||
| } | ||
| }); | ||
| unsubscribeFn = result.unsubscribe; | ||
| } catch (err) { | ||
| reject(err); | ||
| }); | ||
| const result = subscribe3({ | ||
| next(value) { | ||
| onData == null ? void 0 : onData(value); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(value); | ||
| deferValuePromise = promise.createDeferredPromise(); | ||
| }, | ||
| error(err) { | ||
| reject(err); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.reject(err); | ||
| deferValuePromise = null; | ||
| }, | ||
| complete() { | ||
| resolve(); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(null); | ||
| deferValuePromise = null; | ||
| } | ||
| }); | ||
| unsubscribe = result.unsubscribe; | ||
| } | ||
| }); | ||
@@ -70,5 +91,5 @@ return { | ||
| }; | ||
| return { client: client$1, subscribe }; | ||
| return { client, subscribe }; | ||
| } | ||
| exports.createSubscriptionsTransportWebsocketsClient = createSubscriptionsTransportWebsocketsClient; |
@@ -0,14 +1,35 @@ | ||
| import { isDocumentNode } from '@graphql-ez/utils/document'; | ||
| import { LazyPromise, createDeferredPromise } from '@graphql-ez/utils/promise'; | ||
| import { print } from 'graphql'; | ||
| import { SubscriptionClient } from 'subscriptions-transport-ws-envelop/client'; | ||
| import { isDocumentNode } from '@graphql-tools/utils'; | ||
| import ws from 'isomorphic-ws'; | ||
| import { createDeferredPromise } from '@graphql-ez/utils/promise'; | ||
| import { lazyDeps } from '../utils.mjs'; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| return a; | ||
| }; | ||
| function createSubscriptionsTransportWebsocketsClient(wsEndpoint, options = {}) { | ||
| const client = new SubscriptionClient(wsEndpoint, { | ||
| lazy: true, | ||
| ...options | ||
| }, ws); | ||
| const client = LazyPromise(async () => { | ||
| const { SubscriptionsTransportClient, ws } = await lazyDeps; | ||
| return new SubscriptionsTransportClient(wsEndpoint, __spreadValues({ | ||
| lazy: true | ||
| }, options), ws); | ||
| }); | ||
| const subscribe = function subscribe2(query, { onData, variables, operationName, extensions } = {}) { | ||
| let unsubscribe = () => { | ||
| let unsubscribeFn; | ||
| const unsubscribe = async () => { | ||
| if (!unsubscribeFn) | ||
| await done; | ||
| unsubscribeFn == null ? void 0 : unsubscribeFn(); | ||
| }; | ||
@@ -25,30 +46,34 @@ let deferValuePromise = createDeferredPromise(); | ||
| const iterator = iteratorGenerator(); | ||
| const done = new Promise((resolve, reject) => { | ||
| const { subscribe: subscribe3 } = client.request({ | ||
| query: isDocumentNode(query) ? print(query) : query, | ||
| variables, | ||
| operationName, | ||
| extensions | ||
| }); | ||
| client.onError((err) => { | ||
| const done = new Promise(async (resolve, reject) => { | ||
| try { | ||
| const { subscribe: subscribe3 } = (await client).request({ | ||
| query: isDocumentNode(query) ? print(query) : query, | ||
| variables, | ||
| operationName, | ||
| extensions | ||
| }); | ||
| (await client).onError((err) => { | ||
| reject(err); | ||
| }); | ||
| const result = subscribe3({ | ||
| next(value) { | ||
| onData == null ? void 0 : onData(value); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(value); | ||
| deferValuePromise = createDeferredPromise(); | ||
| }, | ||
| error(err) { | ||
| reject(err); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.reject(err); | ||
| deferValuePromise = null; | ||
| }, | ||
| complete() { | ||
| resolve(); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(null); | ||
| deferValuePromise = null; | ||
| } | ||
| }); | ||
| unsubscribeFn = result.unsubscribe; | ||
| } catch (err) { | ||
| reject(err); | ||
| }); | ||
| const result = subscribe3({ | ||
| next(value) { | ||
| onData == null ? void 0 : onData(value); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(value); | ||
| deferValuePromise = createDeferredPromise(); | ||
| }, | ||
| error(err) { | ||
| reject(err); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.reject(err); | ||
| deferValuePromise = null; | ||
| }, | ||
| complete() { | ||
| resolve(); | ||
| deferValuePromise == null ? void 0 : deferValuePromise.resolve(null); | ||
| deferValuePromise = null; | ||
| } | ||
| }); | ||
| unsubscribe = result.unsubscribe; | ||
| } | ||
| }); | ||
@@ -55,0 +80,0 @@ return { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
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
593381
1242.55%5
-64.29%29
26.09%3432
209.47%1
-50%126
Infinity%2
100%16
700%25
150%+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated