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

Support graphql-config type #26

Open
deathemperor opened this issue Dec 17, 2023 · 2 comments
Open

Support graphql-config type #26

deathemperor opened this issue Dec 17, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@deathemperor
Copy link

I'm using this plugin with https://the-guild.dev/graphql/config/docs. although the type causes TS error, it works:

error

Argument of type 'IGraphQLConfig' is not assignable to parameter of type 'Options | undefined'.
  Type 'IGraphQLProject' has no properties in common with type 'Options'.ts(2345)

sample of graphql-config

import type { IGraphQLConfig } from "graphql-config";

const codegenConfig: IGraphQLConfig = {
  schema,
  documents: ["src/**/!(*.generated).{tsx,ts,graphql,gql}", "!src/sdk/**/*", "!node_modules"],
  extensions: {
    languageService: {
      cacheSchemaFileForLookup: true,
    },
    codegen: {
      overwrite: true,
      watch: CODEGEN_WATCH === "true",
      ignoreFieldConflicts: true,
      generates: {
        "src/sdk/gql/types.ts": {
          config: {
            ...config,
          },
          plugins: [
            "typescript",
          ],
        },
        "src/": {
          preset: "near-operation-file",
          presetConfig: {
            extension: ".generated.ts",
            baseTypesPath: "sdk/gql/types.ts",
          },
          plugins: [
            "typescript-operations",
            "typed-document-node",
            {
              add: {
                content: `/* eslint-disable */`,
              },
            },
          ],
        },
      },
    },
  },
};

export default codegenConfig;
@danielwaltz
Copy link
Owner

Ah, that's interesting! I think it's because the type for the plugin only expects a codegen config type, but doesn't also allow the more generic graphql config type.

I can look into adding the option to pass a more generic graphql config as well! I'm not sure if there are consequences in doing that, but I'll try it out and see what I can find.

If it works in the meantime, are you able to restructure your config so that the schema/documents are inside of the codegen config itself instead, sorta like this? Then maybe there's another way to actually set languageService.cacheSchemaFileForLookup like you are doing.

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

const codegenConfig: CodegenConfig = {
  overwrite: true,
  schema,
  documents: [
    'src/**/!(*.generated).{tsx,ts,graphql,gql}',
    '!src/sdk/**/*',
    '!node_modules',
  ],
  watch: CODEGEN_WATCH === 'true',
  ignoreFieldConflicts: true,
  generates: {
    'src/sdk/gql/types.ts': {
      config: {
        ...config,
      },
      plugins: ['typescript'],
    },
    'src/': {
      preset: 'near-operation-file',
      presetConfig: {
        extension: '.generated.ts',
        baseTypesPath: 'sdk/gql/types.ts',
      },
      plugins: [
        'typescript-operations',
        'typed-document-node',
        {
          add: {
            content: `/* eslint-disable */`,
          },
        },
      ],
    },
  },
};

export default codegenConfig;

Another option may be using a dedicated file for the graphql config, and referencing that file instead in the plugin options like this:

import codegen from 'vite-plugin-graphql-codegen';

codegen({ configFilePathOverride: 'path/to/graphql.config.yml' })

@danielwaltz danielwaltz added bug Something isn't working enhancement New feature or request and removed bug Something isn't working labels Dec 18, 2023
@deathemperor
Copy link
Author

Not sure what you meant with option 1 but I'm using option 2 anyways due to some schema overrides that only works with codegen but not vscode and it works great except I have to load the config fire myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants