From 4f641f2f2534090f8c0ad0d82a64a970a4ab51f2 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Thu, 23 Mar 2023 19:07:13 +0000 Subject: [PATCH 01/14] Replace graphql with @0no-co/graphql.web dependency --- packages/core/package.json | 7 +------ pnpm-lock.yaml | 14 +++++++++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 8d3dbb5ce7..3f4bb7e911 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -52,13 +52,8 @@ "prepare": "node ../../scripts/prepare/index.js", "prepublishOnly": "run-s clean build" }, - "devDependencies": { - "graphql": "^16.0.0" - }, - "peerDependencies": { - "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0" - }, "dependencies": { + "@0no-co/graphql.web": "^0.1.6", "wonka": "^6.1.2" }, "publishConfig": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f313512613..fdbe7abe1c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -253,12 +253,11 @@ importers: packages/core: specifiers: - graphql: ^16.6.0 + '@0no-co/graphql.web': ^0.1.6 wonka: ^6.2.4 dependencies: + '@0no-co/graphql.web': 0.1.6 wonka: 6.2.4 - devDependencies: - graphql: 16.6.0 packages/introspection: specifiers: @@ -468,6 +467,10 @@ importers: packages: + /@0no-co/graphql.web/0.1.6: + resolution: {integrity: sha512-HUFsLTSjX6sTdK+CyoHNs71h0HneugTO6nQS8WwxFGarmAh3doKwZRVY39xLkdOmneSKJZIHRysjf+odHHBFhw==} + dev: false + /@actions/artifact/1.1.1: resolution: {integrity: sha512-Vv4y0EW0ptEkU+Pjs5RGS/0EryTvI6s79LjSV9Gg/h+O3H/ddpjhuX/Bi/HZE4pbNPyjGtQjbdFWphkZhmgabA==} dependencies: @@ -9702,6 +9705,8 @@ packages: /match-sorter/3.1.1: resolution: {integrity: sha512-Qlox3wRM/Q4Ww9rv1cBmYKNJwWVX/WC+eA3+1S3Fv4EOhrqyp812ZEfVFKQk0AP6RfzmPUUOwEZBbJ8IRt8SOw==} + dependencies: + remove-accents: 0.4.2 bundledDependencies: - remove-accents @@ -12696,6 +12701,9 @@ packages: unified: 8.4.2 dev: false + /remove-accents/0.4.2: + resolution: {integrity: sha512-7pXIJqJOq5tFgG1A2Zxti3Ht8jJF337m4sowbuHsW30ZnkQFnDzy9qBNhgzX8ZLW4+UBcXiiR7SwR6pokHsxiA==} + /remove-trailing-separator/1.1.0: resolution: {integrity: sha512-/hS+Y0u3aOfIETiaiirUFwDBDzmXPvO+jAfKTitUngIPzdKc6Z0LoFjM/CK5PL4C+eKwHohlHAb6H0VFfmmUsw==} From 67e28c877bbc91538ba46a526c7b272f40220c8e Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Thu, 23 Mar 2023 19:07:40 +0000 Subject: [PATCH 02/14] Add graphql shim types --- packages/core/src/types.ts | 26 +++++++++++++++++++++----- packages/core/src/utils/graphql.ts | 22 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 packages/core/src/utils/graphql.ts diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 0e91e575ef..ee8dab33c6 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -1,4 +1,8 @@ -import type { GraphQLError, DocumentNode, DefinitionNode } from 'graphql'; +import type { + GraphQLError, + DocumentNode, + DefinitionNode, +} from './utils/graphql'; import { Subscription, Source } from 'wonka'; import { Client } from './client'; import { CombinedError } from './utils/error'; @@ -22,10 +26,10 @@ import { CombinedError } from './utils/error'; * * @see {@link https://github.com/dotansimha/graphql-typed-document-node} for more information. */ -export interface TypedDocumentNode< +export type TypedDocumentNode< Result = { [key: string]: any }, Variables = { [key: string]: any } -> extends DocumentNode { +> = DocumentNode & { /** GraphQL.js Definition Nodes of the `DocumentNode`. */ readonly definitions: ReadonlyArray; /** Type to support `@graphql-typed-document-node/core` @@ -36,12 +40,24 @@ export interface TypedDocumentNode< * @internal */ __ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result; -} +}; + +/** Any GraphQL `DocumentNode` or query string input. + * + * @remarks + * Wherever any `urql` bindings or API expect a query, it accepts either a query string, + * a `DocumentNode`, or a {@link TypedDocumentNode}. + */ +export type DocumentInput< + Result = { [key: string]: any }, + Variables = { [key: string]: any } +> = string | DocumentNode | TypedDocumentNode; /** A list of errors on {@link ExecutionResult | ExecutionResults}. * @see {@link https://spec.graphql.org/draft/#sec-Errors.Error-Result-Format} for the GraphQL Error Result format spec. */ -type ErrorLike = Partial | Error; +export type ErrorLike = Partial | Error; + /** Extensions which may be placed on {@link ExecutionResult | ExecutionResults}. * @see {@link https://spec.graphql.org/draft/#sel-EAPHJCAACCoGu9J} for the GraphQL Error Result format spec. */ diff --git a/packages/core/src/utils/graphql.ts b/packages/core/src/utils/graphql.ts new file mode 100644 index 0000000000..9975c6797d --- /dev/null +++ b/packages/core/src/utils/graphql.ts @@ -0,0 +1,22 @@ +import type * as GraphQLWeb from '@0no-co/graphql.web'; +import type * as GraphQL from 'graphql'; + +type OrNever = 0 extends 1 & T ? never : T; + +export type FieldNode = GraphQLWeb.FieldNode | OrNever; + +export type InlineFragmentNode = + | GraphQLWeb.InlineFragmentNode + | OrNever; + +export type GraphQLError = + | GraphQLWeb.GraphQLError + | OrNever; + +export type DocumentNode = + | GraphQLWeb.DocumentNode + | OrNever; + +export type DefinitionNode = + | GraphQLWeb.DefinitionNode + | OrNever; From 3439ca931419302444a8fc175ebe38d64f0bad45 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Thu, 23 Mar 2023 19:08:02 +0000 Subject: [PATCH 03/14] Add ts-ignore pragma to graphql imports --- scripts/rollup/cleanup-plugin.mjs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/rollup/cleanup-plugin.mjs b/scripts/rollup/cleanup-plugin.mjs index 7a7b1eb99f..9cb659f714 100644 --- a/scripts/rollup/cleanup-plugin.mjs +++ b/scripts/rollup/cleanup-plugin.mjs @@ -24,6 +24,7 @@ function removeEmptyImports({ types: t }) { function cleanup() { const emptyImportRe = /import\s+(?:'[^']+'|"[^"]+")\s*;?/g; + const gqlImportRe = /(import\s+(?:[*\s{}\w\d]+)\s*from\s*'graphql';?)/g; const jsFilter = createFilter(/.m?js$/, null, { resolve: false }); const dtsFilter = createFilter(/\.d\.ts(\.map)?$/, null, { resolve: false }); @@ -37,7 +38,9 @@ function cleanup() { babelrc: false }); } else if (dtsFilter(chunk.fileName)) { - return code.replace(emptyImportRe, ''); + return code + .replace(emptyImportRe, '') + .replace(gqlImportRe, x => '/*!@ts-ignore*/\n' + x); } }, }; From d329d82bf421a461a5c70d174ca226d3d03cb941 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Thu, 23 Mar 2023 19:08:42 +0000 Subject: [PATCH 04/14] Update GraphQL types and imports --- packages/core/src/client.test.ts | 2 +- packages/core/src/client.ts | 12 +++++------ packages/core/src/exchanges/ssr.ts | 2 +- packages/core/src/gql.test.ts | 2 +- packages/core/src/gql.ts | 3 ++- packages/core/src/utils/error.ts | 5 +++-- packages/core/src/utils/request.test.ts | 2 +- packages/core/src/utils/request.ts | 26 +++++++---------------- packages/core/src/utils/typenames.test.ts | 2 +- packages/core/src/utils/typenames.ts | 10 +++------ 10 files changed, 26 insertions(+), 40 deletions(-) diff --git a/packages/core/src/client.test.ts b/packages/core/src/client.test.ts index 0963d0e5dd..8137225a02 100755 --- a/packages/core/src/client.test.ts +++ b/packages/core/src/client.test.ts @@ -1,4 +1,4 @@ -import { print } from 'graphql'; +import { print } from '@0no-co/graphql.web'; import { vi, expect, it, beforeEach, describe, afterEach } from 'vitest'; /** NOTE: Testing in this file is designed to test both the client and its interaction with default Exchanges */ diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts index 296c2eddbe..ceea9509a5 100755 --- a/packages/core/src/client.ts +++ b/packages/core/src/client.ts @@ -22,13 +22,11 @@ import { Subscription, } from 'wonka'; -import { DocumentNode } from 'graphql'; - import { composeExchanges } from './exchanges'; import { fallbackExchange } from './exchanges/fallback'; import { - TypedDocumentNode, + DocumentInput, AnyVariables, Exchange, ExchangeInput, @@ -358,7 +356,7 @@ export interface Client { * ``` */ query( - query: DocumentNode | TypedDocumentNode | string, + query: DocumentInput, variables: Variables, context?: Partial ): OperationResultSource>; @@ -384,7 +382,7 @@ export interface Client { * or asynchronously. */ readQuery( - query: DocumentNode | TypedDocumentNode | string, + query: DocumentInput, variables: Variables, context?: Partial ): OperationResult | null; @@ -450,7 +448,7 @@ export interface Client { * ``` */ subscription( - query: DocumentNode | TypedDocumentNode | string, + query: DocumentInput, variables: Variables, context?: Partial ): OperationResultSource>; @@ -519,7 +517,7 @@ export interface Client { * ``` */ mutation( - query: DocumentNode | TypedDocumentNode | string, + query: DocumentInput, variables: Variables, context?: Partial ): OperationResultSource>; diff --git a/packages/core/src/exchanges/ssr.ts b/packages/core/src/exchanges/ssr.ts index 7f5da38c01..e36dd0e76c 100644 --- a/packages/core/src/exchanges/ssr.ts +++ b/packages/core/src/exchanges/ssr.ts @@ -1,4 +1,4 @@ -import { GraphQLError } from 'graphql'; +import type { GraphQLError } from '../utils/graphql'; import { pipe, filter, merge, map, tap } from 'wonka'; import { Exchange, OperationResult, Operation } from '../types'; import { addMetadata, CombinedError } from '../utils'; diff --git a/packages/core/src/gql.test.ts b/packages/core/src/gql.test.ts index 3dfc32637d..5c0ffcf627 100644 --- a/packages/core/src/gql.test.ts +++ b/packages/core/src/gql.test.ts @@ -1,4 +1,4 @@ -import { parse, print } from 'graphql'; +import { parse, print } from '@0no-co/graphql.web'; import { vi, expect, it, beforeEach, SpyInstance } from 'vitest'; import { gql } from './gql'; diff --git a/packages/core/src/gql.ts b/packages/core/src/gql.ts index 80be3004c6..18d356ab2b 100644 --- a/packages/core/src/gql.ts +++ b/packages/core/src/gql.ts @@ -1,5 +1,6 @@ /* eslint-disable prefer-rest-params */ -import { DocumentNode, DefinitionNode, Kind } from 'graphql'; +import { Kind } from '@0no-co/graphql.web'; +import type { DocumentNode, DefinitionNode } from './utils/graphql'; import { AnyVariables, TypedDocumentNode } from './types'; import { keyDocument, stringifyDocument } from './utils'; diff --git a/packages/core/src/utils/error.ts b/packages/core/src/utils/error.ts index 7d8057e6ad..0188d18374 100644 --- a/packages/core/src/utils/error.ts +++ b/packages/core/src/utils/error.ts @@ -1,4 +1,5 @@ -import { GraphQLError } from 'graphql'; +import { GraphQLError } from '@0no-co/graphql.web'; +import { ErrorLike } from '../types'; const generateErrorMessage = ( networkErr?: Error, @@ -93,7 +94,7 @@ export class CombinedError extends Error { constructor(input: { networkError?: Error; - graphQLErrors?: Array | Error>; + graphQLErrors?: Array; response?: any; }) { const normalizedGraphQLErrors = (input.graphQLErrors || []).map( diff --git a/packages/core/src/utils/request.test.ts b/packages/core/src/utils/request.test.ts index 1ef3cdd145..f8e39cb17a 100644 --- a/packages/core/src/utils/request.test.ts +++ b/packages/core/src/utils/request.test.ts @@ -1,6 +1,6 @@ import { expect, it, describe } from 'vitest'; -import { parse, print } from 'graphql'; +import { parse, print } from '@0no-co/graphql.web'; import { gql } from '../gql'; import { createRequest, stringifyDocument } from './request'; import { formatDocument } from './typenames'; diff --git a/packages/core/src/utils/request.ts b/packages/core/src/utils/request.ts index f6451e5b2d..8209aebd2b 100644 --- a/packages/core/src/utils/request.ts +++ b/packages/core/src/utils/request.ts @@ -1,32 +1,22 @@ -import { - Location, - DefinitionNode, - DocumentNode, - Kind, - parse, - print, -} from 'graphql'; - +import { Kind, parse, print } from '@0no-co/graphql.web'; +import type { DocumentNode, DefinitionNode } from './graphql'; import { HashValue, phash } from './hash'; import { stringifyVariables } from './variables'; import type { + DocumentInput, TypedDocumentNode, AnyVariables, GraphQLRequest, RequestExtensions, } from '../types'; -interface WritableLocation { - loc: Location | undefined; -} - /** A `DocumentNode` annotated with its hashed key. * @internal */ -export interface KeyedDocumentNode extends DocumentNode { +export type KeyedDocumentNode = TypedDocumentNode & { __key: HashValue; -} +}; const SOURCE_NAME = 'gql'; const GRAPHQL_STRING_RE = /("{3}[\s\S]*"{3}|"(?:\\.|[^"])*")/g; @@ -70,7 +60,7 @@ export const stringifyDocument = ( } if (typeof node !== 'string' && !node.loc) { - (node as WritableLocation).loc = { + (node as any).loc = { start: 0, end: printed.length, source: { @@ -78,7 +68,7 @@ export const stringifyDocument = ( name: SOURCE_NAME, locationOffset: { line: 1, column: 1 }, }, - } as Location; + }; } return printed; @@ -157,7 +147,7 @@ export const createRequest = < Data = any, Variables extends AnyVariables = AnyVariables >( - _query: string | DocumentNode | TypedDocumentNode, + _query: DocumentInput, _variables: Variables, extensions?: RequestExtensions | undefined ): GraphQLRequest => { diff --git a/packages/core/src/utils/typenames.test.ts b/packages/core/src/utils/typenames.test.ts index 886f48f850..f9d6e0eb6e 100755 --- a/packages/core/src/utils/typenames.test.ts +++ b/packages/core/src/utils/typenames.test.ts @@ -1,4 +1,4 @@ -import { parse, print } from 'graphql'; +import { parse, print } from '@0no-co/graphql.web'; import { describe, it, expect } from 'vitest'; import { collectTypesFromResponse, formatDocument } from './typenames'; import { createRequest } from './request'; diff --git a/packages/core/src/utils/typenames.ts b/packages/core/src/utils/typenames.ts index 144ff82c0e..bd39e0081b 100755 --- a/packages/core/src/utils/typenames.ts +++ b/packages/core/src/utils/typenames.ts @@ -1,10 +1,6 @@ -import { - DocumentNode, - FieldNode, - InlineFragmentNode, - Kind, - visit, -} from 'graphql'; +import { Kind, visit } from '@0no-co/graphql.web'; + +import type { DocumentNode, FieldNode, InlineFragmentNode } from './graphql'; import { KeyedDocumentNode, keyDocument } from './request'; From 2879e43be486b4ed6ea946593f81600ddc969650 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Tue, 14 Mar 2023 14:10:30 +0000 Subject: [PATCH 05/14] feat(core): Replace formatDocument's graphql.visit usage --- .changeset/tame-pumas-promise.md | 5 ++ packages/core/src/utils/graphql.ts | 4 ++ packages/core/src/utils/typenames.ts | 74 ++++++++++++++++------------ 3 files changed, 52 insertions(+), 31 deletions(-) create mode 100644 .changeset/tame-pumas-promise.md diff --git a/.changeset/tame-pumas-promise.md b/.changeset/tame-pumas-promise.md new file mode 100644 index 0000000000..19cddf3454 --- /dev/null +++ b/.changeset/tame-pumas-promise.md @@ -0,0 +1,5 @@ +--- +'@urql/core': patch +--- + +Remove dependence on `import { visit } from 'graphql';` with smaller but functionally equivalent alternative. diff --git a/packages/core/src/utils/graphql.ts b/packages/core/src/utils/graphql.ts index 9975c6797d..bbb3a8c020 100644 --- a/packages/core/src/utils/graphql.ts +++ b/packages/core/src/utils/graphql.ts @@ -20,3 +20,7 @@ export type DocumentNode = export type DefinitionNode = | GraphQLWeb.DefinitionNode | OrNever; + +export type SelectionNode = + | GraphQLWeb.SelectionNode + | OrNever; diff --git a/packages/core/src/utils/typenames.ts b/packages/core/src/utils/typenames.ts index bd39e0081b..d0ca0210a8 100755 --- a/packages/core/src/utils/typenames.ts +++ b/packages/core/src/utils/typenames.ts @@ -1,7 +1,5 @@ -import { Kind, visit } from '@0no-co/graphql.web'; - -import type { DocumentNode, FieldNode, InlineFragmentNode } from './graphql'; - +import { Kind } from '@0no-co/graphql.web'; +import type { DocumentNode, SelectionNode, DefinitionNode } from './graphql'; import { KeyedDocumentNode, keyDocument } from './request'; interface EntityLike { @@ -35,32 +33,49 @@ export const collectTypesFromResponse = (response: object): string[] => [ ...collectTypes(response as EntityLike, new Set()), ]; -const formatNode = (node: FieldNode | InlineFragmentNode) => { - if (!node.selectionSet) return node; - for (const selection of node.selectionSet.selections) - if ( - selection.kind === Kind.FIELD && - selection.name.value === '__typename' && - !selection.alias - ) - return node; +const formatNode = ( + node: T +): T => { + let hasChanged = false; - return { - ...node, - selectionSet: { - ...node.selectionSet, - selections: [ - ...node.selectionSet.selections, - { + if ('definitions' in node) { + const definitions: DefinitionNode[] = []; + for (const definition of node.definitions) { + const newDefinition = formatNode(definition); + hasChanged = hasChanged || newDefinition !== definition; + definitions.push(newDefinition); + } + if (hasChanged) return { ...node, definitions }; + } else if ('selectionSet' in node) { + const selections: SelectionNode[] = []; + let hasTypename = node.kind === Kind.OPERATION_DEFINITION; + if (node.selectionSet) { + for (const selection of node.selectionSet.selections || []) { + hasTypename = + hasTypename || + (selection.kind === Kind.FIELD && + selection.name.value === '__typename' && + !selection.alias); + const newSelection = formatNode(selection); + hasChanged = hasChanged || newSelection !== selection; + selections.push(newSelection); + } + if (!hasTypename) { + hasChanged = true; + selections.push({ kind: Kind.FIELD, name: { kind: Kind.NAME, value: '__typename', }, - }, - ], - }, - }; + }); + } + if (hasChanged) + return { ...node, selectionSet: { ...node.selectionSet, selections } }; + } + } + + return node; }; const formattedDocs = new Map(); @@ -88,11 +103,10 @@ export const formatDocument = (node: T): T => { let result = formattedDocs.get(query.__key); if (!result) { - result = visit(query, { - Field: formatNode, - InlineFragment: formatNode, - }) as KeyedDocumentNode; - + formattedDocs.set( + query.__key, + (result = formatNode(query) as KeyedDocumentNode) + ); // Ensure that the hash of the resulting document won't suddenly change // we are marking __key as non-enumerable so when external exchanges use visit // to manipulate a document we won't restore the previous query due to the __key @@ -101,8 +115,6 @@ export const formatDocument = (node: T): T => { value: query.__key, enumerable: false, }); - - formattedDocs.set(query.__key, result); } return result as unknown as T; From 532bed864a274096be4ea39cff968184ec67cbb7 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Thu, 23 Mar 2023 22:38:24 +0000 Subject: [PATCH 06/14] Remove irrelevant types from src/utils/graphql.ts --- packages/core/src/types.ts | 8 +------- packages/core/src/utils/graphql.ts | 10 ---------- packages/core/src/utils/typenames.ts | 4 ++-- 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index ee8dab33c6..688dd08174 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -1,8 +1,4 @@ -import type { - GraphQLError, - DocumentNode, - DefinitionNode, -} from './utils/graphql'; +import type { GraphQLError, DocumentNode } from './utils/graphql'; import { Subscription, Source } from 'wonka'; import { Client } from './client'; import { CombinedError } from './utils/error'; @@ -30,8 +26,6 @@ export type TypedDocumentNode< Result = { [key: string]: any }, Variables = { [key: string]: any } > = DocumentNode & { - /** GraphQL.js Definition Nodes of the `DocumentNode`. */ - readonly definitions: ReadonlyArray; /** Type to support `@graphql-typed-document-node/core` * @internal */ diff --git a/packages/core/src/utils/graphql.ts b/packages/core/src/utils/graphql.ts index bbb3a8c020..e548a3e2f6 100644 --- a/packages/core/src/utils/graphql.ts +++ b/packages/core/src/utils/graphql.ts @@ -3,12 +3,6 @@ import type * as GraphQL from 'graphql'; type OrNever = 0 extends 1 & T ? never : T; -export type FieldNode = GraphQLWeb.FieldNode | OrNever; - -export type InlineFragmentNode = - | GraphQLWeb.InlineFragmentNode - | OrNever; - export type GraphQLError = | GraphQLWeb.GraphQLError | OrNever; @@ -20,7 +14,3 @@ export type DocumentNode = export type DefinitionNode = | GraphQLWeb.DefinitionNode | OrNever; - -export type SelectionNode = - | GraphQLWeb.SelectionNode - | OrNever; diff --git a/packages/core/src/utils/typenames.ts b/packages/core/src/utils/typenames.ts index d0ca0210a8..c6a270abc5 100755 --- a/packages/core/src/utils/typenames.ts +++ b/packages/core/src/utils/typenames.ts @@ -1,5 +1,5 @@ -import { Kind } from '@0no-co/graphql.web'; -import type { DocumentNode, SelectionNode, DefinitionNode } from './graphql'; +import { Kind, SelectionNode, DefinitionNode } from '@0no-co/graphql.web'; +import type { DocumentNode } from './graphql'; import { KeyedDocumentNode, keyDocument } from './request'; interface EntityLike { From c948dd5da42e265e8a4aa2485c205dab68293c6e Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Fri, 24 Mar 2023 11:56:47 +0000 Subject: [PATCH 07/14] Remove 'graphql' dependency from all bindings --- exchanges/graphcache/package.json | 4 +--- exchanges/graphcache/src/ast/node.ts | 2 +- exchanges/graphcache/src/store/store.ts | 2 +- packages/core/src/types.ts | 4 ++-- packages/preact-urql/package.json | 1 - packages/preact-urql/src/components/Mutation.ts | 5 ++--- packages/preact-urql/src/hooks/useMutation.ts | 7 ++----- packages/react-urql/package.json | 1 - packages/react-urql/src/components/Mutation.ts | 5 ++--- packages/react-urql/src/hooks/useMutation.ts | 7 ++----- packages/react-urql/src/hooks/useRequest.ts | 5 ++--- packages/svelte-urql/package.json | 1 - packages/vue-urql/package.json | 1 - pnpm-lock.yaml | 2 ++ 14 files changed, 17 insertions(+), 30 deletions(-) diff --git a/exchanges/graphcache/package.json b/exchanges/graphcache/package.json index 979aafe35a..a2f0b95835 100644 --- a/exchanges/graphcache/package.json +++ b/exchanges/graphcache/package.json @@ -62,12 +62,10 @@ "prepublishOnly": "run-s clean build" }, "dependencies": { + "@0no-co/graphql.web": "^0.1.6", "@urql/core": ">=3.2.2", "wonka": "^6.0.0" }, - "peerDependencies": { - "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0" - }, "devDependencies": { "@cypress/react": "^7.0.2", "@urql/core": "workspace:*", diff --git a/exchanges/graphcache/src/ast/node.ts b/exchanges/graphcache/src/ast/node.ts index 428e948a99..4cf62b4699 100644 --- a/exchanges/graphcache/src/ast/node.ts +++ b/exchanges/graphcache/src/ast/node.ts @@ -7,7 +7,7 @@ import { FieldNode, FragmentDefinitionNode, Kind, -} from 'graphql'; +} from '@0no-co/graphql.web'; export type SelectionSet = ReadonlyArray; diff --git a/exchanges/graphcache/src/store/store.ts b/exchanges/graphcache/src/store/store.ts index 4dbcbb60b7..23b02dc6a0 100644 --- a/exchanges/graphcache/src/store/store.ts +++ b/exchanges/graphcache/src/store/store.ts @@ -1,4 +1,3 @@ -import { DocumentNode } from 'graphql'; import { TypedDocumentNode, formatDocument, createRequest } from '@urql/core'; import { @@ -35,6 +34,7 @@ import { expectValidOptimisticMutationsConfig, } from '../ast'; +type DocumentNode = TypedDocumentNode; type RootField = 'query' | 'mutation' | 'subscription'; /** Implementation of the {@link Cache} interface as created internally by the {@link cacheExchange}. diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 688dd08174..b41c7e9bf6 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -311,7 +311,7 @@ export type GraphQLRequestParams< Variables extends AnyVariables = AnyVariables > = | ({ - query: string | DocumentNode | TypedDocumentNode; + query: DocumentInput; } & (Variables extends void ? { variables?: Variables; @@ -332,7 +332,7 @@ export type GraphQLRequestParams< variables?: Variables; })) | { - query: string | DocumentNode | TypedDocumentNode; + query: DocumentInput; variables: Variables; }; diff --git a/packages/preact-urql/package.json b/packages/preact-urql/package.json index f89f0f592a..a5e0e73731 100644 --- a/packages/preact-urql/package.json +++ b/packages/preact-urql/package.json @@ -54,7 +54,6 @@ "preact": "^10.13.0" }, "peerDependencies": { - "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0", "preact": ">= 10.0.0" }, "dependencies": { diff --git a/packages/preact-urql/src/components/Mutation.ts b/packages/preact-urql/src/components/Mutation.ts index 09b3fc5dbe..cdacddaefb 100644 --- a/packages/preact-urql/src/components/Mutation.ts +++ b/packages/preact-urql/src/components/Mutation.ts @@ -1,6 +1,5 @@ import { VNode } from 'preact'; -import { DocumentNode } from 'graphql'; -import { AnyVariables, TypedDocumentNode } from '@urql/core'; +import { AnyVariables, DocumentInput } from '@urql/core'; import { useMutation, UseMutationState, UseMutationExecute } from '../hooks'; @@ -18,7 +17,7 @@ export interface MutationProps< Variables extends AnyVariables = AnyVariables > { /* The GraphQL mutation document that {@link useMutation} will execute. */ - query: DocumentNode | TypedDocumentNode | string; + query: DocumentInput; children(arg: MutationState): VNode; } diff --git a/packages/preact-urql/src/hooks/useMutation.ts b/packages/preact-urql/src/hooks/useMutation.ts index 0727d97f30..e2bddf9bb8 100644 --- a/packages/preact-urql/src/hooks/useMutation.ts +++ b/packages/preact-urql/src/hooks/useMutation.ts @@ -1,10 +1,9 @@ -import { DocumentNode } from 'graphql'; import { useState, useCallback, useRef, useEffect } from 'preact/hooks'; import { pipe, toPromise } from 'wonka'; import { AnyVariables, - TypedDocumentNode, + DocumentInput, OperationResult, OperationContext, CombinedError, @@ -144,9 +143,7 @@ export type UseMutationResponse< export function useMutation< Data = any, Variables extends AnyVariables = AnyVariables ->( - query: DocumentNode | TypedDocumentNode | string -): UseMutationResponse { +>(query: DocumentInput): UseMutationResponse { const isMounted = useRef(true); const client = useClient(); diff --git a/packages/react-urql/package.json b/packages/react-urql/package.json index c229cc9bc5..97bd36ee3f 100644 --- a/packages/react-urql/package.json +++ b/packages/react-urql/package.json @@ -57,7 +57,6 @@ "vite": "^3.2.4" }, "peerDependencies": { - "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0", "react": ">= 16.8.0" }, "dependencies": { diff --git a/packages/react-urql/src/components/Mutation.ts b/packages/react-urql/src/components/Mutation.ts index 43bde23c46..362b05b751 100644 --- a/packages/react-urql/src/components/Mutation.ts +++ b/packages/react-urql/src/components/Mutation.ts @@ -1,6 +1,5 @@ -import { DocumentNode } from 'graphql'; import { ReactElement } from 'react'; -import { AnyVariables, TypedDocumentNode } from '@urql/core'; +import { AnyVariables, DocumentInput } from '@urql/core'; import { useMutation, UseMutationState, UseMutationExecute } from '../hooks'; @@ -18,7 +17,7 @@ export interface MutationProps< Variables extends AnyVariables = AnyVariables > { /* The GraphQL mutation document that {@link useMutation} will execute. */ - query: DocumentNode | TypedDocumentNode | string; + query: DocumentInput; children(arg: MutationState): ReactElement; } diff --git a/packages/react-urql/src/hooks/useMutation.ts b/packages/react-urql/src/hooks/useMutation.ts index ad5ec0703e..34c4c18d9e 100644 --- a/packages/react-urql/src/hooks/useMutation.ts +++ b/packages/react-urql/src/hooks/useMutation.ts @@ -1,10 +1,9 @@ -import { DocumentNode } from 'graphql'; import { useState, useCallback, useRef, useEffect } from 'react'; import { pipe, toPromise } from 'wonka'; import { AnyVariables, - TypedDocumentNode, + DocumentInput, OperationResult, OperationContext, CombinedError, @@ -144,9 +143,7 @@ export type UseMutationResponse< export function useMutation< Data = any, Variables extends AnyVariables = AnyVariables ->( - query: DocumentNode | TypedDocumentNode | string -): UseMutationResponse { +>(query: DocumentInput): UseMutationResponse { const isMounted = useRef(true); const client = useClient(); diff --git a/packages/react-urql/src/hooks/useRequest.ts b/packages/react-urql/src/hooks/useRequest.ts index a909b95f00..0f9801599c 100644 --- a/packages/react-urql/src/hooks/useRequest.ts +++ b/packages/react-urql/src/hooks/useRequest.ts @@ -1,8 +1,7 @@ -import { DocumentNode } from 'graphql'; import { useRef, useMemo } from 'react'; import { AnyVariables, - TypedDocumentNode, + DocumentInput, GraphQLRequest, createRequest, } from '@urql/core'; @@ -14,7 +13,7 @@ export function useRequest< Data = any, Variables extends AnyVariables = AnyVariables >( - query: string | DocumentNode | TypedDocumentNode, + query: DocumentInput, variables: Variables ): GraphQLRequest { const prev = useRef>(undefined); diff --git a/packages/svelte-urql/package.json b/packages/svelte-urql/package.json index 6af683c296..52488ad644 100644 --- a/packages/svelte-urql/package.json +++ b/packages/svelte-urql/package.json @@ -48,7 +48,6 @@ "prepublishOnly": "run-s clean build" }, "peerDependencies": { - "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0", "svelte": "^3.0.0" }, "dependencies": { diff --git a/packages/vue-urql/package.json b/packages/vue-urql/package.json index 3664cb40d7..69fd09ce64 100644 --- a/packages/vue-urql/package.json +++ b/packages/vue-urql/package.json @@ -54,7 +54,6 @@ "vue": "^3.2.47" }, "peerDependencies": { - "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0", "vue": "^2.7.0 || ^3.0.0" }, "dependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fdbe7abe1c..7ee9415195 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -158,6 +158,7 @@ importers: exchanges/graphcache: specifiers: + '@0no-co/graphql.web': ^0.1.6 '@cypress/react': ^7.0.2 '@urql/core': '>=3.2.2' '@urql/exchange-execute': workspace:* @@ -169,6 +170,7 @@ importers: urql: workspace:* wonka: ^6.2.4 dependencies: + '@0no-co/graphql.web': 0.1.6 '@urql/core': link:../../packages/core wonka: 6.2.4 devDependencies: From cc0b2414244742467abeaa725260d6f335bfd1c9 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Fri, 24 Mar 2023 12:15:54 +0000 Subject: [PATCH 08/14] Refactor Graphcache to @0no-co/graphql.web --- exchanges/graphcache/src/ast/graphql.ts | 55 +++++++++++++++++++ exchanges/graphcache/src/ast/schema.ts | 9 ++- .../graphcache/src/ast/schemaPredicates.ts | 5 +- exchanges/graphcache/src/ast/traversal.ts | 2 +- exchanges/graphcache/src/ast/variables.ts | 2 +- exchanges/graphcache/src/helpers/help.ts | 6 +- exchanges/graphcache/src/offlineExchange.ts | 2 +- exchanges/graphcache/src/operations/query.ts | 7 ++- exchanges/graphcache/src/operations/shared.ts | 12 ++-- exchanges/graphcache/src/operations/write.ts | 7 ++- exchanges/graphcache/src/types.ts | 23 +++++--- pnpm-lock.yaml | 3 +- 12 files changed, 105 insertions(+), 28 deletions(-) create mode 100644 exchanges/graphcache/src/ast/graphql.ts diff --git a/exchanges/graphcache/src/ast/graphql.ts b/exchanges/graphcache/src/ast/graphql.ts new file mode 100644 index 0000000000..bfa446e06d --- /dev/null +++ b/exchanges/graphcache/src/ast/graphql.ts @@ -0,0 +1,55 @@ +import type * as GraphQL from 'graphql'; + +type OrNever = 0 extends 1 & T ? never : T; + +export type IntrospectionQuery = + | { + readonly __schema: { + queryType: { name: string; kind?: any }; + mutationType?: { name: string; kind?: any } | null; + subscriptionType?: { name: string; kind?: any } | null; + types?: readonly IntrospectionType[]; + }; + } + | OrNever; + +export type IntrospectionTypeRef = + | { + readonly kind: + | 'SCALAR' + | 'OBJECT' + | 'INTERFACE' + | 'ENUM' + | 'UNION' + | 'INPUT_OBJECT'; + readonly name?: string; + readonly ofType?: IntrospectionTypeRef; + } + | OrNever; + +export type IntrospectionInputTypeRef = + | { + readonly kind: 'SCALAR' | 'ENUM' | 'INPUT_OBJECT'; + readonly name?: string; + readonly ofType?: IntrospectionInputTypeRef; + } + | OrNever; + +export type IntrospectionInputValue = + | { + readonly name: string; + readonly description?: string | null; + readonly defaultValue?: string | null; + readonly type: IntrospectionInputTypeRef; + } + | OrNever; + +export type IntrospectionType = + | { + readonly kind: string; + readonly name: string; + readonly fields?: readonly any[]; + readonly interfaces?: readonly any[]; + readonly possibleTypes?: readonly any[]; + } + | OrNever; diff --git a/exchanges/graphcache/src/ast/schema.ts b/exchanges/graphcache/src/ast/schema.ts index 75585be095..103e9763a4 100644 --- a/exchanges/graphcache/src/ast/schema.ts +++ b/exchanges/graphcache/src/ast/schema.ts @@ -1,10 +1,9 @@ -import { +import type { IntrospectionQuery, - IntrospectionSchema, - IntrospectionInputValue, IntrospectionTypeRef, + IntrospectionInputValue, IntrospectionType, -} from 'graphql'; +} from './graphql'; export interface SchemaField { name: string; @@ -37,7 +36,7 @@ export interface PartialIntrospectionSchema { queryType: { name: string; kind?: any }; mutationType?: { name: string; kind?: any } | null; subscriptionType?: { name: string; kind?: any } | null; - types?: IntrospectionSchema['types']; + types?: readonly any[]; } export type IntrospectionData = diff --git a/exchanges/graphcache/src/ast/schemaPredicates.ts b/exchanges/graphcache/src/ast/schemaPredicates.ts index 382a5f50d3..49ff055e20 100644 --- a/exchanges/graphcache/src/ast/schemaPredicates.ts +++ b/exchanges/graphcache/src/ast/schemaPredicates.ts @@ -1,4 +1,7 @@ -import { InlineFragmentNode, FragmentDefinitionNode } from 'graphql'; +import { + InlineFragmentNode, + FragmentDefinitionNode, +} from '@0no-co/graphql.web'; import { warn, invariant } from '../helpers/help'; import { getTypeCondition } from './node'; diff --git a/exchanges/graphcache/src/ast/traversal.ts b/exchanges/graphcache/src/ast/traversal.ts index 1a45d3571b..a0b1bbd2bb 100644 --- a/exchanges/graphcache/src/ast/traversal.ts +++ b/exchanges/graphcache/src/ast/traversal.ts @@ -6,7 +6,7 @@ import { InlineFragmentNode, valueFromASTUntyped, Kind, -} from 'graphql'; +} from '@0no-co/graphql.web'; import { getName } from './node'; diff --git a/exchanges/graphcache/src/ast/variables.ts b/exchanges/graphcache/src/ast/variables.ts index c06d60d77d..28b72486ab 100644 --- a/exchanges/graphcache/src/ast/variables.ts +++ b/exchanges/graphcache/src/ast/variables.ts @@ -2,7 +2,7 @@ import { FieldNode, OperationDefinitionNode, valueFromASTUntyped, -} from 'graphql'; +} from '@0no-co/graphql.web'; import { getName } from './node'; diff --git a/exchanges/graphcache/src/helpers/help.ts b/exchanges/graphcache/src/helpers/help.ts index 9c09b6be91..763665369d 100644 --- a/exchanges/graphcache/src/helpers/help.ts +++ b/exchanges/graphcache/src/helpers/help.ts @@ -3,7 +3,11 @@ // Every warning and error comes with a number that uniquely identifies them. // You can read more about the messages themselves in `docs/graphcache/errors.md` -import { Kind, ExecutableDefinitionNode, InlineFragmentNode } from 'graphql'; +import { + Kind, + ExecutableDefinitionNode, + InlineFragmentNode, +} from '@0no-co/graphql.web'; export type ErrorCode = | 1 diff --git a/exchanges/graphcache/src/offlineExchange.ts b/exchanges/graphcache/src/offlineExchange.ts index 7e47c40594..3c0172fef0 100644 --- a/exchanges/graphcache/src/offlineExchange.ts +++ b/exchanges/graphcache/src/offlineExchange.ts @@ -1,5 +1,5 @@ import { pipe, merge, makeSubject, filter } from 'wonka'; -import { SelectionNode } from 'graphql'; +import { SelectionNode } from '@0no-co/graphql.web'; import { Operation, diff --git a/exchanges/graphcache/src/operations/query.ts b/exchanges/graphcache/src/operations/query.ts index 496f994c59..4914c907a4 100644 --- a/exchanges/graphcache/src/operations/query.ts +++ b/exchanges/graphcache/src/operations/query.ts @@ -1,6 +1,11 @@ -import { FieldNode, DocumentNode, FragmentDefinitionNode } from 'graphql'; import { CombinedError } from '@urql/core'; +import { + FieldNode, + DocumentNode, + FragmentDefinitionNode, +} from '@0no-co/graphql.web'; + import { getSelectionSet, getName, diff --git a/exchanges/graphcache/src/operations/shared.ts b/exchanges/graphcache/src/operations/shared.ts index 1d8ec32656..aabb6f28f3 100644 --- a/exchanges/graphcache/src/operations/shared.ts +++ b/exchanges/graphcache/src/operations/shared.ts @@ -1,10 +1,10 @@ -import { CombinedError } from '@urql/core'; +import { CombinedError, ErrorLike } from '@urql/core'; + import { - GraphQLError, FieldNode, InlineFragmentNode, FragmentDefinitionNode, -} from 'graphql'; +} from '@0no-co/graphql.web'; import { isDeferred, @@ -41,12 +41,12 @@ export interface Context { parentFieldKey: string; parent: Data; fieldName: string; - error: GraphQLError | undefined; + error: ErrorLike | undefined; partial: boolean; optimistic: boolean; __internal: { path: Array; - errorMap: { [path: string]: GraphQLError } | undefined; + errorMap: { [path: string]: ErrorLike } | undefined; }; } @@ -54,7 +54,7 @@ export const contextRef: { current: Context | null } = { current: null }; export const deferRef: { current: boolean } = { current: false }; // Checks whether the current data field is a cache miss because of a GraphQLError -export const getFieldError = (ctx: Context): GraphQLError | undefined => +export const getFieldError = (ctx: Context): ErrorLike | undefined => ctx.__internal.path.length > 0 && ctx.__internal.errorMap ? ctx.__internal.errorMap[ctx.__internal.path.join('.')] : undefined; diff --git a/exchanges/graphcache/src/operations/write.ts b/exchanges/graphcache/src/operations/write.ts index 5222ec9e7d..eac9097164 100644 --- a/exchanges/graphcache/src/operations/write.ts +++ b/exchanges/graphcache/src/operations/write.ts @@ -1,6 +1,11 @@ -import { FieldNode, DocumentNode, FragmentDefinitionNode } from 'graphql'; import { CombinedError } from '@urql/core'; +import { + FieldNode, + DocumentNode, + FragmentDefinitionNode, +} from '@0no-co/graphql.web'; + import { getFragments, getMainOperation, diff --git a/exchanges/graphcache/src/types.ts b/exchanges/graphcache/src/types.ts index 12475c7e44..5eee2b1abe 100644 --- a/exchanges/graphcache/src/types.ts +++ b/exchanges/graphcache/src/types.ts @@ -1,5 +1,12 @@ -import { AnyVariables, TypedDocumentNode, RequestExtensions } from '@urql/core'; -import { GraphQLError, DocumentNode, FragmentDefinitionNode } from 'graphql'; +import { + AnyVariables, + DocumentInput, + RequestExtensions, + TypedDocumentNode, + ErrorLike, +} from '@urql/core'; + +import { FragmentDefinitionNode } from '@0no-co/graphql.web'; import { IntrospectionData } from './ast'; /** Nullable GraphQL list types of `T`. @@ -177,7 +184,7 @@ export interface KeyInfo { * GraphQL operation: its query document and variables. */ export interface OperationRequest { - query: DocumentNode | TypedDocumentNode; + query: Exclude, string>; variables?: any; } @@ -209,7 +216,7 @@ export interface ResolveInfo { parentFieldKey: string; /** Current field that the resolver has been called on. */ fieldName: string; - /** Map of fragment definitions from the {@link DocumentNode}. */ + /** Map of fragment definitions from the query document. */ fragments: Fragments; /** Full original {@link Variables} object on the {@link OperationRequest}. */ variables: Variables; @@ -220,7 +227,7 @@ export interface ResolveInfo { * will be set and provided here. This can be useful to recover from an * error on a specific field. */ - error: GraphQLError | undefined; + error: ErrorLike | undefined; /** Flag used to indicate whether the current GraphQL query is only partially cached. * * @remarks @@ -257,7 +264,7 @@ export interface ResolveInfo { * cached data, as accepted by {@link cache.readQuery}. */ export interface QueryInput { - query: string | DocumentNode | TypedDocumentNode; + query: DocumentInput; variables?: V; } @@ -443,7 +450,7 @@ export interface Cache { * ``` */ readFragment( - fragment: DocumentNode | TypedDocumentNode, + fragment: TypedDocumentNode | TypedDocumentNode, entity: string | Data | T, variables?: V ): T | null; @@ -473,7 +480,7 @@ export interface Cache { * ``` */ writeFragment( - fragment: DocumentNode | TypedDocumentNode, + fragment: TypedDocumentNode | TypedDocumentNode, data: T, variables?: V ): void; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7ee9415195..fc4ad85f64 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -170,10 +170,10 @@ importers: urql: workspace:* wonka: ^6.2.4 dependencies: - '@0no-co/graphql.web': 0.1.6 '@urql/core': link:../../packages/core wonka: 6.2.4 devDependencies: + '@0no-co/graphql.web': 0.1.6 '@cypress/react': 7.0.2_kxqn2c7raunyx4zfzvxjupflne '@urql/exchange-execute': link:../execute '@urql/introspection': link:../../packages/introspection @@ -471,7 +471,6 @@ packages: /@0no-co/graphql.web/0.1.6: resolution: {integrity: sha512-HUFsLTSjX6sTdK+CyoHNs71h0HneugTO6nQS8WwxFGarmAh3doKwZRVY39xLkdOmneSKJZIHRysjf+odHHBFhw==} - dev: false /@actions/artifact/1.1.1: resolution: {integrity: sha512-Vv4y0EW0ptEkU+Pjs5RGS/0EryTvI6s79LjSV9Gg/h+O3H/ddpjhuX/Bi/HZE4pbNPyjGtQjbdFWphkZhmgabA==} From 3f7f30022c176dba85210fb3e3574d7726d6a129 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Fri, 24 Mar 2023 12:17:59 +0000 Subject: [PATCH 09/14] Add changeset --- .changeset/fluffy-tools-marry.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/fluffy-tools-marry.md diff --git a/.changeset/fluffy-tools-marry.md b/.changeset/fluffy-tools-marry.md new file mode 100644 index 0000000000..e49ac45175 --- /dev/null +++ b/.changeset/fluffy-tools-marry.md @@ -0,0 +1,6 @@ +--- +'@urql/exchange-graphcache': major +'@urql/core': major +--- + +Remove dependence on `graphql` package and replace it with `@0no-co/graphql.web`, which reduces the default bundlesize impact of `urql` packages to a minimum. All types should remain compatible, even if you use `graphql` elsewhere in your app, and if other dependencies are using `graphql` you may alias it to `graphql-web-lite`. From e10d92f79d6e693baec629995a47c559af216817 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Fri, 24 Mar 2023 12:25:38 +0000 Subject: [PATCH 10/14] Update pnpm-lock.yaml file --- pnpm-lock.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fc4ad85f64..7ee9415195 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -170,10 +170,10 @@ importers: urql: workspace:* wonka: ^6.2.4 dependencies: + '@0no-co/graphql.web': 0.1.6 '@urql/core': link:../../packages/core wonka: 6.2.4 devDependencies: - '@0no-co/graphql.web': 0.1.6 '@cypress/react': 7.0.2_kxqn2c7raunyx4zfzvxjupflne '@urql/exchange-execute': link:../execute '@urql/introspection': link:../../packages/introspection @@ -471,6 +471,7 @@ packages: /@0no-co/graphql.web/0.1.6: resolution: {integrity: sha512-HUFsLTSjX6sTdK+CyoHNs71h0HneugTO6nQS8WwxFGarmAh3doKwZRVY39xLkdOmneSKJZIHRysjf+odHHBFhw==} + dev: false /@actions/artifact/1.1.1: resolution: {integrity: sha512-Vv4y0EW0ptEkU+Pjs5RGS/0EryTvI6s79LjSV9Gg/h+O3H/ddpjhuX/Bi/HZE4pbNPyjGtQjbdFWphkZhmgabA==} From a0d6b33eeaed5bc8d909cd626ea96b9ff5988c1f Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Fri, 24 Mar 2023 12:37:21 +0000 Subject: [PATCH 11/14] Fix type error in exchanges/graphcache/src/ast/schema.ts --- exchanges/graphcache/src/ast/schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exchanges/graphcache/src/ast/schema.ts b/exchanges/graphcache/src/ast/schema.ts index 103e9763a4..2b6f1ca0a5 100644 --- a/exchanges/graphcache/src/ast/schema.ts +++ b/exchanges/graphcache/src/ast/schema.ts @@ -72,7 +72,7 @@ export const buildClientSchema = ({ kind: type.kind as 'OBJECT' | 'INTERFACE', interfaces: buildNameMap(type.interfaces || []), fields: buildNameMap( - type.fields.map(field => ({ + type.fields!.map((field: any) => ({ name: field.name, type: field.type, args: buildNameMap(field.args), From dee2f094aac6e6f4555fca436059cfcb283e6172 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Fri, 24 Mar 2023 12:41:00 +0000 Subject: [PATCH 12/14] Remove graphql peers from exchanges (except populate) --- exchanges/auth/package.json | 3 --- exchanges/auth/src/authExchange.ts | 8 +++----- exchanges/context/package.json | 3 --- exchanges/multipart-fetch/package.json | 3 --- exchanges/persisted/package.json | 3 --- exchanges/persisted/src/persistedExchange.ts | 8 +++++--- exchanges/refocus/package.json | 3 --- exchanges/request-policy/package.json | 3 --- exchanges/retry/package.json | 3 --- 9 files changed, 8 insertions(+), 29 deletions(-) diff --git a/exchanges/auth/package.json b/exchanges/auth/package.json index 2cc41ac9a7..dbc50abde7 100644 --- a/exchanges/auth/package.json +++ b/exchanges/auth/package.json @@ -51,9 +51,6 @@ "@urql/core": ">=3.2.2", "wonka": "^6.0.0" }, - "peerDependencies": { - "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0" - }, "devDependencies": { "@urql/core": "workspace:*", "graphql": "^16.0.0" diff --git a/exchanges/auth/src/authExchange.ts b/exchanges/auth/src/authExchange.ts index 7ac7da1d4f..3fdfa5204f 100644 --- a/exchanges/auth/src/authExchange.ts +++ b/exchanges/auth/src/authExchange.ts @@ -18,12 +18,10 @@ import { OperationResult, CombinedError, Exchange, - TypedDocumentNode, + DocumentInput, AnyVariables, } from '@urql/core'; -import { DocumentNode } from 'graphql'; - /** Utilities to use while refreshing authentication tokens. */ export interface AuthUtilities { /** Sends a mutation to your GraphQL API, bypassing earlier exchanges and authentication. @@ -43,7 +41,7 @@ export interface AuthUtilities { * options, so you may have to pass them again, if needed. */ mutate( - query: DocumentNode | TypedDocumentNode | string, + query: DocumentInput, variables: Variables, context?: Partial ): Promise>; @@ -222,7 +220,7 @@ export function authExchange( .then(() => init({ mutate( - query: DocumentNode | string, + query: DocumentInput, variables: Variables, context?: Partial ): Promise> { diff --git a/exchanges/context/package.json b/exchanges/context/package.json index 6b5623d6db..4cf345b379 100644 --- a/exchanges/context/package.json +++ b/exchanges/context/package.json @@ -50,9 +50,6 @@ "@urql/core": ">=3.2.2", "wonka": "^6.0.0" }, - "peerDependencies": { - "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0" - }, "devDependencies": { "@urql/core": "workspace:*", "graphql": "^16.0.0" diff --git a/exchanges/multipart-fetch/package.json b/exchanges/multipart-fetch/package.json index 9504b75b8b..46132dcdc0 100644 --- a/exchanges/multipart-fetch/package.json +++ b/exchanges/multipart-fetch/package.json @@ -50,9 +50,6 @@ "extract-files": "^11.0.0", "wonka": "^6.0.0" }, - "peerDependencies": { - "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0" - }, "devDependencies": { "@urql/core": "workspace:*", "graphql": "^16.0.0" diff --git a/exchanges/persisted/package.json b/exchanges/persisted/package.json index ffddae4ea2..5ddeeee11d 100644 --- a/exchanges/persisted/package.json +++ b/exchanges/persisted/package.json @@ -49,9 +49,6 @@ "@urql/core": ">=3.2.2", "wonka": "^6.0.0" }, - "peerDependencies": { - "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0" - }, "devDependencies": { "@urql/core": "workspace:*", "graphql": "^16.0.0" diff --git a/exchanges/persisted/src/persistedExchange.ts b/exchanges/persisted/src/persistedExchange.ts index 56a2121478..cd4d99e899 100644 --- a/exchanges/persisted/src/persistedExchange.ts +++ b/exchanges/persisted/src/persistedExchange.ts @@ -12,14 +12,13 @@ import { makeOperation, stringifyDocument, PersistedRequestExtensions, + TypedDocumentNode, OperationResult, CombinedError, Exchange, Operation, } from '@urql/core'; -import type { DocumentNode } from 'graphql'; - import { hash } from './sha256'; const isPersistedMiss = (error: CombinedError): boolean => @@ -67,7 +66,10 @@ export interface PersistedExchangeOptions { * API is unavailable on React Native, which may require you to * pass a custom function here. */ - generateHash?(query: string, document: DocumentNode): Promise; + generateHash?( + query: string, + document: TypedDocumentNode + ): Promise; /** Enables persisted queries to be used for mutations. * * @remarks diff --git a/exchanges/refocus/package.json b/exchanges/refocus/package.json index 2091bd8d42..1c3a06e7d6 100644 --- a/exchanges/refocus/package.json +++ b/exchanges/refocus/package.json @@ -52,9 +52,6 @@ "@types/react": "^17.0.4", "graphql": "^16.0.0" }, - "peerDependencies": { - "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0" - }, "dependencies": { "@urql/core": ">=3.2.2", "wonka": "^6.0.0" diff --git a/exchanges/request-policy/package.json b/exchanges/request-policy/package.json index 4ab414e436..18e33a3717 100644 --- a/exchanges/request-policy/package.json +++ b/exchanges/request-policy/package.json @@ -50,9 +50,6 @@ "@urql/core": "workspace:*", "graphql": "^16.0.0" }, - "peerDependencies": { - "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0" - }, "dependencies": { "@urql/core": ">=3.2.2", "wonka": "^6.0.0" diff --git a/exchanges/retry/package.json b/exchanges/retry/package.json index 7644c5c93a..87ddae81ff 100644 --- a/exchanges/retry/package.json +++ b/exchanges/retry/package.json @@ -50,9 +50,6 @@ "@urql/core": "workspace:*", "graphql": "^16.0.0" }, - "peerDependencies": { - "graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0" - }, "dependencies": { "@urql/core": ">=3.2.2", "wonka": "^6.0.0" From af2ef5a30ea5f3261e87c106c8f76ce12bac3efe Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Fri, 24 Mar 2023 13:03:25 +0000 Subject: [PATCH 13/14] Update to @0no-co/graphql.web@^1.0.0 --- exchanges/graphcache/package.json | 2 +- package.json | 1 + packages/core/package.json | 2 +- pnpm-lock.yaml | 35 ++++++++++++++++++++----------- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/exchanges/graphcache/package.json b/exchanges/graphcache/package.json index a2f0b95835..a8afeaf2ab 100644 --- a/exchanges/graphcache/package.json +++ b/exchanges/graphcache/package.json @@ -62,7 +62,7 @@ "prepublishOnly": "run-s clean build" }, "dependencies": { - "@0no-co/graphql.web": "^0.1.6", + "@0no-co/graphql.web": "^1.0.0", "@urql/core": ">=3.2.2", "wonka": "^6.0.0" }, diff --git a/package.json b/package.json index 92e2e38d91..315834329e 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ } }, "devDependencies": { + "@0no-co/graphql.web": "^1.0.0", "@actions/artifact": "^1.1.1", "@actions/core": "^1.10.0", "@babel/core": "^7.21.3", diff --git a/packages/core/package.json b/packages/core/package.json index 3f4bb7e911..54341c7b2f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -53,7 +53,7 @@ "prepublishOnly": "run-s clean build" }, "dependencies": { - "@0no-co/graphql.web": "^0.1.6", + "@0no-co/graphql.web": "^1.0.0", "wonka": "^6.1.2" }, "publishConfig": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7ee9415195..7357f7ed06 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,7 @@ importers: .: specifiers: + '@0no-co/graphql.web': ^1.0.0 '@actions/artifact': ^1.1.1 '@actions/core': ^1.10.0 '@actions/github': ^5.1.1 @@ -71,6 +72,7 @@ importers: '@actions/github': 5.1.1 node-fetch: 3.3.1 devDependencies: + '@0no-co/graphql.web': 1.0.0_graphql@16.6.0 '@actions/artifact': 1.1.1 '@actions/core': 1.10.0 '@babel/core': 7.21.3 @@ -158,7 +160,7 @@ importers: exchanges/graphcache: specifiers: - '@0no-co/graphql.web': ^0.1.6 + '@0no-co/graphql.web': ^1.0.0 '@cypress/react': ^7.0.2 '@urql/core': '>=3.2.2' '@urql/exchange-execute': workspace:* @@ -170,7 +172,7 @@ importers: urql: workspace:* wonka: ^6.2.4 dependencies: - '@0no-co/graphql.web': 0.1.6 + '@0no-co/graphql.web': 1.0.0_graphql@16.6.0 '@urql/core': link:../../packages/core wonka: 6.2.4 devDependencies: @@ -255,10 +257,10 @@ importers: packages/core: specifiers: - '@0no-co/graphql.web': ^0.1.6 + '@0no-co/graphql.web': ^1.0.0 wonka: ^6.2.4 dependencies: - '@0no-co/graphql.web': 0.1.6 + '@0no-co/graphql.web': 1.0.0 wonka: 6.2.4 packages/introspection: @@ -469,10 +471,25 @@ importers: packages: - /@0no-co/graphql.web/0.1.6: - resolution: {integrity: sha512-HUFsLTSjX6sTdK+CyoHNs71h0HneugTO6nQS8WwxFGarmAh3doKwZRVY39xLkdOmneSKJZIHRysjf+odHHBFhw==} + /@0no-co/graphql.web/1.0.0: + resolution: {integrity: sha512-JBq2pWyDchE1vVjj/+c4dzZ8stbpew4RrzpZ3vYdn1WJFGHfYg6YIX1fDdMKtSXJJM9FUlsoDOxemr9WMM2p+A==} + peerDependencies: + graphql: ^14.0.0 || ^15.0.0 || ^16.0.0 + peerDependenciesMeta: + graphql: + optional: true dev: false + /@0no-co/graphql.web/1.0.0_graphql@16.6.0: + resolution: {integrity: sha512-JBq2pWyDchE1vVjj/+c4dzZ8stbpew4RrzpZ3vYdn1WJFGHfYg6YIX1fDdMKtSXJJM9FUlsoDOxemr9WMM2p+A==} + peerDependencies: + graphql: ^14.0.0 || ^15.0.0 || ^16.0.0 + peerDependenciesMeta: + graphql: + optional: true + dependencies: + graphql: 16.6.0 + /@actions/artifact/1.1.1: resolution: {integrity: sha512-Vv4y0EW0ptEkU+Pjs5RGS/0EryTvI6s79LjSV9Gg/h+O3H/ddpjhuX/Bi/HZE4pbNPyjGtQjbdFWphkZhmgabA==} dependencies: @@ -7894,7 +7911,6 @@ packages: /graphql/16.6.0: resolution: {integrity: sha512-KPIBPDlW7NxrbT/eh4qPXz5FiFdL5UbaA0XUNz2Rp3Z3hqBSkbj0GVjwFDztsWVauZUWsbKHgMg++sk8UX0bkw==} engines: {node: ^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0} - dev: true /gud/1.0.0: resolution: {integrity: sha512-zGEOVKFM5sVPPrYs7J5/hYEw2Pof8KCyOwyhG8sAF26mCAeUFAcYPu1mwB7hhpIP29zOIBaDqwuHdLp0jvZXjw==} @@ -9707,8 +9723,6 @@ packages: /match-sorter/3.1.1: resolution: {integrity: sha512-Qlox3wRM/Q4Ww9rv1cBmYKNJwWVX/WC+eA3+1S3Fv4EOhrqyp812ZEfVFKQk0AP6RfzmPUUOwEZBbJ8IRt8SOw==} - dependencies: - remove-accents: 0.4.2 bundledDependencies: - remove-accents @@ -12703,9 +12717,6 @@ packages: unified: 8.4.2 dev: false - /remove-accents/0.4.2: - resolution: {integrity: sha512-7pXIJqJOq5tFgG1A2Zxti3Ht8jJF337m4sowbuHsW30ZnkQFnDzy9qBNhgzX8ZLW4+UBcXiiR7SwR6pokHsxiA==} - /remove-trailing-separator/1.1.0: resolution: {integrity: sha512-/hS+Y0u3aOfIETiaiirUFwDBDzmXPvO+jAfKTitUngIPzdKc6Z0LoFjM/CK5PL4C+eKwHohlHAb6H0VFfmmUsw==} From c8d6e2b44b0f6cd5af031a099b7f5e23da13cdc2 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Fri, 24 Mar 2023 13:10:15 +0000 Subject: [PATCH 14/14] Fix type dependence in formatDocument --- packages/core/src/utils/typenames.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/core/src/utils/typenames.ts b/packages/core/src/utils/typenames.ts index c6a270abc5..5f227e27a2 100755 --- a/packages/core/src/utils/typenames.ts +++ b/packages/core/src/utils/typenames.ts @@ -1,6 +1,6 @@ import { Kind, SelectionNode, DefinitionNode } from '@0no-co/graphql.web'; -import type { DocumentNode } from './graphql'; import { KeyedDocumentNode, keyDocument } from './request'; +import { TypedDocumentNode } from '../types'; interface EntityLike { [key: string]: EntityLike | EntityLike[] | any; @@ -33,7 +33,9 @@ export const collectTypesFromResponse = (response: object): string[] => [ ...collectTypes(response as EntityLike, new Set()), ]; -const formatNode = ( +const formatNode = < + T extends SelectionNode | DefinitionNode | TypedDocumentNode +>( node: T ): T => { let hasChanged = false; @@ -98,7 +100,9 @@ const formattedDocs = new Map(); * @see {@link https://spec.graphql.org/October2021/#sec-Type-Name-Introspection} for more information * on typename introspection via the `__typename` field. */ -export const formatDocument = (node: T): T => { +export const formatDocument = >( + node: T +): T => { const query = keyDocument(node); let result = formattedDocs.get(query.__key);