Socket
Socket
Sign inDemoInstall

@graphiql/toolkit

Package Overview
Dependencies
Maintainers
2
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphiql/toolkit - npm Package Compare versions

Comparing version 0.6.1 to 0.7.0-canary-dda1cf54.0

17

CHANGELOG.md
# @graphiql/toolkit
## 0.7.0-canary-dda1cf54.0
### Minor Changes
- [#2688](https://github.com/graphql/graphiql/pull/2688) [`b1e0a9de`](https://github.com/graphql/graphiql/commit/b1e0a9deb795f40c1baccdbca4a0d224ee874e02) Thanks [@thomasheyenbrock](https://github.com/thomasheyenbrock)! - BREAKING: Don't pass `shouldPersistHeaders` anymore when invoking the fetcher function. This value can be looked up by consuming the `EditorContext`:
```js
import { useEditorContext } from '@graphiql/react';
function MyComponent() {
const { shouldPersistHeaders } = useEditorContext();
// Do things...
}
```
* [#2688](https://github.com/graphql/graphiql/pull/2688) [`2af736cb`](https://github.com/graphql/graphiql/commit/2af736cbf9dafaf8fe2d6e3c49e246fb1b21fbd2) Thanks [@thomasheyenbrock](https://github.com/thomasheyenbrock)! - Add a `clear` method to `Storage` classes
## 0.6.1

@@ -4,0 +21,0 @@

8

dist/async-helpers/index.js

@@ -38,8 +38,4 @@ "use strict";

var _a;
var iteratorReturn = (_a = ('return' in input
? input
: input[Symbol.asyncIterator]()).return) === null || _a === void 0 ? void 0 : _a.bind(input);
var iteratorNext = ('next' in input
? input
: input[Symbol.asyncIterator]()).next.bind(input);
var iteratorReturn = (_a = ('return' in input ? input : input[Symbol.asyncIterator]()).return) === null || _a === void 0 ? void 0 : _a.bind(input);
var iteratorNext = ('next' in input ? input : input[Symbol.asyncIterator]()).next.bind(input);
iteratorNext()

@@ -46,0 +42,0 @@ .then(function (result) {

@@ -91,17 +91,19 @@ "use strict";

exports.isSubscriptionWithName = isSubscriptionWithName;
var createSimpleFetcher = function (options, httpFetch) { return function (graphQLParams, fetcherOpts) { return __awaiter(void 0, void 0, void 0, function () {
var data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, httpFetch(options.url, {
method: 'POST',
body: JSON.stringify(graphQLParams),
headers: __assign(__assign({ 'content-type': 'application/json' }, options.headers), fetcherOpts === null || fetcherOpts === void 0 ? void 0 : fetcherOpts.headers),
})];
case 1:
data = _a.sent();
return [2, data.json()];
}
});
}); }; };
var createSimpleFetcher = function (options, httpFetch) {
return function (graphQLParams, fetcherOpts) { return __awaiter(void 0, void 0, void 0, function () {
var data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, httpFetch(options.url, {
method: 'POST',
body: JSON.stringify(graphQLParams),
headers: __assign(__assign({ 'content-type': 'application/json' }, options.headers), fetcherOpts === null || fetcherOpts === void 0 ? void 0 : fetcherOpts.headers),
})];
case 1:
data = _a.sent();
return [2, data.json()];
}
});
}); };
};
exports.createSimpleFetcher = createSimpleFetcher;

@@ -141,6 +143,8 @@ var createWebsocketsFetcherFromUrl = function (url, connectionParams) {

exports.createWebsocketsFetcherFromClient = createWebsocketsFetcherFromClient;
var createLegacyWebsocketsFetcher = function (legacyWsClient) { return function (graphQLParams) {
var observable = legacyWsClient.request(graphQLParams);
return (0, push_pull_async_iterable_iterator_1.makeAsyncIterableIteratorFromSink)(function (sink) { return observable.subscribe(sink).unsubscribe; });
}; };
var createLegacyWebsocketsFetcher = function (legacyWsClient) {
return function (graphQLParams) {
var observable = legacyWsClient.request(graphQLParams);
return (0, push_pull_async_iterable_iterator_1.makeAsyncIterableIteratorFromSink)(function (sink) { return observable.subscribe(sink).unsubscribe; });
};
};
exports.createLegacyWebsocketsFetcher = createLegacyWebsocketsFetcher;

@@ -158,4 +162,4 @@ var createMultipartFetcher = function (options, httpFetch) {

headers: __assign(__assign({ 'content-type': 'application/json', accept: 'application/json, multipart/mixed' }, options.headers), fetcherOpts === null || fetcherOpts === void 0 ? void 0 : fetcherOpts.headers),
}).then(function (response) {
return (0, meros_1.meros)(response, {
}).then(function (r) {
return (0, meros_1.meros)(r, {
multiple: true,

@@ -162,0 +166,0 @@ });

@@ -24,3 +24,2 @@ import type { DocumentNode, IntrospectionQuery } from 'graphql';

};
shouldPersistHeaders?: boolean;
documentAST?: DocumentNode;

@@ -27,0 +26,0 @@ };

export declare type Storage = {
getItem(key: string): string | null;
setItem(key: string, value: string): void;
removeItem(key: string): void;
setItem(key: string, value: string): void;
clear(): void;
length: number;

@@ -15,3 +16,4 @@ };

};
clear(): void;
}
//# sourceMappingURL=base.d.ts.map

