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.11.0-canary-3bb4b14b.0 to 0.11.0

vitest.config.mts

6

CHANGELOG.md
# @graphiql/toolkit
## 0.11.0-canary-3bb4b14b.0
## 0.11.0
### Minor Changes
- [#3747](https://github.com/graphql/graphiql/pull/3747) [`2b175f5`](https://github.com/graphql/graphiql/commit/2b175f5f17a8424f72c2fbb26ad4bc50244e677c) Thanks [@dimaMachina](https://github.com/dimaMachina)! - do not include `require` statements in ESM build, include `import` in esm and `require` in cjs builds
- [#3747](https://github.com/graphql/graphiql/pull/3747) [`21c4409`](https://github.com/graphql/graphiql/commit/21c44096c0c0b23cea955a574d1110cb19ab6405) Thanks [@dimaMachina](https://github.com/dimaMachina)! - do not include `require` statements in ESM build, include `import` in esm and `require` in cjs builds
make `getWsFetcher`, `createWebsocketsFetcherFromUrl` async
- [#3746](https://github.com/graphql/graphiql/pull/3746) [`2ad4e75`](https://github.com/graphql/graphiql/commit/2ad4e7505385fefd252b9aa8ea2233cbaeca7f6a) Thanks [@dimaMachina](https://github.com/dimaMachina)! - compile with `tsup` instead of `tsc`
## 0.10.0

@@ -12,0 +14,0 @@

{
"name": "@graphiql/toolkit",
"version": "0.11.0-canary-3bb4b14b.0",
"version": "0.11.0",
"description": "Utility to build a fetcher for GraphiQL",

@@ -25,3 +25,4 @@ "contributors": [

"prebuild": "yarn types:check",
"types:check": "tsc --noEmit"
"types:check": "tsc --noEmit",
"test": "vitest run"
},

@@ -28,0 +29,0 @@ "dependencies": {

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

import { Mock } from 'vitest';
import { parse, getIntrospectionQuery } from 'graphql';

@@ -6,16 +7,16 @@ import { createGraphiQLFetcher } from '../createFetcher';

jest.mock('../lib');
vi.mock('../lib');
jest.mock('graphql-ws');
vi.mock('graphql-ws');
jest.mock('subscriptions-transport-ws');
vi.mock('subscriptions-transport-ws');
import {
createWebsocketsFetcherFromUrl,
createMultipartFetcher,
createSimpleFetcher,
createWebsocketsFetcherFromClient,
createLegacyWebsocketsFetcher,
createWebsocketsFetcherFromUrl as _createWebsocketsFetcherFromUrl,
createMultipartFetcher as _createMultipartFetcher,
createSimpleFetcher as _createSimpleFetcher,
createWebsocketsFetcherFromClient as _createWebsocketsFetcherFromClient,
createLegacyWebsocketsFetcher as _createLegacyWebsocketsFetcher,
} from '../lib';
import { createClient } from 'graphql-ws';
import { createClient as _createClient } from 'graphql-ws';
import { SubscriptionClient } from 'subscriptions-transport-ws';

@@ -28,7 +29,26 @@

const createWebsocketsFetcherFromUrl = _createWebsocketsFetcherFromUrl as Mock<
typeof _createWebsocketsFetcherFromUrl
>;
const createMultipartFetcher = _createMultipartFetcher as Mock<
typeof _createMultipartFetcher
>;
const createSimpleFetcher = _createSimpleFetcher as Mock<
typeof _createSimpleFetcher
>;
const createClient = _createClient as Mock<typeof _createClient>;
const createWebsocketsFetcherFromClient =
_createWebsocketsFetcherFromClient as Mock<
typeof _createWebsocketsFetcherFromClient
>;
const createLegacyWebsocketsFetcher = _createLegacyWebsocketsFetcher as Mock<
typeof _createLegacyWebsocketsFetcher
>;
describe('createGraphiQLFetcher', () => {
afterEach(() => {
jest.resetAllMocks();
vi.resetAllMocks();
});
it('returns fetcher without websocket client by default', () => {
// @ts-expect-error
createWebsocketsFetcherFromUrl.mockReturnValue(true);

@@ -43,2 +63,3 @@ createGraphiQLFetcher({ url: serverURL });

it('returns simple fetcher for introspection', async () => {
// @ts-expect-error
createSimpleFetcher.mockReturnValue(async () => 'hey!');

@@ -60,2 +81,3 @@ const fetcher = createGraphiQLFetcher({ url: serverURL });

it('returns fetcher without websocket client or multipart', () => {
// @ts-expect-error
createWebsocketsFetcherFromUrl.mockReturnValue(true);

@@ -70,2 +92,3 @@ createGraphiQLFetcher({ url: serverURL, enableIncrementalDelivery: false });

it('returns fetcher with websocket client', () => {
// @ts-expect-error
createWebsocketsFetcherFromUrl.mockReturnValue('Client1');

@@ -85,3 +108,5 @@

it('returns fetcher with custom wsClient', () => {
// @ts-expect-error
createClient.mockReturnValue('WSClient');
// @ts-expect-error
createWebsocketsFetcherFromUrl.mockReturnValue('CustomWSSFetcher');

@@ -103,3 +128,5 @@

it('returns fetcher with custom legacyClient', () => {
// @ts-expect-error
createClient.mockReturnValue('WSClient');
// @ts-expect-error
createLegacyWebsocketsFetcher.mockReturnValue('CustomWSSFetcher');

@@ -106,0 +133,0 @@

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

import { Mock } from 'vitest';
import { parse } from 'graphql';

@@ -10,10 +11,13 @@ import {

jest.mock('graphql-ws');
vi.mock('graphql-ws');
jest.mock('subscriptions-transport-ws');
vi.mock('subscriptions-transport-ws');
import { createClient } from 'graphql-ws';
import { createClient as _createClient } from 'graphql-ws';
import { SubscriptionClient } from 'subscriptions-transport-ws';
import { SubscriptionClient as _SubscriptionClient } from 'subscriptions-transport-ws';
const createClient = _createClient as Mock<typeof _createClient>;
const SubscriptionClient = _SubscriptionClient as Mock;
const exampleWithSubscription = parse(/* GraphQL */ `

@@ -48,9 +52,9 @@ subscription Example {

afterEach(() => {
jest.resetAllMocks();
vi.resetAllMocks();
});
it('creates a websockets client using provided url', async () => {
// @ts-expect-error
createClient.mockReturnValue(true);
await createWebsocketsFetcherFromUrl('wss://example.com');
// @ts-ignore
expect(createClient.mock.calls[0][0]).toEqual({ url: 'wss://example.com' });

@@ -60,5 +64,5 @@ });

it('creates a websockets client using provided url that fails', async () => {
// @ts-expect-error
createClient.mockReturnValue(false);
expect(await createWebsocketsFetcherFromUrl('wss://example.com')).toThrow();
// @ts-ignore
expect(createClient.mock.calls[0][0]).toEqual({ url: 'wss://example.com' });

@@ -70,14 +74,15 @@ });

afterEach(() => {
jest.resetAllMocks();
vi.resetAllMocks();
});
it('provides an observable wsClient when custom wsClient option is provided', async () => {
// @ts-expect-error
createClient.mockReturnValue(true);
// @ts-expect-error
await getWsFetcher({ url: '', wsClient: true });
// @ts-ignore
expect(createClient.mock.calls).toHaveLength(0);
});
it('creates a subscriptions-transports-ws observable when custom legacyClient option is provided', async () => {
// @ts-expect-error
createClient.mockReturnValue(true);
await getWsFetcher({ url: '', legacyClient: true });
// @ts-ignore
expect(createClient.mock.calls).toHaveLength(0);

@@ -88,2 +93,3 @@ expect(SubscriptionClient.mock.calls).toHaveLength(0);

it('if subscriptionsUrl is provided, create a client on the fly', async () => {
// @ts-expect-error
createClient.mockReturnValue(true);

@@ -100,6 +106,13 @@ await getWsFetcher({ url: '', subscriptionUrl: 'wss://example' });

it('should throw a nice error', async () => {
jest.resetModules();
jest.doMock('graphql-ws', () => {
// eslint-disable-next-line no-throw-literal
throw { code: 'MODULE_NOT_FOUND' };
vi.resetModules();
vi.doMock('graphql-ws', () => {
// While throwing an error directly inside this callback `code` is attached in `cause`
// property e.g. `Error.cause.code`, so I throw an error on calling `createClient` instead
return {
createClient: vi.fn().mockImplementation(() => {
// eslint-disable-next-line no-throw-literal
throw { code: 'MODULE_NOT_FOUND' };
}),
};
});

@@ -106,0 +119,0 @@

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

it('returns any error while setting a value', () => {
// @ts-ignore
// @ts-expect-error
const throwingStorage = new StorageAPI({

@@ -83,3 +83,3 @@ setItem() {

expect(result.error.message).toEqual('Terrible Error');
expect(result.error!.message).toEqual('Error: Terrible Error');
expect(result.isQuotaError).toBe(false);

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

it('returns isQuotaError to true if isQuotaError is thrown', () => {
// @ts-ignore
// @ts-expect-error
const throwingStorage = new StorageAPI({

@@ -99,5 +99,5 @@ setItem() {

expect(result.error.message).toEqual('Terrible Error');
expect(result.error!.message).toEqual('QuotaExceededError: Terrible Error');
expect(result.isQuotaError).toBe(true);
});
});

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

shouldThrow: () => boolean;
// @ts-expect-error
count: number;
map = {};
// @ts-expect-error
storage: Storage;
constructor(shouldThrow: () => boolean) {

@@ -23,3 +26,3 @@ this.shouldThrow = shouldThrow;

}
// @ts-expect-error
this.map[key] = value;

@@ -34,2 +37,3 @@

get(key: string) {
// @ts-expect-error
return this.map[key] || null;

@@ -53,2 +57,3 @@ }

let i = 0;
// @ts-expect-error
const store = new QueryStore('normal', new StorageMock(() => i > 4));

@@ -85,2 +90,3 @@

'normal',
// @ts-expect-error
new StorageMock(() => {

@@ -118,2 +124,3 @@ retryCounter++;

'normal',
// @ts-expect-error
new StorageMock(() => {

@@ -120,0 +127,0 @@ retryCounter++;

@@ -12,6 +12,6 @@ {

"lib": ["es2022", "dom"],
"moduleResolution": "node"
"moduleResolution": "node",
"types": ["vitest/globals"]
},
"include": ["src", "tsup.config.ts"],
"exclude": ["**/*.spec.ts"]
"include": ["src", "tsup.config.ts", "vitest.config.mts"]
}
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