From 1cb7b23fc44f2920cbb152ccfa544c10ec756e31 Mon Sep 17 00:00:00 2001 From: Jonas Jongejan <227529+HalfdanJ@users.noreply.github.com> Date: Sat, 7 Oct 2023 15:55:29 -0400 Subject: [PATCH 1/4] Make offlineExchange import respect useTypeImports --- packages/plugins/typescript/urql-graphcache/src/index.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/plugins/typescript/urql-graphcache/src/index.ts b/packages/plugins/typescript/urql-graphcache/src/index.ts index f5ef5f1b0..7b421ff49 100644 --- a/packages/plugins/typescript/urql-graphcache/src/index.ts +++ b/packages/plugins/typescript/urql-graphcache/src/index.ts @@ -276,12 +276,9 @@ function getOptimisticUpdatersConfig( } function getImports(config: UrqlGraphCacheConfig): string { - return [ - "import { offlineExchange } from '@urql/exchange-graphcache';", - `${ + return `${ config.useTypeImports ? 'import type' : 'import' - } { Resolver as GraphCacheResolver, UpdateResolver as GraphCacheUpdateResolver, OptimisticMutationResolver as GraphCacheOptimisticMutationResolver } from '@urql/exchange-graphcache';\n`, - ].join('\n'); + } { Resolver as GraphCacheResolver, UpdateResolver as GraphCacheUpdateResolver, OptimisticMutationResolver as GraphCacheOptimisticMutationResolver, offlineExchange } from '@urql/exchange-graphcache';\n`; } export const plugin: PluginFunction = ( From 24ca2f66c8f6ac3e26be468dad79b5dc80050134 Mon Sep 17 00:00:00 2001 From: Jonas Jongejan Date: Sat, 7 Oct 2023 16:25:52 -0400 Subject: [PATCH 2/4] Update test --- .../urql-graphcache/tests/__snapshots__/urql.spec.ts.snap | 4 +--- .../plugins/typescript/urql-graphcache/tests/urql.spec.ts | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/plugins/typescript/urql-graphcache/tests/__snapshots__/urql.spec.ts.snap b/packages/plugins/typescript/urql-graphcache/tests/__snapshots__/urql.spec.ts.snap index d5db0c0fa..64f258ef0 100644 --- a/packages/plugins/typescript/urql-graphcache/tests/__snapshots__/urql.spec.ts.snap +++ b/packages/plugins/typescript/urql-graphcache/tests/__snapshots__/urql.spec.ts.snap @@ -1,9 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`urql graphcache Should correctly name GraphCacheResolvers & GraphCacheOptimisticUpdaters with nonstandard mutationType names 1`] = ` -"import { offlineExchange } from '@urql/exchange-graphcache'; -import { Resolver as GraphCacheResolver, UpdateResolver as GraphCacheUpdateResolver, OptimisticMutationResolver as GraphCacheOptimisticMutationResolver } from '@urql/exchange-graphcache'; - +import { Resolver as GraphCacheResolver, UpdateResolver as GraphCacheUpdateResolver, OptimisticMutationResolver as GraphCacheOptimisticMutationResolver, offlineExchange } from '@urql/exchange-graphcache'; export type WithTypename = Partial & { __typename: NonNullable }; export type GraphCacheKeysConfig = { diff --git a/packages/plugins/typescript/urql-graphcache/tests/urql.spec.ts b/packages/plugins/typescript/urql-graphcache/tests/urql.spec.ts index 16632258b..5886391ac 100644 --- a/packages/plugins/typescript/urql-graphcache/tests/urql.spec.ts +++ b/packages/plugins/typescript/urql-graphcache/tests/urql.spec.ts @@ -166,8 +166,7 @@ describe('urql graphcache', () => { const result = mergeOutputs([await plugin(schema, [], { useTypeImports: true })]); expect(result).toBeSimilarStringTo(`\ -import { offlineExchange } from '@urql/exchange-graphcache'; -import type { Resolver as GraphCacheResolver, UpdateResolver as GraphCacheUpdateResolver, OptimisticMutationResolver as GraphCacheOptimisticMutationResolver } from '@urql/exchange-graphcache'; +import type { Resolver as GraphCacheResolver, UpdateResolver as GraphCacheUpdateResolver, OptimisticMutationResolver as GraphCacheOptimisticMutationResolver, offlineExchange } from '@urql/exchange-graphcache'; `); }); From db9298923dc4bc43a858a756a4e41964f6fec295 Mon Sep 17 00:00:00 2001 From: Jonas Jongejan <227529+HalfdanJ@users.noreply.github.com> Date: Tue, 31 Oct 2023 02:16:35 +0000 Subject: [PATCH 3/4] Apply prettier formatting --- packages/plugins/typescript/urql-graphcache/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/plugins/typescript/urql-graphcache/src/index.ts b/packages/plugins/typescript/urql-graphcache/src/index.ts index 7b421ff49..59df668b4 100644 --- a/packages/plugins/typescript/urql-graphcache/src/index.ts +++ b/packages/plugins/typescript/urql-graphcache/src/index.ts @@ -277,8 +277,8 @@ function getOptimisticUpdatersConfig( function getImports(config: UrqlGraphCacheConfig): string { return `${ - config.useTypeImports ? 'import type' : 'import' - } { Resolver as GraphCacheResolver, UpdateResolver as GraphCacheUpdateResolver, OptimisticMutationResolver as GraphCacheOptimisticMutationResolver, offlineExchange } from '@urql/exchange-graphcache';\n`; + config.useTypeImports ? 'import type' : 'import' + } { Resolver as GraphCacheResolver, UpdateResolver as GraphCacheUpdateResolver, OptimisticMutationResolver as GraphCacheOptimisticMutationResolver, offlineExchange } from '@urql/exchange-graphcache';\n`; } export const plugin: PluginFunction = ( From 7493c0dff9ac336ec4afab036eb1ecbecafd29cf Mon Sep 17 00:00:00 2001 From: Jonas Jongejan <227529+HalfdanJ@users.noreply.github.com> Date: Tue, 31 Oct 2023 02:19:08 +0000 Subject: [PATCH 4/4] Resolve generated types --- dev-test/githunt/types.urql.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-test/githunt/types.urql.tsx b/dev-test/githunt/types.urql.tsx index 954f55b0a..1314f48ad 100644 --- a/dev-test/githunt/types.urql.tsx +++ b/dev-test/githunt/types.urql.tsx @@ -1,11 +1,11 @@ import { IntrospectionQuery } from 'graphql'; import gql from 'graphql-tag'; import * as Urql from 'urql'; -import { offlineExchange } from '@urql/exchange-graphcache'; import { OptimisticMutationResolver as GraphCacheOptimisticMutationResolver, Resolver as GraphCacheResolver, UpdateResolver as GraphCacheUpdateResolver, + offlineExchange, } from '@urql/exchange-graphcache'; export type Maybe = T | null;