@@ -56,2 +56,7 @@ "use strict";

};
StorageAPI.prototype.clear = function () {
if (this.storage) {
this.storage.clear();
}
};
return StorageAPI;

@@ -58,0 +63,0 @@ }());

@@ -32,8 +32,4 @@ export function isPromise(value) {

var _a;
const iteratorReturn = (_a = ('return' in input
? input
: input[Symbol.asyncIterator]()).return) === null || _a === void 0 ? void 0 : _a.bind(input);
const iteratorNext = ('next' in input
? input
: input[Symbol.asyncIterator]()).next.bind(input);
const iteratorReturn = (_a = ('return' in input ? input : input[Symbol.asyncIterator]()).return) === null || _a === void 0 ? void 0 : _a.bind(input);
const iteratorNext = ('next' in input ? input : input[Symbol.asyncIterator]()).next.bind(input);
iteratorNext()

@@ -40,0 +36,0 @@ .then(result => {

@@ -95,3 +95,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

headers: Object.assign(Object.assign({ 'content-type': 'application/json', accept: 'application/json, multipart/mixed' }, options.headers), fetcherOpts === null || fetcherOpts === void 0 ? void 0 : fetcherOpts.headers),
}).then(response => meros(response, {
}).then(r => meros(r, {
multiple: true,

@@ -98,0 +98,0 @@ })));

@@ -24,3 +24,2 @@ import type { DocumentNode, IntrospectionQuery } from 'graphql';

};
shouldPersistHeaders?: boolean;
documentAST?: DocumentNode;

@@ -27,0 +26,0 @@ };

export declare type Storage = {
getItem(key: string): string | null;
setItem(key: string, value: string): void;
removeItem(key: string): void;
setItem(key: string, value: string): void;
clear(): void;
length: number;

@@ -15,3 +16,4 @@ };

};
clear(): void;
}
//# sourceMappingURL=base.d.ts.map

@@ -53,4 +53,9 @@ function isQuotaError(storage, e) {

}
clear() {
if (this.storage) {
this.storage.clear();
}
}
}
const STORAGE_NAMESPACE = 'graphiql';
//# sourceMappingURL=base.js.map
{
"name": "@graphiql/toolkit",
"version": "0.6.1",
"version": "0.7.0-canary-dda1cf54.0",
"description": "Utility to build a fetcher for GraphiQL",

@@ -5,0 +5,0 @@ "contributors": [

@@ -57,9 +57,7 @@ import {

// so every AsyncIterable must be implemented using AsyncGenerator.
const iteratorReturn = ('return' in input
? input
: input[Symbol.asyncIterator]()
const iteratorReturn = (
'return' in input ? input : input[Symbol.asyncIterator]()
).return?.bind(input);
const iteratorNext = ('next' in input
? input
: input[Symbol.asyncIterator]()
const iteratorNext = (
'next' in input ? input : input[Symbol.asyncIterator]()
).next.bind(input);

@@ -66,0 +64,0 @@

@@ -52,6 +52,3 @@ import { parse, getIntrospectionQuery } from 'graphql';

{ query: getIntrospectionQuery(), operationName: 'IntrospectionQuery' },
{
documentAST: exampleIntrospectionDocument,
shouldPersistHeaders: false,
},
{ documentAST: exampleIntrospectionDocument },
);

@@ -58,0 +55,0 @@ expect(res).toEqual('hey!');

@@ -58,20 +58,16 @@ import { DocumentNode, visit } from 'graphql';

*/
export const createSimpleFetcher = (
options: CreateFetcherOptions,
httpFetch: typeof fetch,
): Fetcher => async (
graphQLParams: FetcherParams,
fetcherOpts?: FetcherOpts,
) => {
const data = await httpFetch(options.url, {
method: 'POST',
body: JSON.stringify(graphQLParams),
headers: {
'content-type': 'application/json',
...options.headers,
...fetcherOpts?.headers,
},
});
return data.json();
};
export const createSimpleFetcher =
(options: CreateFetcherOptions, httpFetch: typeof fetch): Fetcher =>
async (graphQLParams: FetcherParams, fetcherOpts?: FetcherOpts) => {
const data = await httpFetch(options.url, {
method: 'POST',
body: JSON.stringify(graphQLParams),
headers: {
'content-type': 'application/json',
...options.headers,
...fetcherOpts?.headers,
},
});
return data.json();
};

@@ -112,21 +108,22 @@ export const createWebsocketsFetcherFromUrl = (

*/
export const createWebsocketsFetcherFromClient = (wsClient: Client) => (
graphQLParams: FetcherParams,
) =>
makeAsyncIterableIteratorFromSink<ExecutionResult>(sink =>
wsClient!.subscribe(graphQLParams, {
...sink,
error: err => {
if (err instanceof CloseEvent) {
sink.error(
new Error(
`Socket closed with event ${err.code} ${err.reason || ''}`.trim(),
),
);
} else {
sink.error(err);
}
},
}),
);
export const createWebsocketsFetcherFromClient =
(wsClient: Client) => (graphQLParams: FetcherParams) =>
makeAsyncIterableIteratorFromSink<ExecutionResult>(sink =>
wsClient!.subscribe(graphQLParams, {
...sink,
error: err => {
if (err instanceof CloseEvent) {
sink.error(
new Error(
`Socket closed with event ${err.code} ${
err.reason || ''
}`.trim(),
),
);
} else {
sink.error(err);
}
},
}),
);

@@ -140,11 +137,11 @@ /**

*/
export const createLegacyWebsocketsFetcher = (legacyWsClient: {
request: (params: FetcherParams) => unknown;
}) => (graphQLParams: FetcherParams) => {
const observable = legacyWsClient.request(graphQLParams);
return makeAsyncIterableIteratorFromSink<ExecutionResult>(
// @ts-ignore
sink => observable.subscribe(sink).unsubscribe,
);
};
export const createLegacyWebsocketsFetcher =
(legacyWsClient: { request: (params: FetcherParams) => unknown }) =>
(graphQLParams: FetcherParams) => {
const observable = legacyWsClient.request(graphQLParams);
return makeAsyncIterableIteratorFromSink<ExecutionResult>(
// @ts-ignore
sink => observable.subscribe(sink).unsubscribe,
);
};
/**

@@ -173,4 +170,4 @@ * create a fetcher with the `IncrementalDelivery` HTTP/S spec for

},
}).then(response =>
meros<Extract<ExecutionResultPayload, { hasNext: boolean }>>(response, {
}).then(r =>
meros<Extract<ExecutionResultPayload, { hasNext: boolean }>>(r, {
multiple: true,

@@ -177,0 +174,0 @@ }),

@@ -35,8 +35,2 @@ import type { DocumentNode, IntrospectionQuery } from 'graphql';

headers?: { [key: string]: any };
/**
* @deprecated This property will be removed in the next major version of
* `graphiql`, it just echoes back the value passed as prop to the `GraphiQL`
* component with a default value of `false`
*/
shouldPersistHeaders?: boolean;
documentAST?: DocumentNode;

@@ -43,0 +37,0 @@ };

@@ -0,5 +1,34 @@

/**
* This describes the attributes and methods that a store has to support in
* order to be used with GraphiQL. It closely resembles the `localStorage`
* API as it is the default storage used in GraphiQL.
*/
export type Storage = {
/**
* Retrieve an item from the store by its key.
* @param key The key of the item to retrieve.
* @returns {?string} The stored value for the given key if it exists, `null`
* otherwise.
*/
getItem(key: string): string | null;
/**
* Add a value to the store for a given key. If there already exists a value
* for the given key, this method will override the value.
* @param key The key to store the value for.
* @param value The value to store.
*/
setItem(key: string, value: string): void;
/**
* Remove the value for a given key from the store. If there is no value for
* the given key this method does nothing.
* @param key The key to remove the value from the store.
*/
removeItem(key: string): void;
setItem(key: string, value: string): void;
/**
* Remove all items from the store.
*/
clear(): void;
/**
* The number of items that are currently stored.
*/
length: number;

@@ -80,4 +109,10 @@ };

}
clear() {
if (this.storage) {
this.storage.clear();
}
}
}
const STORAGE_NAMESPACE = 'graphiql';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc