graphql-code-generator-community icon indicating copy to clipboard operation
graphql-code-generator-community copied to clipboard

offlineExchange import from @urql/exchange-graphcache not respecting `useTypeImports`

Open HalfdanJ opened this issue 2 years ago • 1 comments

Which packages are impacted by your issue?

@graphql-codegen/typescript-urql-graphcache

Describe the bug

The code generator adds an import for offlineExchange from '@urql/exchange-graphcache', but it is not using the config.useTypeImports config to determine if the import should by type import.

offlineExchange is only used in the following generated code (which only requires types):

export type GraphCacheConfig = Parameters<typeof offlineExchange>[0] & {
  updates?: GraphCacheUpdaters,
  keys?: GraphCacheKeysConfig,
  optimistic?: GraphCacheOptimisticUpdaters,
  resolvers?: GraphCacheResolvers,
};

Using the library with importsNotUsedAsValues set to error will throw an error with the imported code.

Your Example Website or App

https://stackblitz.com/edit/github-pg6z88?file=package.json

Steps to Reproduce the Bug or Issue

Open stackblitz, and run npm run check

Expected behavior

tsc command succeeds, instead it throws an error.

Screenshots or Videos

No response

Platform

  • OS: macOS
  • NodeJS: 18.18
  • graphql version:16.2
  • @graphql-codegen/typescript-urql-graphcache version: 3.0.0

Codegen Config File

import type { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
  schema: 'schema.graphql',
  documents: 'document.graphql',
  generates: {
    'types.ts': {
      config: {
        useTypeImports: true,
      },
      plugins: [
        'typescript',
        'typescript-operations',
        'typescript-urql-graphcache',
      ],
    },
  },
};

export default config;

Additional context

No response

HalfdanJ avatar Oct 07 '23 20:10 HalfdanJ

Created a PR that should fix this issue here too: https://github.com/dotansimha/graphql-code-generator-community/pull/1110

dargmuesli avatar May 23 '25 06:05 dargmuesli