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

Make offlineExchange import respect useTypeImports #446

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion dev-test/githunt/types.urql.tsx
Original file line number Diff line number Diff line change
@@ -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> = T | null;
Expand Down
9 changes: 3 additions & 6 deletions packages/plugins/typescript/urql-graphcache/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,9 @@ function getOptimisticUpdatersConfig(
}

function getImports(config: UrqlGraphCacheConfig): string {
return [
"import { offlineExchange } from '@urql/exchange-graphcache';",
`${
config.useTypeImports ? 'import type' : 'import'
} { Resolver as GraphCacheResolver, UpdateResolver as GraphCacheUpdateResolver, OptimisticMutationResolver as GraphCacheOptimisticMutationResolver } from '@urql/exchange-graphcache';\n`,
].join('\n');
return `${
config.useTypeImports ? 'import type' : 'import'
} { Resolver as GraphCacheResolver, UpdateResolver as GraphCacheUpdateResolver, OptimisticMutationResolver as GraphCacheOptimisticMutationResolver, offlineExchange } from '@urql/exchange-graphcache';\n`;
}

export const plugin: PluginFunction<UrqlGraphCacheConfig, Types.ComplexPluginOutput> = (
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T extends { __typename?: any }> = Partial<T> & { __typename: NonNullable<T['__typename']> };

export type GraphCacheKeysConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
`);
});

Expand Down