Skip to content

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

@HalfdanJ

Description

@HalfdanJ

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions