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.0 to 1.0.0-next.0

12

dist/create-fetcher/createFetcher.js

@@ -20,6 +20,6 @@ "use strict";

}
var simpleFetcher = lib_1.createSimpleFetcher(options, httpFetch);
var wsFetcher = lib_1.getWsFetcher(options);
var simpleFetcher = (0, lib_1.createSimpleFetcher)(options, httpFetch);
var wsFetcher = (0, lib_1.getWsFetcher)(options);
var httpFetcher = options.enableIncrementalDelivery
? lib_1.createMultipartFetcher(options, httpFetch)
? (0, lib_1.createMultipartFetcher)(options, httpFetch)
: simpleFetcher;

@@ -30,7 +30,7 @@ return function (graphQLParams, fetcherOpts) {

}
var isSubscription = lib_1.isSubscriptionWithName(fetcherOpts === null || fetcherOpts === void 0 ? void 0 : fetcherOpts.documentAST, graphQLParams.operationName || undefined);
var isSubscription = (0, lib_1.isSubscriptionWithName)(fetcherOpts === null || fetcherOpts === void 0 ? void 0 : fetcherOpts.documentAST, graphQLParams.operationName || undefined);
if (isSubscription) {
if (!wsFetcher) {
throw Error("Your GraphiQL createFetcher is not properly configured for websocket subscriptions yet. " + (options.subscriptionUrl
? "Provided URL " + options.subscriptionUrl + " failed"
throw Error("Your GraphiQL createFetcher is not properly configured for websocket subscriptions yet. ".concat(options.subscriptionUrl
? "Provided URL ".concat(options.subscriptionUrl, " failed")
: "Please provide subscriptionUrl, wsClient or legacyClient option first."));

@@ -37,0 +37,0 @@ }

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -78,3 +78,3 @@ "use strict";

var isSubscription = false;
graphql_1.visit(document, {
(0, graphql_1.visit)(document, {
OperationDefinition: function (node) {

@@ -116,3 +116,3 @@ var _a;

});
return exports.createWebsocketsFetcherFromClient(wsClient);
return (0, exports.createWebsocketsFetcherFromClient)(wsClient);
}

@@ -125,3 +125,3 @@ catch (err) {

}
console.error("Error creating websocket client for:\n" + url + "\n\n" + err);
console.error("Error creating websocket client for:\n".concat(url, "\n\n").concat(err));
}

@@ -131,3 +131,3 @@ };

var createWebsocketsFetcherFromClient = function (wsClient) { return function (graphQLParams) {
return push_pull_async_iterable_iterator_1.makeAsyncIterableIteratorFromSink(function (sink) {
return (0, push_pull_async_iterable_iterator_1.makeAsyncIterableIteratorFromSink)(function (sink) {
return wsClient.subscribe(graphQLParams, __assign(__assign({}, sink), { error: function (err) {

@@ -138,3 +138,3 @@ if (err instanceof Error) {

else if (err instanceof CloseEvent) {
sink.error(new Error(("Socket closed with event " + err.code + " " + (err.reason || '')).trim()));
sink.error(new Error("Socket closed with event ".concat(err.code, " ").concat(err.reason || '').trim()));
}

@@ -153,3 +153,3 @@ else {

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

@@ -169,3 +169,3 @@ exports.createLegacyWebsocketsFetcher = createLegacyWebsocketsFetcher;

}).then(function (response) {
return meros_1.meros(response, {
return (0, meros_1.meros)(response, {
multiple: true,

@@ -176,3 +176,3 @@ });

response = _b.sent();
if (!!push_pull_async_iterable_iterator_1.isAsyncIterable(response)) return [3, 5];
if (!!(0, push_pull_async_iterable_iterator_1.isAsyncIterable)(response)) return [3, 5];
return [4, __await(response.json())];

@@ -191,4 +191,4 @@ case 2: return [4, _b.sent()];

if (chunk.some(function (part) { return !part.json; })) {
message = chunk.map(function (part) { return "Headers::\n" + part.headers + "\n\nBody::\n" + part.body; });
throw new Error("Expected multipart chunks to be of json type. got:\n" + message);
message = chunk.map(function (part) { return "Headers::\n".concat(part.headers, "\n\nBody::\n").concat(part.body); });
throw new Error("Expected multipart chunks to be of json type. got:\n".concat(message));
}

@@ -227,10 +227,10 @@ return [4, __await(chunk.map(function (part) { return part.body; }))];

if (options.wsClient) {
return exports.createWebsocketsFetcherFromClient(options.wsClient);
return (0, exports.createWebsocketsFetcherFromClient)(options.wsClient);
}
if (options.subscriptionUrl) {
return exports.createWebsocketsFetcherFromUrl(options.subscriptionUrl, options.wsConnectionParams);
return (0, exports.createWebsocketsFetcherFromUrl)(options.subscriptionUrl, options.wsConnectionParams);
}
var legacyWebsocketsClient = options.legacyClient || options.legacyWsClient;
if (legacyWebsocketsClient) {
return exports.createLegacyWebsocketsFetcher(legacyWebsocketsClient);
return (0, exports.createLegacyWebsocketsFetcher)(legacyWebsocketsClient);
}

@@ -237,0 +237,0 @@ };

@@ -12,3 +12,3 @@ "use strict";

try {
ast = graphql_1.parse(docString);
ast = (0, graphql_1.parse)(docString);
}

@@ -20,3 +20,3 @@ catch (error) {

var typeInfo = new graphql_1.TypeInfo(schema);
graphql_1.visit(ast, {
(0, graphql_1.visit)(ast, {
leave: function (node) {

@@ -34,3 +34,3 @@ typeInfo.leave(node);

index: node.loc.end,
string: ' ' + graphql_1.print(selectionSet).replace(/\n/g, '\n' + indent),
string: ' ' + (0, graphql_1.print)(selectionSet).replace(/\n/g, '\n' + indent),
});

@@ -63,3 +63,3 @@ }

Object.keys(fields).forEach(function (fieldName) {
if (graphql_1.isLeafType(fields[fieldName].type)) {
if ((0, graphql_1.isLeafType)(fields[fieldName].type)) {
leafFieldNames.push(fieldName);

@@ -71,4 +71,4 @@ }

function buildSelectionSet(type, getDefaultFieldNames) {
var namedType = graphql_1.getNamedType(type);
if (!type || graphql_1.isLeafType(type)) {
var namedType = (0, graphql_1.getNamedType)(type);
if (!type || (0, graphql_1.isLeafType)(type)) {
return;

@@ -75,0 +75,0 @@ }

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -40,5 +40,10 @@ "use strict";

};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -50,2 +55,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

var e_1, _a;
var _b;
var FilteredMap = new Map();

@@ -59,8 +65,8 @@ var result = [];

var existing = FilteredMap.get(uniqueValue);
if (item.directives && item.directives.length) {
if ((_b = item.directives) === null || _b === void 0 ? void 0 : _b.length) {
var itemClone = __assign({}, item);
result.push(itemClone);
}
else if (existing && existing.selectionSet && item.selectionSet) {
existing.selectionSet.selections = __spread(existing.selectionSet.selections, item.selectionSet.selections);
else if ((existing === null || existing === void 0 ? void 0 : existing.selectionSet) && item.selectionSet) {
existing.selectionSet.selections = __spreadArray(__spreadArray([], __read(existing.selectionSet.selections), false), __read(item.selectionSet.selections), false);
}

@@ -91,3 +97,3 @@ else if (!existing) {

var selectionSetTypeName = selectionSetType
? graphql_1.getNamedType(selectionSetType).name
? (0, graphql_1.getNamedType)(selectionSetType).name
: null;

@@ -126,3 +132,3 @@ var outputSelections = [];

if (!fragmentTypeName || fragmentTypeName === selectionSetTypeName) {
outputSelections.push.apply(outputSelections, __spread(inlineRelevantFragmentSpreads(fragmentDefinitions, selection.selectionSet.selections, selectionSetType)));
outputSelections.push.apply(outputSelections, __spreadArray([], __read(inlineRelevantFragmentSpreads(fragmentDefinitions, selection.selectionSet.selections, selectionSetType)), false));
continue;

@@ -176,5 +182,5 @@ }

};
return graphql_1.visit(documentAST, typeInfo ? graphql_1.visitWithTypeInfo(typeInfo, visitors) : visitors);
return (0, graphql_1.visit)(documentAST, typeInfo ? (0, graphql_1.visitWithTypeInfo)(typeInfo, visitors) : visitors);
}
exports.mergeAst = mergeAst;
//# sourceMappingURL=merge-ast.js.map

@@ -8,3 +8,3 @@ "use strict";

}
var names = operations.map(function (op) { return op.name && op.name.value; });
var names = operations.map(function (op) { var _a; return (_a = op.name) === null || _a === void 0 ? void 0 : _a.value; });
if (prevSelectedOperationName &&

@@ -15,3 +15,3 @@ names.indexOf(prevSelectedOperationName) !== -1) {

if (prevSelectedOperationName && prevOperations) {
var prevNames = prevOperations.map(function (op) { return op.name && op.name.value; });
var prevNames = prevOperations.map(function (op) { var _a; return (_a = op.name) === null || _a === void 0 ? void 0 : _a.value; });
var prevIndex = prevNames.indexOf(prevSelectedOperationName);

@@ -18,0 +18,0 @@ if (prevIndex !== -1 && prevIndex < names.length) {

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -28,3 +28,3 @@ "use strict";

}
var key = STORAGE_NAMESPACE + ":" + name;
var key = "".concat(STORAGE_NAMESPACE, ":").concat(name);
var value = this.storage.getItem(key);

@@ -41,3 +41,3 @@ if (value === 'null' || value === 'undefined') {

if (this.storage) {
var key = STORAGE_NAMESPACE + ":" + name;
var key = "".concat(STORAGE_NAMESPACE, ":").concat(name);
if (value) {

@@ -48,3 +48,3 @@ try {

catch (e) {
error = e instanceof Error ? e : new Error("" + e);
error = e instanceof Error ? e : new Error("".concat(e));
quotaError = isQuotaError(this.storage, e);

@@ -51,0 +51,0 @@ }

@@ -29,5 +29,10 @@ "use strict";

};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -59,3 +64,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

this.favorite = new query_1.QueryStore('favorites', this.storage, null);
this.queries = __spread(this.history.fetchAll(), this.favorite.fetchAll());
this.queries = __spreadArray(__spreadArray([], __read(this.history.fetchAll()), false), __read(this.favorite.fetchAll()), false);
}

@@ -67,3 +72,3 @@ HistoryStore.prototype.shouldSaveQuery = function (query, variables, headers, lastQuerySaved) {

try {
graphql_1.parse(query);
(0, graphql_1.parse)(query);
}

@@ -110,3 +115,3 @@ catch (e) {

}
this.queries = __spread(this.history.items, this.favorite.items);
this.queries = __spreadArray(__spreadArray([], __read(this.history.items), false), __read(this.favorite.items), false);
};

@@ -127,3 +132,3 @@ HistoryStore.prototype.editLabel = function (query, variables, headers, operationName, label, favorite) {

}
this.queries = __spread(this.history.items, this.favorite.items);
this.queries = __spreadArray(__spreadArray([], __read(this.history.items), false), __read(this.favorite.items), false);
};

@@ -130,0 +135,0 @@ return HistoryStore;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -18,5 +18,10 @@ "use strict";

};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -84,3 +89,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

var _a;
var items = __spread(this.items, [item]);
var items = __spreadArray(__spreadArray([], __read(this.items), false), [item], false);
if (this.maxSize && items.length > this.maxSize) {

@@ -87,0 +92,0 @@ items.shift();

@@ -104,3 +104,3 @@ ## Create Fetcher

Pass a custom fetch implementation such as `isomorphic-feth`
Pass a custom fetch implementation such as `isomorphic-fetch`

@@ -139,3 +139,3 @@ ### Customization Examples

(not reccomended)
(not recommended)

@@ -165,3 +165,3 @@ By providing the `legacyClient` you can support a `subscriptions-transport-ws` client implementation, or equivalent

you will need to install the client seperately:
you will need to install the client separately:

@@ -168,0 +168,0 @@ ```bash

import { TypeInfo, getNamedType, visit, visitWithTypeInfo, Kind, } from 'graphql';
function uniqueBy(array, iteratee) {
var _a;
const FilteredMap = new Map();

@@ -9,7 +10,7 @@ const result = [];

const existing = FilteredMap.get(uniqueValue);
if (item.directives && item.directives.length) {
if ((_a = item.directives) === null || _a === void 0 ? void 0 : _a.length) {
const itemClone = Object.assign({}, item);
result.push(itemClone);
}
else if (existing && existing.selectionSet && item.selectionSet) {
else if ((existing === null || existing === void 0 ? void 0 : existing.selectionSet) && item.selectionSet) {
existing.selectionSet.selections = [

@@ -16,0 +17,0 @@ ...existing.selectionSet.selections,

@@ -5,3 +5,3 @@ export function getSelectedOperationName(prevOperations, prevSelectedOperationName, operations) {

}
const names = operations.map(op => op.name && op.name.value);
const names = operations.map(op => { var _a; return (_a = op.name) === null || _a === void 0 ? void 0 : _a.value; });
if (prevSelectedOperationName &&

@@ -12,3 +12,3 @@ names.indexOf(prevSelectedOperationName) !== -1) {

if (prevSelectedOperationName && prevOperations) {
const prevNames = prevOperations.map(op => op.name && op.name.value);
const prevNames = prevOperations.map(op => { var _a; return (_a = op.name) === null || _a === void 0 ? void 0 : _a.value; });
const prevIndex = prevNames.indexOf(prevSelectedOperationName);

@@ -15,0 +15,0 @@ if (prevIndex !== -1 && prevIndex < names.length) {

{
"name": "@graphiql/toolkit",
"version": "0.6.0",
"version": "1.0.0-next.0",
"description": "Utility to build a fetcher for GraphiQL",

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

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

[Discord Channel](https://discord.gg/NP5vbPeUFp)
[Changelog](https://github.com/graphql/graphiql/blob/main/packages/graphql-toolkit/CHANGELOG.md) | [API Docs](https://graphiql-test.netlify.app/typedoc/modules/graphiql_toolkit.html) | [NPM](https://www.npmjs.com/package/@graphiql/toolkit) | [Discord](https://discord.gg/NP5vbPeUFp)

@@ -3,0 +3,0 @@ # `@graphiql/toolkit`

@@ -22,13 +22,2 @@ import { parse, getIntrospectionQuery } from 'graphql';

const exampleWithSubscripton = /* GraphQL */ `
subscription Example {
example
}
query SomethingElse {
example
}
`;
const exampleWithSubscriptonNode = parse(exampleWithSubscripton);
const serverURL = 'http://localhost:3000/graphql';

@@ -43,5 +32,5 @@ const wssURL = 'ws://localhost:3000/graphql';

});
it('returns fetcher without websocket client by default', async () => {
it('returns fetcher without websocket client by default', () => {
createWebsocketsFetcherFromUrl.mockReturnValue(true);
const fetcher = createGraphiQLFetcher({ url: serverURL });
createGraphiQLFetcher({ url: serverURL });
expect(createWebsocketsFetcherFromUrl.mock.calls).toEqual([]);

@@ -48,0 +37,0 @@ expect(createMultipartFetcher.mock.calls).toEqual([

@@ -18,3 +18,3 @@ import { parse } from 'graphql';

const exampleWithSubscripton = /* GraphQL */ parse(`
const exampleWithSubscription = /* GraphQL */ parse(`
subscription Example {

@@ -28,6 +28,6 @@ example

describe('isSubcriptionWithName', () => {
describe('isSubscriptionWithName', () => {
it('detects when the subscription is present', () => {
expect(
isSubscriptionWithName(exampleWithSubscripton, 'Example'),
isSubscriptionWithName(exampleWithSubscription, 'Example'),
).toBeTruthy();

@@ -37,3 +37,3 @@ });

expect(
isSubscriptionWithName(exampleWithSubscripton, 'SomethingElse'),
isSubscriptionWithName(exampleWithSubscription, 'SomethingElse'),
).toBeFalsy();

@@ -43,3 +43,3 @@ });

expect(
isSubscriptionWithName(exampleWithSubscripton, 'NotPresent'),
isSubscriptionWithName(exampleWithSubscription, 'NotPresent'),
).toBeFalsy();

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

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

* `legacyWsClient` implementation that matches `subscriptions-transport-ws` signature,
* whether via `new SubcriptionsClient()` itself or another client with a similar signature.
* whether via `new SubscriptionsClient()` itself or another client with a similar signature.
*/

@@ -112,3 +112,3 @@ legacyWsClient?: any;

* If you enable the headers editor and the user provides
* A header you set statically here, it will be overriden by their value.
* A header you set statically here, it will be overridden by their value.
*/

@@ -115,0 +115,0 @@ headers?: Record<string, string>;

@@ -36,3 +36,3 @@ import {

it('inlines simple nested fragment', () => {
it('does inline simple nested fragment', () => {
const query = `

@@ -60,3 +60,3 @@ query Test {

it('inlines triple nested fragment', () => {
it('does inline triple nested fragment', () => {
const query = `

@@ -96,3 +96,3 @@ query Test {

it('inlines multiple fragments', () => {
it('does inline multiple fragments', () => {
const query = `

@@ -99,0 +99,0 @@ query Test {

@@ -26,7 +26,7 @@ import {

const existing = FilteredMap.get(uniqueValue);
if (item.directives && item.directives.length) {
if (item.directives?.length) {
// Cannot inline fields with directives (yet)
const itemClone = { ...item };
result.push(itemClone);
} else if (existing && existing.selectionSet && item.selectionSet) {
} else if (existing?.selectionSet && item.selectionSet) {
// Merge the selection sets

@@ -33,0 +33,0 @@ existing.selectionSet.selections = [

@@ -18,3 +18,3 @@ import { OperationDefinitionNode } from 'graphql';

// If a previous selection still exists, continue to use it.
const names = operations.map(op => op.name && op.name.value);
const names = operations.map(op => op.name?.value);
if (

@@ -29,3 +29,3 @@ prevSelectedOperationName &&

if (prevSelectedOperationName && prevOperations) {
const prevNames = prevOperations.map(op => op.name && op.name.value);
const prevNames = prevOperations.map(op => op.name?.value);
const prevIndex = prevNames.indexOf(prevSelectedOperationName);

@@ -32,0 +32,0 @@ if (prevIndex !== -1 && prevIndex < names.length) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc