Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate @graphiql/toolkit to tsup #3746

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
aa
  • Loading branch information
dimaMachina committed Aug 23, 2024
commit 9da88f310f33efeb4012ca1f038c7f449a1ccdec
5 changes: 5 additions & 0 deletions .changeset/silent-ghosts-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphiql/toolkit': minor
---

compile with `tsup` instead of `tsc`
10 changes: 2 additions & 8 deletions packages/graphiql-toolkit/docs/create-fetcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ const url = 'https://my-schema.com/graphql';

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

const fetcher = createGraphiQLFetcher({
url,
subscriptionUrl,
});
const fetcher = createGraphiQLFetcher({ url, subscriptionUrl });

export const App = () => <GraphiQL fetcher={fetcher} />;

Expand Down Expand Up @@ -209,10 +206,7 @@ import { createGraphiQLFetcher } from '@graphiql/toolkit';

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

const fetcher = createGraphiQLFetcher({
url,
fetch,
});
const fetcher = createGraphiQLFetcher({ url, fetch });

export const App = () => <GraphiQL fetcher={fetcher} />;

Expand Down
16 changes: 11 additions & 5 deletions packages/graphiql-toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
"url": "https://github.com/graphql/graphiql/issues?q=issue+label:@graphiql/toolkit"
},
"license": "MIT",
"main": "dist/index.js",
"module": "esm/index.js",
"typings": "dist/index.d.ts",
"scripts": {},
"main": "dist/cjs/index.js",
"module": "dist/esm/index.mjs",
"typings": "dist/esm/index.d.mts",
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"prebuild": "yarn types:check",
"types:check": "tsc --noEmit"
},
"dependencies": {
"@n1ru4l/push-pull-async-iterable-iterator": "^3.1.0",
"meros": "^1.1.4"
Expand All @@ -27,7 +32,8 @@
"graphql": "^17.0.0-alpha.7",
"graphql-ws": "^5.5.5",
"isomorphic-fetch": "^3.0.0",
"subscriptions-transport-ws": "0.11.0"
"subscriptions-transport-ws": "0.11.0",
"tsup": "^8.2.4"
},
"peerDependencies": {
"graphql": "^15.5.0 || ^16.0.0 || ^17.0.0-alpha.2",
Expand Down
15 changes: 3 additions & 12 deletions packages/graphiql-toolkit/src/create-fetcher/__tests__/lib.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,21 @@ describe('getWsFetcher', () => {
});
it('provides an observable wsClient when custom wsClient option is provided', () => {
createClient.mockReturnValue(true);
getWsFetcher({
url: '',
wsClient: true,
});
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', () => {
createClient.mockReturnValue(true);
getWsFetcher({
url: '',
legacyClient: true,
});
getWsFetcher({ url: '', legacyClient: true });
// @ts-ignore
expect(createClient.mock.calls).toHaveLength(0);
expect(SubscriptionClient.mock.calls).toHaveLength(0);
});

it('if subscriptionsUrl is provided, create a client on the fly', () => {
createClient.mockReturnValue(true);
getWsFetcher({
url: '',
subscriptionUrl: 'wss://example',
});
getWsFetcher({ url: '', subscriptionUrl: 'wss://example' });
expect(createClient.mock.calls[0]).toEqual([
{ connectionParams: {}, url: 'wss://example' },
]);
Expand Down
20 changes: 4 additions & 16 deletions packages/graphiql-toolkit/src/create-fetcher/createFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,15 @@ import {
* build a GraphiQL fetcher that is:
* - backwards compatible
* - optionally supports graphql-ws or `
*
* @param options {CreateFetcherOptions}
* @returns {Fetcher}
*/
export function createGraphiQLFetcher(options: CreateFetcherOptions): Fetcher {
let httpFetch;
if (typeof window !== 'undefined' && window.fetch) {
httpFetch = window.fetch;
}
if (
options?.enableIncrementalDelivery === null ||
options.enableIncrementalDelivery !== false
) {
options.enableIncrementalDelivery = true;
}
if (options.fetch) {
httpFetch = options.fetch;
}
const httpFetch =
options.fetch || (typeof window !== 'undefined' && window.fetch);
if (!httpFetch) {
throw new Error('No valid fetcher implementation available');
}
options.enableIncrementalDelivery =
options.enableIncrementalDelivery !== false;
Comment on lines -19 to +22
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplified these parts

// simpler fetcher for schema requests
const simpleFetcher = createSimpleFetcher(options, httpFetch);

Expand Down
22 changes: 6 additions & 16 deletions packages/graphiql-toolkit/src/create-fetcher/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const errorHasCode = (err: unknown): err is { code: string } => {
*/
export const isSubscriptionWithName = (
document: DocumentNode,
name: string | undefined,
name?: string,
): boolean => {
let isSubscription = false;
visit(document, {
Expand Down Expand Up @@ -97,12 +97,10 @@ export const createWebsocketsFetcherFromUrl = (

/**
* Create ws/s fetcher using provided wsClient implementation
*
* @param wsClient {Client}
* @returns {Fetcher}
*/
export const createWebsocketsFetcherFromClient =
(wsClient: Client) => (graphQLParams: FetcherParams) =>
(wsClient: Client): Fetcher =>
(graphQLParams: FetcherParams) =>
makeAsyncIterableIteratorFromSink<ExecutionResult>(sink =>
wsClient.subscribe(graphQLParams, {
...sink,
Expand All @@ -125,12 +123,9 @@ export const createWebsocketsFetcherFromClient =
/**
* Allow legacy websockets protocol client, but no definitions for it,
* as the library is deprecated and has security issues
*
* @param legacyWsClient
* @returns
*/
export const createLegacyWebsocketsFetcher =
(legacyWsClient: { request: (params: FetcherParams) => unknown }) =>
(legacyWsClient: { request: (params: FetcherParams) => unknown }): Fetcher =>
(graphQLParams: FetcherParams) => {
const observable = legacyWsClient.request(graphQLParams);
return makeAsyncIterableIteratorFromSink<ExecutionResult>(
Expand All @@ -139,11 +134,8 @@ export const createLegacyWebsocketsFetcher =
);
};
/**
* create a fetcher with the `IncrementalDelivery` HTTP/S spec for
* Create a fetcher with the `IncrementalDelivery` HTTP/S spec for
* `@stream` and `@defer` support using `fetch-multipart-graphql`
*
* @param options {CreateFetcherOptions}
* @returns {Fetcher}
*/
export const createMultipartFetcher = (
options: CreateFetcherOptions,
Expand Down Expand Up @@ -187,13 +179,11 @@ export const createMultipartFetcher = (

/**
* If `wsClient` or `legacyClient` are provided, then `subscriptionUrl` is overridden.
* @param options {CreateFetcherOptions}
* @returns
*/
export const getWsFetcher = (
options: CreateFetcherOptions,
fetcherOpts: FetcherOpts | undefined,
) => {
): Fetcher | void => {
if (options.wsClient) {
return createWebsocketsFetcherFromClient(options.wsClient);
}
Expand Down
20 changes: 0 additions & 20 deletions packages/graphiql-toolkit/tsconfig.esm.json

This file was deleted.

29 changes: 12 additions & 17 deletions packages/graphiql-toolkit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
{
"extends": "../../resources/tsconfig.base.cjs.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
"composite": true,
"jsx": "react",
"target": "es5",
"baseUrl": ".",
"strictPropertyInitialization": false
"target": "es2016",
"module": "ESNext",
"declaration": true,
"noEmit": true,
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"allowJs": true,
"lib": ["es2022", "dom"],
"moduleResolution": "node"
},
"include": ["src"],
"exclude": [
"**/__tests__/**",
"**/dist/**.*",
"**/*.spec.ts",
"**/*.spec.js",
"**/*-test.ts",
"**/*-test.js"
]
"include": ["src", "tsup.config.ts"],
"exclude": ["**/*.spec.ts"]
}
21 changes: 21 additions & 0 deletions packages/graphiql-toolkit/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { defineConfig, Options } from 'tsup';

const opts: Options = {
entry: ['src/**/*.ts', '!**/__tests__'],
bundle: false,
clean: true,
dts: true,
};

export default defineConfig([
{
...opts,
format: 'esm',
outDir: 'dist/esm',
},
{
...opts,
format: 'cjs',
outDir: 'dist/cjs',
},
]);
3 changes: 0 additions & 3 deletions packages/graphiql/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
{
"path": "../codemirror-graphql"
},
{
"path": "../graphiql-toolkit"
},
{
"path": "../graphql-language-service"
}
Expand Down
3 changes: 0 additions & 3 deletions packages/graphiql/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
"include": ["src"],
"exclude": ["**/__tests__/**", "**/dist/**.*", "cypress/**"],
"references": [
{
"path": "../graphiql-toolkit"
},
{
"path": "../codemirror-graphql"
},
Expand Down
3 changes: 0 additions & 3 deletions resources/tsconfig.build.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"files": [],
"include": [],
"references": [
{
"path": "../packages/graphiql-toolkit"
},
{
"path": "../packages/monaco-graphql"
},
Expand Down
3 changes: 0 additions & 3 deletions resources/tsconfig.build.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"files": [],
"include": [],
"references": [
{
"path": "../packages/graphiql-toolkit/tsconfig.esm.json"
},
{
"path": "../packages/cm6-graphql/tsconfig.esm.json"
},
Expand Down