Socket
Socket
Sign inDemoInstall

@graphiql/toolkit

Package Overview
Dependencies
Maintainers
5
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.8.4 to 0.9.0-canary-344df134.0

8

CHANGELOG.md
# @graphiql/toolkit
## 0.9.0-canary-344df134.0
### Minor Changes
- [#3324](https://github.com/graphql/graphiql/pull/3324) [`c5fafc3a`](https://github.com/graphql/graphiql/commit/c5fafc3ac1e140711c054c5812a5b63f76140280) Thanks [@acao](https://github.com/acao)! - _BREAKING CHANGE:_ drop commonjs exports in all libraries except for `graphiql` and `@graphiql/react`
all previously `<package>/esm` paths are now `<package>/dist` for example, `monaco-graphql/esm/initializeMode` is now `monaco-graphql/dist/initializeMode`
## 0.8.4

@@ -4,0 +12,0 @@

95

dist/async-helpers/index.js

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

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -11,32 +10,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetcherReturnToPromise = exports.isAsyncIterable = exports.isObservable = exports.isPromise = void 0;
function isPromise(value) {
export function isPromise(value) {
return (typeof value === 'object' &&

@@ -46,7 +16,6 @@ value !== null &&

}
exports.isPromise = isPromise;
function observableToPromise(observable) {
return new Promise(function (resolve, reject) {
var subscription = observable.subscribe({
next: function (v) {
return new Promise((resolve, reject) => {
const subscription = observable.subscribe({
next(v) {
resolve(v);

@@ -56,3 +25,3 @@ subscription.unsubscribe();

error: reject,
complete: function () {
complete() {
reject(new Error('no value resolved'));

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

}
function isObservable(value) {
export function isObservable(value) {
return (typeof value === 'object' &&

@@ -70,4 +39,3 @@ value !== null &&

}
exports.isObservable = isObservable;
function isAsyncIterable(input) {
export function isAsyncIterable(input) {
return (typeof input === 'object' &&

@@ -78,41 +46,24 @@ input !== null &&

}
exports.isAsyncIterable = isAsyncIterable;
function asyncIterableToPromise(input) {
var _a;
return __awaiter(this, void 0, void 0, function () {
var iteratorReturn, iteratorNext, result;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
iteratorReturn = (_a = ('return' in input ? input : input[Symbol.asyncIterator]()).return) === null || _a === void 0 ? void 0 : _a.bind(input);
iteratorNext = ('next' in input ? input : input[Symbol.asyncIterator]()).next.bind(input);
return [4, iteratorNext()];
case 1:
result = _b.sent();
void (iteratorReturn === null || iteratorReturn === void 0 ? void 0 : iteratorReturn());
return [2, result.value];
}
});
return __awaiter(this, void 0, void 0, function* () {
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 result = yield iteratorNext();
void (iteratorReturn === null || iteratorReturn === void 0 ? void 0 : iteratorReturn());
return result.value;
});
}
function fetcherReturnToPromise(fetcherResult) {
return __awaiter(this, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, fetcherResult];
case 1:
result = _a.sent();
if (isAsyncIterable(result)) {
return [2, asyncIterableToPromise(result)];
}
if (isObservable(result)) {
return [2, observableToPromise(result)];
}
return [2, result];
}
});
export function fetcherReturnToPromise(fetcherResult) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield fetcherResult;
if (isAsyncIterable(result)) {
return asyncIterableToPromise(result);
}
if (isObservable(result)) {
return observableToPromise(result);
}
return result;
});
}
exports.fetcherReturnToPromise = fetcherReturnToPromise;
//# sourceMappingURL=index.js.map

@@ -1,7 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createGraphiQLFetcher = void 0;
var lib_1 = require("./lib");
function createGraphiQLFetcher(options) {
var httpFetch;
import { createMultipartFetcher, createSimpleFetcher, isSubscriptionWithName, getWsFetcher, } from './lib';
export function createGraphiQLFetcher(options) {
let httpFetch;
if (typeof window !== 'undefined' && window.fetch) {

@@ -20,19 +17,19 @@ httpFetch = window.fetch;

}
var simpleFetcher = (0, lib_1.createSimpleFetcher)(options, httpFetch);
var httpFetcher = options.enableIncrementalDelivery
? (0, lib_1.createMultipartFetcher)(options, httpFetch)
const simpleFetcher = createSimpleFetcher(options, httpFetch);
const httpFetcher = options.enableIncrementalDelivery
? createMultipartFetcher(options, httpFetch)
: simpleFetcher;
return function (graphQLParams, fetcherOpts) {
return (graphQLParams, fetcherOpts) => {
if (graphQLParams.operationName === 'IntrospectionQuery') {
return (options.schemaFetcher || simpleFetcher)(graphQLParams, fetcherOpts);
}
var isSubscription = (fetcherOpts === null || fetcherOpts === void 0 ? void 0 : fetcherOpts.documentAST)
? (0, lib_1.isSubscriptionWithName)(fetcherOpts.documentAST, graphQLParams.operationName || undefined)
const isSubscription = (fetcherOpts === null || fetcherOpts === void 0 ? void 0 : fetcherOpts.documentAST)
? isSubscriptionWithName(fetcherOpts.documentAST, graphQLParams.operationName || undefined)
: false;
if (isSubscription) {
var wsFetcher = (0, lib_1.getWsFetcher)(options, fetcherOpts);
const wsFetcher = getWsFetcher(options, fetcherOpts);
if (!wsFetcher) {
throw new 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."));
throw new Error(`Your GraphiQL createFetcher is not properly configured for websocket subscriptions yet. ${options.subscriptionUrl
? `Provided URL ${options.subscriptionUrl} failed`
: 'Please provide subscriptionUrl, wsClient or legacyClient option first.'}`);
}

@@ -44,3 +41,2 @@ return wsFetcher(graphQLParams);

}
exports.createGraphiQLFetcher = createGraphiQLFetcher;
//# sourceMappingURL=createFetcher.js.map

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

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = 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) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createGraphiQLFetcher = void 0;
__exportStar(require("./types"), exports);
var createFetcher_1 = require("./createFetcher");
Object.defineProperty(exports, "createGraphiQLFetcher", { enumerable: true, get: function () { return createFetcher_1.createGraphiQLFetcher; } });
export * from './types';
export { createGraphiQLFetcher } from './createFetcher';
//# sourceMappingURL=index.js.map

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

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -22,29 +10,2 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }

@@ -69,14 +30,12 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {

};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWsFetcher = exports.createMultipartFetcher = exports.createLegacyWebsocketsFetcher = exports.createWebsocketsFetcherFromClient = exports.createWebsocketsFetcherFromUrl = exports.createSimpleFetcher = exports.isSubscriptionWithName = void 0;
var graphql_1 = require("graphql");
var meros_1 = require("meros");
var push_pull_async_iterable_iterator_1 = require("@n1ru4l/push-pull-async-iterable-iterator");
var errorHasCode = function (err) {
import { visit } from 'graphql';
import { meros } from 'meros';
import { isAsyncIterable, makeAsyncIterableIteratorFromSink, } from '@n1ru4l/push-pull-async-iterable-iterator';
const errorHasCode = (err) => {
return typeof err === 'object' && err !== null && 'code' in err;
};
var isSubscriptionWithName = function (document, name) {
var isSubscription = false;
(0, graphql_1.visit)(document, {
OperationDefinition: function (node) {
export const isSubscriptionWithName = (document, name) => {
let isSubscription = false;
visit(document, {
OperationDefinition(node) {
var _a;

@@ -90,30 +49,19 @@ if (name === ((_a = node.name) === null || _a === void 0 ? void 0 : _a.value) && node.operation === 'subscription') {

};
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()];
}
});
}); };
};
exports.createSimpleFetcher = createSimpleFetcher;
var createWebsocketsFetcherFromUrl = function (url, connectionParams) {
var wsClient;
export const createSimpleFetcher = (options, httpFetch) => (graphQLParams, fetcherOpts) => __awaiter(void 0, void 0, void 0, function* () {
const data = yield httpFetch(options.url, {
method: 'POST',
body: JSON.stringify(graphQLParams),
headers: Object.assign(Object.assign({ 'content-type': 'application/json' }, options.headers), fetcherOpts === null || fetcherOpts === void 0 ? void 0 : fetcherOpts.headers),
});
return data.json();
});
export const createWebsocketsFetcherFromUrl = (url, connectionParams) => {
let wsClient;
try {
var createClient = require('graphql-ws').createClient;
const { createClient } = require('graphql-ws');
wsClient = createClient({
url: url,
connectionParams: connectionParams,
url,
connectionParams,
});
return (0, exports.createWebsocketsFetcherFromClient)(wsClient);
return createWebsocketsFetcherFromClient(wsClient);
}

@@ -124,104 +72,61 @@ catch (err) {

}
console.error("Error creating websocket client for ".concat(url), err);
console.error(`Error creating websocket client for ${url}`, err);
}
};
exports.createWebsocketsFetcherFromUrl = createWebsocketsFetcherFromUrl;
var createWebsocketsFetcherFromClient = function (wsClient) { return function (graphQLParams) {
return (0, push_pull_async_iterable_iterator_1.makeAsyncIterableIteratorFromSink)(function (sink) {
return wsClient.subscribe(graphQLParams, __assign(__assign({}, sink), { error: function (err) {
if (err instanceof CloseEvent) {
sink.error(new Error("Socket closed with event ".concat(err.code, " ").concat(err.reason || '').trim()));
export const createWebsocketsFetcherFromClient = (wsClient) => (graphQLParams) => makeAsyncIterableIteratorFromSink(sink => wsClient.subscribe(graphQLParams, Object.assign(Object.assign({}, 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 createLegacyWebsocketsFetcher = (legacyWsClient) => (graphQLParams) => {
const observable = legacyWsClient.request(graphQLParams);
return makeAsyncIterableIteratorFromSink(sink => observable.subscribe(sink).unsubscribe);
};
export const createMultipartFetcher = (options, httpFetch) => function (graphQLParams, fetcherOpts) {
return __asyncGenerator(this, arguments, function* () {
var e_1, _a;
const response = yield __await(httpFetch(options.url, {
method: 'POST',
body: JSON.stringify(graphQLParams),
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(r => meros(r, {
multiple: true,
})));
if (!isAsyncIterable(response)) {
return yield __await(yield yield __await(response.json()));
}
try {
for (var response_1 = __asyncValues(response), response_1_1; response_1_1 = yield __await(response_1.next()), !response_1_1.done;) {
const chunk = response_1_1.value;
if (chunk.some(part => !part.json)) {
const message = chunk.map(part => `Headers::\n${part.headers}\n\nBody::\n${part.body}`);
throw new Error(`Expected multipart chunks to be of json type. got:\n${message}`);
}
else {
sink.error(err);
}
} }));
yield yield __await(chunk.map(part => part.body));
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (response_1_1 && !response_1_1.done && (_a = response_1.return)) yield __await(_a.call(response_1));
}
finally { if (e_1) throw e_1.error; }
}
});
}; };
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; });
};
};
exports.createLegacyWebsocketsFetcher = createLegacyWebsocketsFetcher;
var createMultipartFetcher = function (options, httpFetch) {
return function (graphQLParams, fetcherOpts) {
return __asyncGenerator(this, arguments, function () {
var response, response_1, response_1_1, chunk, message, e_1_1;
var e_1, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4, __await(httpFetch(options.url, {
method: 'POST',
body: JSON.stringify(graphQLParams),
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 (r) {
return (0, meros_1.meros)(r, {
multiple: true,
});
}))];
case 1:
response = _b.sent();
if (!!(0, push_pull_async_iterable_iterator_1.isAsyncIterable)(response)) return [3, 5];
return [4, __await(response.json())];
case 2: return [4, _b.sent()];
case 3: return [4, __await.apply(void 0, [_b.sent()])];
case 4: return [2, _b.sent()];
case 5:
_b.trys.push([5, 12, 13, 18]);
response_1 = __asyncValues(response);
_b.label = 6;
case 6: return [4, __await(response_1.next())];
case 7:
if (!(response_1_1 = _b.sent(), !response_1_1.done)) return [3, 11];
chunk = response_1_1.value;
if (chunk.some(function (part) { return !part.json; })) {
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));
}
return [4, __await(chunk.map(function (part) { return part.body; }))];
case 8: return [4, _b.sent()];
case 9:
_b.sent();
_b.label = 10;
case 10: return [3, 6];
case 11: return [3, 18];
case 12:
e_1_1 = _b.sent();
e_1 = { error: e_1_1 };
return [3, 18];
case 13:
_b.trys.push([13, , 16, 17]);
if (!(response_1_1 && !response_1_1.done && (_a = response_1.return))) return [3, 15];
return [4, __await(_a.call(response_1))];
case 14:
_b.sent();
_b.label = 15;
case 15: return [3, 17];
case 16:
if (e_1) throw e_1.error;
return [7];
case 17: return [7];
case 18: return [2];
}
});
});
};
};
exports.createMultipartFetcher = createMultipartFetcher;
var getWsFetcher = function (options, fetcherOpts) {
export const getWsFetcher = (options, fetcherOpts) => {
if (options.wsClient) {
return (0, exports.createWebsocketsFetcherFromClient)(options.wsClient);
return createWebsocketsFetcherFromClient(options.wsClient);
}
if (options.subscriptionUrl) {
return (0, exports.createWebsocketsFetcherFromUrl)(options.subscriptionUrl, __assign(__assign({}, options.wsConnectionParams), fetcherOpts === null || fetcherOpts === void 0 ? void 0 : fetcherOpts.headers));
return createWebsocketsFetcherFromUrl(options.subscriptionUrl, Object.assign(Object.assign({}, options.wsConnectionParams), fetcherOpts === null || fetcherOpts === void 0 ? void 0 : fetcherOpts.headers));
}
var legacyWebsocketsClient = options.legacyClient || options.legacyWsClient;
const legacyWebsocketsClient = options.legacyClient || options.legacyWsClient;
if (legacyWebsocketsClient) {
return (0, exports.createLegacyWebsocketsFetcher)(legacyWebsocketsClient);
return createLegacyWebsocketsFetcher(legacyWebsocketsClient);
}
};
exports.getWsFetcher = getWsFetcher;
//# sourceMappingURL=lib.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export {};
//# sourceMappingURL=types.js.map

@@ -1,15 +0,1 @@

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatResult = exports.formatError = void 0;
function stringify(obj) {

@@ -19,3 +5,3 @@ return JSON.stringify(obj, null, 2);

function formatSingleError(error) {
return __assign(__assign({}, error), { message: error.message, stack: error.stack });
return Object.assign(Object.assign({}, error), { message: error.message, stack: error.stack });
}

@@ -28,6 +14,6 @@ function handleSingleError(error) {

}
function formatError(error) {
export function formatError(error) {
if (Array.isArray(error)) {
return stringify({
errors: error.map(function (e) { return handleSingleError(e); }),
errors: error.map(e => handleSingleError(e)),
});

@@ -37,7 +23,5 @@ }

}
exports.formatError = formatError;
function formatResult(result) {
export function formatResult(result) {
return stringify(result);
}
exports.formatResult = formatResult;
//# sourceMappingURL=index.js.map

@@ -1,44 +0,30 @@

"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fillLeafs = void 0;
var graphql_1 = require("graphql");
function fillLeafs(schema, docString, getDefaultFieldNames) {
var insertions = [];
import { getNamedType, isLeafType, Kind, parse, print, TypeInfo, visit, } from 'graphql';
export function fillLeafs(schema, docString, getDefaultFieldNames) {
const insertions = [];
if (!schema || !docString) {
return { insertions: insertions, result: docString };
return { insertions, result: docString };
}
var ast;
let ast;
try {
ast = (0, graphql_1.parse)(docString);
ast = parse(docString);
}
catch (_a) {
return { insertions: insertions, result: docString };
return { insertions, result: docString };
}
var fieldNameFn = getDefaultFieldNames || defaultGetDefaultFieldNames;
var typeInfo = new graphql_1.TypeInfo(schema);
(0, graphql_1.visit)(ast, {
leave: function (node) {
const fieldNameFn = getDefaultFieldNames || defaultGetDefaultFieldNames;
const typeInfo = new TypeInfo(schema);
visit(ast, {
leave(node) {
typeInfo.leave(node);
},
enter: function (node) {
enter(node) {
typeInfo.enter(node);
if (node.kind === 'Field' && !node.selectionSet) {
var fieldType = typeInfo.getType();
var selectionSet = buildSelectionSet(isFieldType(fieldType), fieldNameFn);
const fieldType = typeInfo.getType();
const selectionSet = buildSelectionSet(isFieldType(fieldType), fieldNameFn);
if (selectionSet && node.loc) {
var indent = getIndentation(docString, node.loc.start);
const indent = getIndentation(docString, node.loc.start);
insertions.push({
index: node.loc.end,
string: ' ' + (0, graphql_1.print)(selectionSet).replaceAll('\n', '\n' + indent),
string: ' ' + print(selectionSet).replaceAll('\n', '\n' + indent),
});

@@ -50,13 +36,11 @@ }

return {
insertions: insertions,
insertions,
result: withInsertions(docString, insertions),
};
}
exports.fillLeafs = fillLeafs;
function defaultGetDefaultFieldNames(type) {
var e_1, _a;
if (!('getFields' in type)) {
return [];
}
var fields = type.getFields();
const fields = type.getFields();
if (fields.id) {

@@ -71,26 +55,16 @@ return ['id'];

}
var leafFieldNames = [];
try {
for (var _b = __values(Object.keys(fields)), _c = _b.next(); !_c.done; _c = _b.next()) {
var fieldName = _c.value;
if ((0, graphql_1.isLeafType)(fields[fieldName].type)) {
leafFieldNames.push(fieldName);
}
const leafFieldNames = [];
for (const fieldName of Object.keys(fields)) {
if (isLeafType(fields[fieldName].type)) {
leafFieldNames.push(fieldName);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return leafFieldNames;
}
function buildSelectionSet(type, getDefaultFieldNames) {
var namedType = (0, graphql_1.getNamedType)(type);
if (!type || (0, graphql_1.isLeafType)(type)) {
const namedType = getNamedType(type);
if (!type || isLeafType(type)) {
return;
}
var fieldNames = getDefaultFieldNames(namedType);
const fieldNames = getDefaultFieldNames(namedType);
if (!Array.isArray(fieldNames) ||

@@ -102,10 +76,10 @@ fieldNames.length === 0 ||

return {
kind: graphql_1.Kind.SELECTION_SET,
selections: fieldNames.map(function (fieldName) {
var fieldDef = namedType.getFields()[fieldName];
var fieldType = fieldDef ? fieldDef.type : null;
kind: Kind.SELECTION_SET,
selections: fieldNames.map(fieldName => {
const fieldDef = namedType.getFields()[fieldName];
const fieldType = fieldDef ? fieldDef.type : null;
return {
kind: graphql_1.Kind.FIELD,
kind: Kind.FIELD,
name: {
kind: graphql_1.Kind.NAME,
kind: Kind.NAME,
value: fieldName,

@@ -119,22 +93,11 @@ },

function withInsertions(initial, insertions) {
var e_2, _a;
if (insertions.length === 0) {
return initial;
}
var edited = '';
var prevIndex = 0;
try {
for (var insertions_1 = __values(insertions), insertions_1_1 = insertions_1.next(); !insertions_1_1.done; insertions_1_1 = insertions_1.next()) {
var _b = insertions_1_1.value, index = _b.index, string = _b.string;
edited += initial.slice(prevIndex, index) + string;
prevIndex = index;
}
let edited = '';
let prevIndex = 0;
for (const { index, string } of insertions) {
edited += initial.slice(prevIndex, index) + string;
prevIndex = index;
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (insertions_1_1 && !insertions_1_1.done && (_a = insertions_1.return)) _a.call(insertions_1);
}
finally { if (e_2) throw e_2.error; }
}
edited += initial.slice(prevIndex);

@@ -144,6 +107,6 @@ return edited;

function getIndentation(str, index) {
var indentStart = index;
var indentEnd = index;
let indentStart = index;
let indentEnd = index;
while (indentStart) {
var c = str.charCodeAt(indentStart - 1);
const c = str.charCodeAt(indentStart - 1);
if (c === 10 || c === 13 || c === 0x2028 || c === 0x2029) {

@@ -150,0 +113,0 @@ break;

@@ -1,20 +0,4 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = 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) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./auto-complete"), exports);
__exportStar(require("./merge-ast"), exports);
__exportStar(require("./operation-name"), exports);
export * from './auto-complete';
export * from './merge-ast';
export * from './operation-name';
//# sourceMappingURL=index.js.map

@@ -1,87 +0,29 @@

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
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));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeAst = void 0;
var graphql_1 = require("graphql");
import { TypeInfo, getNamedType, visit, visitWithTypeInfo, Kind, } from 'graphql';
function uniqueBy(array, iteratee) {
var e_1, _a;
var _b;
var FilteredMap = new Map();
var result = [];
try {
for (var array_1 = __values(array), array_1_1 = array_1.next(); !array_1_1.done; array_1_1 = array_1.next()) {
var item = array_1_1.value;
if (item.kind === 'Field') {
var uniqueValue = iteratee(item);
var existing = FilteredMap.get(uniqueValue);
if ((_b = item.directives) === null || _b === void 0 ? void 0 : _b.length) {
var itemClone = __assign({}, item);
result.push(itemClone);
}
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);
}
else if (!existing) {
var itemClone = __assign({}, item);
FilteredMap.set(uniqueValue, itemClone);
result.push(itemClone);
}
var _a;
const FilteredMap = new Map();
const result = [];
for (const item of array) {
if (item.kind === 'Field') {
const uniqueValue = iteratee(item);
const existing = FilteredMap.get(uniqueValue);
if ((_a = item.directives) === null || _a === void 0 ? void 0 : _a.length) {
const itemClone = Object.assign({}, item);
result.push(itemClone);
}
else {
result.push(item);
else if ((existing === null || existing === void 0 ? void 0 : existing.selectionSet) && item.selectionSet) {
existing.selectionSet.selections = [
...existing.selectionSet.selections,
...item.selectionSet.selections,
];
}
else if (!existing) {
const itemClone = Object.assign({}, item);
FilteredMap.set(uniqueValue, itemClone);
result.push(itemClone);
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (array_1_1 && !array_1_1.done && (_a = array_1.return)) _a.call(array_1);
else {
result.push(item);
}
finally { if (e_1) throw e_1.error; }
}

@@ -91,91 +33,66 @@ return result;

function inlineRelevantFragmentSpreads(fragmentDefinitions, selections, selectionSetType) {
var e_2, _a;
var _b;
var selectionSetTypeName = selectionSetType
? (0, graphql_1.getNamedType)(selectionSetType).name
var _a;
const selectionSetTypeName = selectionSetType
? getNamedType(selectionSetType).name
: null;
var outputSelections = [];
var seenSpreads = [];
try {
for (var selections_1 = __values(selections), selections_1_1 = selections_1.next(); !selections_1_1.done; selections_1_1 = selections_1.next()) {
var selection = selections_1_1.value;
if (selection.kind === 'FragmentSpread') {
var fragmentName = selection.name.value;
if (!selection.directives || selection.directives.length === 0) {
if (seenSpreads.includes(fragmentName)) {
continue;
}
else {
seenSpreads.push(fragmentName);
}
const outputSelections = [];
const seenSpreads = [];
for (let selection of selections) {
if (selection.kind === 'FragmentSpread') {
const fragmentName = selection.name.value;
if (!selection.directives || selection.directives.length === 0) {
if (seenSpreads.includes(fragmentName)) {
continue;
}
var fragmentDefinition = fragmentDefinitions[selection.name.value];
if (fragmentDefinition) {
var typeCondition = fragmentDefinition.typeCondition, directives = fragmentDefinition.directives, selectionSet = fragmentDefinition.selectionSet;
selection = {
kind: graphql_1.Kind.INLINE_FRAGMENT,
typeCondition: typeCondition,
directives: directives,
selectionSet: selectionSet,
};
else {
seenSpreads.push(fragmentName);
}
}
if (selection.kind === graphql_1.Kind.INLINE_FRAGMENT &&
(!selection.directives || ((_b = selection.directives) === null || _b === void 0 ? void 0 : _b.length) === 0)) {
var fragmentTypeName = selection.typeCondition
? selection.typeCondition.name.value
: null;
if (!fragmentTypeName || fragmentTypeName === selectionSetTypeName) {
outputSelections.push.apply(outputSelections, __spreadArray([], __read(inlineRelevantFragmentSpreads(fragmentDefinitions, selection.selectionSet.selections, selectionSetType)), false));
continue;
}
const fragmentDefinition = fragmentDefinitions[selection.name.value];
if (fragmentDefinition) {
const { typeCondition, directives, selectionSet } = fragmentDefinition;
selection = {
kind: Kind.INLINE_FRAGMENT,
typeCondition,
directives,
selectionSet,
};
}
outputSelections.push(selection);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (selections_1_1 && !selections_1_1.done && (_a = selections_1.return)) _a.call(selections_1);
if (selection.kind === Kind.INLINE_FRAGMENT &&
(!selection.directives || ((_a = selection.directives) === null || _a === void 0 ? void 0 : _a.length) === 0)) {
const fragmentTypeName = selection.typeCondition
? selection.typeCondition.name.value
: null;
if (!fragmentTypeName || fragmentTypeName === selectionSetTypeName) {
outputSelections.push(...inlineRelevantFragmentSpreads(fragmentDefinitions, selection.selectionSet.selections, selectionSetType));
continue;
}
}
finally { if (e_2) throw e_2.error; }
outputSelections.push(selection);
}
return outputSelections;
}
function mergeAst(documentAST, schema) {
var e_3, _a;
var typeInfo = schema ? new graphql_1.TypeInfo(schema) : null;
var fragmentDefinitions = Object.create(null);
try {
for (var _b = __values(documentAST.definitions), _c = _b.next(); !_c.done; _c = _b.next()) {
var definition = _c.value;
if (definition.kind === graphql_1.Kind.FRAGMENT_DEFINITION) {
fragmentDefinitions[definition.name.value] = definition;
}
export function mergeAst(documentAST, schema) {
const typeInfo = schema ? new TypeInfo(schema) : null;
const fragmentDefinitions = Object.create(null);
for (const definition of documentAST.definitions) {
if (definition.kind === Kind.FRAGMENT_DEFINITION) {
fragmentDefinitions[definition.name.value] = definition;
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_3) throw e_3.error; }
}
var visitors = {
SelectionSet: function (node) {
var selectionSetType = typeInfo ? typeInfo.getParentType() : null;
var selections = node.selections;
const visitors = {
SelectionSet(node) {
const selectionSetType = typeInfo ? typeInfo.getParentType() : null;
let { selections } = node;
selections = inlineRelevantFragmentSpreads(fragmentDefinitions, selections, selectionSetType);
selections = uniqueBy(selections, function (selection) {
return selection.alias ? selection.alias.value : selection.name.value;
});
return __assign(__assign({}, node), { selections: selections });
selections = uniqueBy(selections, selection => selection.alias ? selection.alias.value : selection.name.value);
return Object.assign(Object.assign({}, node), { selections });
},
FragmentDefinition: function () {
FragmentDefinition() {
return null;
},
};
return (0, graphql_1.visit)(documentAST, typeInfo ? (0, graphql_1.visitWithTypeInfo)(typeInfo, visitors) : visitors);
return visit(documentAST, typeInfo ? visitWithTypeInfo(typeInfo, visitors) : visitors);
}
exports.mergeAst = mergeAst;
//# sourceMappingURL=merge-ast.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSelectedOperationName = void 0;
function getSelectedOperationName(prevOperations, prevSelectedOperationName, operations) {
export function getSelectedOperationName(prevOperations, prevSelectedOperationName, operations) {
if (!operations || operations.length < 1) {
return;
}
var names = operations.map(function (op) { var _a; return (_a = op.name) === null || _a === void 0 ? void 0 : _a.value; });
const names = operations.map(op => { var _a; return (_a = op.name) === null || _a === void 0 ? void 0 : _a.value; });
if (prevSelectedOperationName && names.includes(prevSelectedOperationName)) {

@@ -13,4 +10,4 @@ return prevSelectedOperationName;

if (prevSelectedOperationName && prevOperations) {
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);
const prevNames = prevOperations.map(op => { var _a; return (_a = op.name) === null || _a === void 0 ? void 0 : _a.value; });
const prevIndex = prevNames.indexOf(prevSelectedOperationName);
if (prevIndex !== -1 && prevIndex < names.length) {

@@ -22,3 +19,2 @@ return names[prevIndex];

}
exports.getSelectedOperationName = getSelectedOperationName;
//# sourceMappingURL=operation-name.js.map

@@ -1,22 +0,6 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = 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) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./async-helpers"), exports);
__exportStar(require("./create-fetcher"), exports);
__exportStar(require("./format"), exports);
__exportStar(require("./graphql-helpers"), exports);
__exportStar(require("./storage"), exports);
export * from './async-helpers';
export * from './create-fetcher';
export * from './format';
export * from './graphql-helpers';
export * from './storage';
//# sourceMappingURL=index.js.map

@@ -1,4 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StorageAPI = void 0;
function isQuotaError(storage, e) {

@@ -12,4 +9,4 @@ return (e instanceof DOMException &&

}
var StorageAPI = (function () {
function StorageAPI(storage) {
export class StorageAPI {
constructor(storage) {
if (storage) {

@@ -30,5 +27,5 @@ this.storage = storage;

get length() {
var keys = 0;
for (var key in window.localStorage) {
if (key.indexOf("".concat(STORAGE_NAMESPACE, ":")) === 0) {
let keys = 0;
for (const key in window.localStorage) {
if (key.indexOf(`${STORAGE_NAMESPACE}:`) === 0) {
keys += 1;

@@ -39,5 +36,5 @@ }

},
clear: function () {
for (var key in window.localStorage) {
if (key.indexOf("".concat(STORAGE_NAMESPACE, ":")) === 0) {
clear() {
for (const key in window.localStorage) {
if (key.indexOf(`${STORAGE_NAMESPACE}:`) === 0) {
window.localStorage.removeItem(key);

@@ -50,8 +47,8 @@ }

}
StorageAPI.prototype.get = function (name) {
get(name) {
if (!this.storage) {
return null;
}
var key = "".concat(STORAGE_NAMESPACE, ":").concat(name);
var value = this.storage.getItem(key);
const key = `${STORAGE_NAMESPACE}:${name}`;
const value = this.storage.getItem(key);
if (value === 'null' || value === 'undefined') {

@@ -62,8 +59,8 @@ this.storage.removeItem(key);

return value || null;
};
StorageAPI.prototype.set = function (name, value) {
var quotaError = false;
var error = null;
}
set(name, value) {
let quotaError = false;
let error = null;
if (this.storage) {
var key = "".concat(STORAGE_NAMESPACE, ":").concat(name);
const key = `${STORAGE_NAMESPACE}:${name}`;
if (value) {

@@ -74,3 +71,3 @@ try {

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

@@ -83,13 +80,11 @@ }

}
return { isQuotaError: quotaError, error: error };
};
StorageAPI.prototype.clear = function () {
return { isQuotaError: quotaError, error };
}
clear() {
if (this.storage) {
this.storage.clear();
}
};
return StorageAPI;
}());
exports.StorageAPI = StorageAPI;
var STORAGE_NAMESPACE = 'graphiql';
}
}
const STORAGE_NAMESPACE = 'graphiql';
//# sourceMappingURL=base.js.map

@@ -1,66 +0,27 @@

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
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));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HistoryStore = void 0;
var graphql_1 = require("graphql");
var query_1 = require("./query");
var MAX_QUERY_SIZE = 100000;
var HistoryStore = (function () {
function HistoryStore(storage, maxHistoryLength) {
var _this = this;
import { parse } from 'graphql';
import { QueryStore } from './query';
const MAX_QUERY_SIZE = 100000;
export class HistoryStore {
constructor(storage, maxHistoryLength) {
this.storage = storage;
this.maxHistoryLength = maxHistoryLength;
this.updateHistory = function (query, variables, headers, operationName) {
if (_this.shouldSaveQuery(query, variables, headers, _this.history.fetchRecent())) {
_this.history.push({
query: query,
variables: variables,
headers: headers,
operationName: operationName,
});
var historyQueries = _this.history.items;
var favoriteQueries = _this.favorite.items;
_this.queries = historyQueries.concat(favoriteQueries);
this.updateHistory = (query, variables, headers, operationName) => {
if (!this.shouldSaveQuery(query, variables, headers, this.history.fetchRecent())) {
return;
}
this.history.push({
query,
variables,
headers,
operationName,
});
const historyQueries = this.history.items;
const favoriteQueries = this.favorite.items;
this.queries = historyQueries.concat(favoriteQueries);
};
this.history = new query_1.QueryStore('queries', this.storage, this.maxHistoryLength);
this.favorite = new query_1.QueryStore('favorites', this.storage, null);
this.queries = __spreadArray(__spreadArray([], __read(this.history.fetchAll()), false), __read(this.favorite.fetchAll()), false);
this.history = new QueryStore('queries', this.storage, this.maxHistoryLength);
this.favorite = new QueryStore('favorites', this.storage, null);
this.queries = [...this.history.fetchAll(), ...this.favorite.fetchAll()];
}
HistoryStore.prototype.shouldSaveQuery = function (query, variables, headers, lastQuerySaved) {
shouldSaveQuery(query, variables, headers, lastQuerySaved) {
if (!query) {

@@ -70,3 +31,3 @@ return false;

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

@@ -96,10 +57,10 @@ catch (_a) {

return true;
};
HistoryStore.prototype.toggleFavorite = function (query, variables, headers, operationName, label, favorite) {
var item = {
query: query,
variables: variables,
headers: headers,
operationName: operationName,
label: label,
}
toggleFavorite(query, variables, headers, operationName, label, favorite) {
const item = {
query,
variables,
headers,
operationName,
label,
};

@@ -114,14 +75,14 @@ if (!this.favorite.contains(item)) {

}
this.queries = __spreadArray(__spreadArray([], __read(this.history.items), false), __read(this.favorite.items), false);
};
HistoryStore.prototype.editLabel = function (query, variables, headers, operationName, label, favorite) {
var item = {
query: query,
variables: variables,
headers: headers,
operationName: operationName,
label: label,
this.queries = [...this.history.items, ...this.favorite.items];
}
editLabel(query, variables, headers, operationName, label, favorite) {
const item = {
query,
variables,
headers,
operationName,
label,
};
if (favorite) {
this.favorite.edit(__assign(__assign({}, item), { favorite: favorite }));
this.favorite.edit(Object.assign(Object.assign({}, item), { favorite }));
}

@@ -131,7 +92,5 @@ else {

}
this.queries = __spreadArray(__spreadArray([], __read(this.history.items), false), __read(this.favorite.items), false);
};
return HistoryStore;
}());
exports.HistoryStore = HistoryStore;
this.queries = [...this.history.items, ...this.favorite.items];
}
}
//# sourceMappingURL=history.js.map

@@ -1,20 +0,4 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = 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) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./base"), exports);
__exportStar(require("./history"), exports);
__exportStar(require("./query"), exports);
export * from './base';
export * from './history';
export * from './query';
//# sourceMappingURL=index.js.map

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

"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
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));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.QueryStore = void 0;
var QueryStore = (function () {
function QueryStore(key, storage, maxSize) {
if (maxSize === void 0) { maxSize = null; }
export class QueryStore {
constructor(key, storage, maxSize = null) {
this.key = key;

@@ -37,24 +8,16 @@ this.storage = storage;

}
Object.defineProperty(QueryStore.prototype, "length", {
get: function () {
return this.items.length;
},
enumerable: false,
configurable: true
});
QueryStore.prototype.contains = function (item) {
return this.items.some(function (x) {
return x.query === item.query &&
x.variables === item.variables &&
x.headers === item.headers &&
x.operationName === item.operationName;
});
};
QueryStore.prototype.edit = function (item) {
var itemIndex = this.items.findIndex(function (x) {
return x.query === item.query &&
x.variables === item.variables &&
x.headers === item.headers &&
x.operationName === item.operationName;
});
get length() {
return this.items.length;
}
contains(item) {
return this.items.some(x => x.query === item.query &&
x.variables === item.variables &&
x.headers === item.headers &&
x.operationName === item.operationName);
}
edit(item) {
const itemIndex = this.items.findIndex(x => x.query === item.query &&
x.variables === item.variables &&
x.headers === item.headers &&
x.operationName === item.operationName);
if (itemIndex !== -1) {

@@ -64,10 +27,8 @@ this.items.splice(itemIndex, 1, item);

}
};
QueryStore.prototype.delete = function (item) {
var itemIndex = this.items.findIndex(function (x) {
return x.query === item.query &&
x.variables === item.variables &&
x.headers === item.headers &&
x.operationName === item.operationName;
});
}
delete(item) {
const itemIndex = this.items.findIndex(x => x.query === item.query &&
x.variables === item.variables &&
x.headers === item.headers &&
x.operationName === item.operationName);
if (itemIndex !== -1) {

@@ -77,8 +38,8 @@ this.items.splice(itemIndex, 1);

}
};
QueryStore.prototype.fetchRecent = function () {
}
fetchRecent() {
return this.items.at(-1);
};
QueryStore.prototype.fetchAll = function () {
var raw = this.storage.get(this.key);
}
fetchAll() {
const raw = this.storage.get(this.key);
if (raw) {

@@ -88,11 +49,10 @@ return JSON.parse(raw)[this.key];

return [];
};
QueryStore.prototype.push = function (item) {
var _a;
var items = __spreadArray(__spreadArray([], __read(this.items), false), [item], false);
}
push(item) {
const items = [...this.items, item];
if (this.maxSize && items.length > this.maxSize) {
items.shift();
}
for (var attempts = 0; attempts < 5; attempts++) {
var response = this.storage.set(this.key, JSON.stringify((_a = {}, _a[this.key] = items, _a)));
for (let attempts = 0; attempts < 5; attempts++) {
const response = this.storage.set(this.key, JSON.stringify({ [this.key]: items }));
if (!(response === null || response === void 0 ? void 0 : response.error)) {

@@ -108,10 +68,7 @@ this.items = items;

}
};
QueryStore.prototype.save = function () {
var _a;
this.storage.set(this.key, JSON.stringify((_a = {}, _a[this.key] = this.items, _a)));
};
return QueryStore;
}());
exports.QueryStore = QueryStore;
}
save() {
this.storage.set(this.key, JSON.stringify({ [this.key]: this.items }));
}
}
//# sourceMappingURL=query.js.map

@@ -32,9 +32,9 @@ # `createGraphiQLFetcher`

```ts
```jsx
import * as React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import { GraphiQL } from 'graphiql';
import { createGraphiQLFetcher } from '@graphiql/toolkit';
const url = 'https://myschema.com/graphql';
const url = 'https://my-schema.com/graphql';

@@ -45,3 +45,4 @@ const fetcher = createGraphiQLFetcher({ url });

ReactDOM.render(document.getElementByID('graphiql'), <App />);
const root = createRoot(document.getElementById('graphiql'));
root.render(<App />);
```

@@ -61,11 +62,11 @@

```ts
```jsx
import * as React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import { GraphiQL } from 'graphiql';
import { createGraphiQLFetcher } from '@graphiql/toolkit';
const url = 'https://myschema.com/graphql';
const url = 'https://my-schema.com/graphql';
const subscriptionUrl = 'wss://myschema.com/graphql';
const subscriptionUrl = 'wss://my-schema.com/graphql';

@@ -79,3 +80,4 @@ const fetcher = createGraphiQLFetcher({

ReactDOM.render(document.getElementByID('graphiql'), <App />);
const root = createRoot(document.getElementById('graphiql'));
root.render(<App />);
```

@@ -108,13 +110,12 @@

```ts
```jsx
const fetcher = createGraphiQLFetcher({
url: "https://localhost:3000",
subscriptionUrl: "https://localhost:3001",
wsConnectionParams: { Authorization: "token 1234" }
})
url: 'https://localhost:3000',
subscriptionUrl: 'https://localhost:3001',
wsConnectionParams: { Authorization: 'token 1234' },
});
const App () {
return <GraphiQL fetcher={fetcher} />
}
const App = () => {
return <GraphiQL fetcher={fetcher} />;
};
```

@@ -143,5 +144,5 @@

```ts
```jsx
import * as React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import { GraphiQL } from 'graphiql';

@@ -151,5 +152,5 @@ import { createClient } from 'graphql-ws';

const url = 'https://myschema.com/graphql';
const url = 'https://my-schema.com/graphql';
const subscriptionUrl = 'wss://myschema.com/graphql';
const subscriptionUrl = 'wss://my-schema.com/graphql';

@@ -166,3 +167,4 @@ const fetcher = createGraphiQLFetcher({

ReactDOM.render(document.getElementByID('graphiql'), <App />);
const root = createRoot(document.getElementById('graphiql'));
root.render(<App />);
```

@@ -177,5 +179,5 @@

```ts
```jsx
import * as React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import { GraphiQL } from 'graphiql';

@@ -185,5 +187,5 @@ import { SubscriptionClient } from 'subscriptions-transport-ws';

const url = 'https://myschema.com/graphql';
const url = 'https://my-schema.com/graphql';
const subscriptionUrl = 'wss://myschema.com/graphql';
const subscriptionUrl = 'wss://my-schema.com/graphql';

@@ -197,3 +199,4 @@ const fetcher = createGraphiQLFetcher({

ReactDOM.render(document.getElementByID('graphiql'), <App />);
const root = createRoot(document.getElementById('graphiql'));
root.render(<App />);
```

@@ -211,5 +214,5 @@

```ts
```jsx
import * as React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import { GraphiQL } from 'graphiql';

@@ -219,3 +222,3 @@ import { fetch } from 'isomorphic-fetch';

const url = 'https://myschema.com/graphql';
const url = 'https://my-schema.com/graphql';

@@ -229,3 +232,4 @@ const fetcher = createGraphiQLFetcher({

ReactDOM.render(document.getElementByID('graphiql'), <App />);
const root = createRoot(document.getElementById('graphiql'));
root.render(<App />);
```

@@ -232,0 +236,0 @@

{
"name": "@graphiql/toolkit",
"version": "0.8.4",
"version": "0.9.0-canary-344df134.0",
"description": "Utility to build a fetcher for GraphiQL",

@@ -18,5 +18,4 @@ "contributors": [

"license": "MIT",
"main": "dist/index.js",
"module": "esm/index.js",
"typings": "dist/index.d.ts",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {},

@@ -23,0 +22,0 @@ "dependencies": {

@@ -20,3 +20,3 @@ import {

const subscription = observable.subscribe({
next: v => {
next(v) {
resolve(v);

@@ -26,3 +26,3 @@ subscription.unsubscribe();

error: reject,
complete: () => {
complete() {
reject(new Error('no value resolved'));

@@ -29,0 +29,0 @@ },

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

url: '',
// @ts-ignore
wsClient: true,

@@ -84,3 +83,2 @@ });

url: '',
// @ts-ignore
legacyClient: true,

@@ -87,0 +85,0 @@ });

@@ -63,3 +63,3 @@ import type { Fetcher, CreateFetcherOptions } from './types';

? `Provided URL ${options.subscriptionUrl} failed`
: `Please provide subscriptionUrl, wsClient or legacyClient option first.`
: 'Please provide subscriptionUrl, wsClient or legacyClient option first.'
}`,

@@ -66,0 +66,0 @@ );

@@ -109,3 +109,3 @@ import { DocumentNode, visit } from 'graphql';

...sink,
error: err => {
error(err) {
if (err instanceof CloseEvent) {

@@ -112,0 +112,0 @@ sink.error(

@@ -24,10 +24,12 @@ import {

it('does not modify query with no fragments', () => {
const query = `
const query = /* GraphQL */ `
query Test {
id
}`;
const mergedQuery = stripWhitespace(`
}
`;
const mergedQuery = stripWhitespace(/* GraphQL */ `
query Test {
id
}`);
}
`);
expect(parseMergeAndPrint(query)).toBe(mergedQuery);

@@ -38,20 +40,23 @@ expect(parseMergeAndPrint(query, schema)).toBe(mergedQuery);

it('does inline simple nested fragment', () => {
const query = `
const query = /* GraphQL */ `
query Test {
...Fragment1
}
fragment Fragment1 on Test {
id
}`;
const mergedQuery = stripWhitespace(`
}
`;
const mergedQuery = stripWhitespace(/* GraphQL */ `
query Test {
...on Test {
... on Test {
id
}
}`);
const mergedQueryWithSchema = stripWhitespace(`
}
`);
const mergedQueryWithSchema = stripWhitespace(/* GraphQL */ `
query Test {
id
}`);
}
`);
expect(parseMergeAndPrint(query)).toBe(mergedQuery);

@@ -62,23 +67,24 @@ expect(parseMergeAndPrint(query, schema)).toBe(mergedQueryWithSchema);

it('does inline triple nested fragment', () => {
const query = `
const query = /* GraphQL */ `
query Test {
...Fragment1
}
fragment Fragment1 on Test {
...Fragment2
}
fragment Fragment2 on Test {
...Fragment3
}
fragment Fragment3 on Test {
id
}`;
const mergedQuery = stripWhitespace(`
}
`;
const mergedQuery = stripWhitespace(/* GraphQL */ `
query Test {
...on Test {
...on Test {
...on Test {
... on Test {
... on Test {
... on Test {
id

@@ -88,7 +94,9 @@ }

}
}`);
const mergedQueryWithSchema = stripWhitespace(`
}
`);
const mergedQueryWithSchema = stripWhitespace(/* GraphQL */ `
query Test {
id
}`);
}
`);
expect(parseMergeAndPrint(query)).toBe(mergedQuery);

@@ -99,3 +107,3 @@ expect(parseMergeAndPrint(query, schema)).toBe(mergedQueryWithSchema);

it('does inline multiple fragments', () => {
const query = `
const query = /* GraphQL */ `
query Test {

@@ -106,30 +114,33 @@ ...Fragment1

}
fragment Fragment1 on Test {
id
}
fragment Fragment2 on Test {
id
}
fragment Fragment3 on Test {
id
}`;
const mergedQuery = stripWhitespace(`
}
`;
const mergedQuery = stripWhitespace(/* GraphQL */ `
query Test {
...on Test {
... on Test {
id
}
...on Test {
... on Test {
id
}
...on Test {
... on Test {
id
}
}`);
const mergedQueryWithSchema = stripWhitespace(`
}
`);
const mergedQueryWithSchema = stripWhitespace(/* GraphQL */ `
query Test {
id
}`);
}
`);
expect(parseMergeAndPrint(query)).toBe(mergedQuery);

@@ -140,3 +151,3 @@ expect(parseMergeAndPrint(query, schema)).toBe(mergedQueryWithSchema);

it('removes duplicate fragment spreads', () => {
const query = `
const query = /* GraphQL */ `
query Test {

@@ -146,16 +157,19 @@ ...Fragment1

}
fragment Fragment1 on Test {
id
}`;
const mergedQuery = stripWhitespace(`
}
`;
const mergedQuery = stripWhitespace(/* GraphQL */ `
query Test {
...on Test {
... on Test {
id
}
}`);
const mergedQueryWithSchema = stripWhitespace(`
}
`);
const mergedQueryWithSchema = stripWhitespace(/* GraphQL */ `
query Test {
id
}`);
}
`);
expect(parseMergeAndPrint(query)).toBe(mergedQuery);

@@ -162,0 +176,0 @@ expect(parseMergeAndPrint(query, schema)).toBe(mergedQueryWithSchema);

@@ -160,6 +160,3 @@ import {

// comes from an origin parameter
selectionSet: buildSelectionSet(
fieldType as GraphQLOutputType,
getDefaultFieldNames,
),
selectionSet: buildSelectionSet(fieldType!, getDefaultFieldNames),
};

@@ -166,0 +163,0 @@ }),

@@ -75,3 +75,3 @@ import { StorageAPI } from '../base';

const throwingStorage = new StorageAPI({
setItem: () => {
setItem() {
throw new DOMException('Terrible Error');

@@ -90,3 +90,3 @@ },

const throwingStorage = new StorageAPI({
setItem: () => {
setItem() {
throw new DOMException('Terrible Error', 'QuotaExceededError');

@@ -93,0 +93,0 @@ },

@@ -7,7 +7,6 @@ import { StorageAPI } from '../base';

count: number;
map: any;
map = {};
storage: Storage;
constructor(shouldThrow: () => boolean) {
this.shouldThrow = shouldThrow;
this.map = {};
}

@@ -103,3 +102,3 @@

shouldThrow = () => retryCounter < 3;
store.push({ query: `finalItem` });
store.push({ query: 'finalItem' });

@@ -136,3 +135,3 @@ expect(store.items.length).toBe(8);

shouldThrow = () => true;
store.push({ query: `finalItem` });
store.push({ query: 'finalItem' });

@@ -139,0 +138,0 @@ expect(store.items.length).toBe(10);

@@ -81,3 +81,3 @@ /**

clear: () => {
clear() {
// We only want to clear the namespaced items

@@ -84,0 +84,0 @@ for (const key in window.localStorage) {

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

constructor(private storage: StorageAPI, private maxHistoryLength: number) {
constructor(
private storage: StorageAPI,
private maxHistoryLength: number,
) {
this.history = new QueryStore(

@@ -76,3 +79,3 @@ 'queries',

if (
this.shouldSaveQuery(
!this.shouldSaveQuery(
query,

@@ -84,12 +87,13 @@ variables,

) {
this.history.push({
query,
variables,
headers,
operationName,
});
const historyQueries = this.history.items;
const favoriteQueries = this.favorite.items;
this.queries = historyQueries.concat(favoriteQueries);
return;
}
this.history.push({
query,
variables,
headers,
operationName,
});
const historyQueries = this.history.items;
const favoriteQueries = this.favorite.items;
this.queries = historyQueries.concat(favoriteQueries);
};

@@ -96,0 +100,0 @@

{
"extends": "../../resources/tsconfig.base.cjs.json",
"extends": "../../resources/tsconfig.base.json",
"compilerOptions": {

@@ -8,5 +8,4 @@ "rootDir": "./src",

"jsx": "react",
"target": "es5",
"baseUrl": ".",
"strictPropertyInitialization": false
"strictPropertyInitialization": false,
"baseUrl": "."
},

@@ -20,7 +19,4 @@ "include": ["src"],

"**/*-test.ts",
"**/*-test.js",
"**/*.stories.js",
"**/*.stories.ts",
"**/*.stories.tsx"
"**/*-test.js"
]
}

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