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

[client-preset] if gqlTagName is changed doesn't generate any documents #9820

Open
Yagogc opened this issue Jan 18, 2024 · 0 comments
Open

Comments

@Yagogc
Copy link

Yagogc commented Jan 18, 2024

Which packages are impacted by your issue?

@graphql-codegen/client-preset

Describe the bug

I need to generate types for 2 differents schemas, so to avoid clashing with the ts pluging @0no-co/graphqlsp I'm separating them by the use of the gql tag.

The problem is that when I change the presetConfig.gqlTagName to something else that's not graphql or gql when tries to generate the documents it's not able to parse the new tagName creating an empty document array in gql.ts

Your Example Website or App

none

Steps to Reproduce the Bug or Issue

  1. In codegen.ts for the client preset change the gqlTagName to something else. i.e:
      presetConfig: {
        gqlTagName: 'gqlX',
      },
  1. Modify one of the queries w/ the new function name:
import { gqlX } from '../generated/X';

const pageCollectionQuery = gqlX(`
  query PageCollection {
    pageCollection {
      items {
        sys {
          id
        }
      }
    }
  }
`);

export { pageCollectionQuery };
  1. after running codegen the updated gql.ts file will have an empty document variable:
const documents = [];

Expected behavior

I expect that the gql.ts document variable is populated as expected:

const documents = {
    "\n  query something {\n    pageCollection {\n      items {\n        sys {\n          id\n        }\n        title\n        slug\n      }\n    }\n  }\n": types.SomethingDocument,
};

Screenshots or Videos

No response

Platform

  • OS: macOS
  • NodeJS: 20.9.0
  • graphql: 16.8.1,
  • @graphql-codegen/cli: 5.0.0,
  • @graphql-codegen/client-preset: 4.1.0,

Codegen Config File

No response

Additional context

// codegen.ts

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

import env from './env';

const schema1Endpoint = env.SCHEMA_1;
const schema2Endpoint = env.SCHEMA_2;


const config: CodegenConfig = {
  overwrite: true,
  ignoreNoDocuments: true,
  generates: {
    './src/graphql/generated/schema1/': {
      schema: schema1Endpoint,
      documents: './src/graphql/schema1/**/*.{ts,tsx}',
      preset: 'client',
      presetConfig: {
        gqlTagName: 'gqlSchema1',
      },
      config: {
        useTypeImports: true,
      },
    },
    './src/graphql/generated/schema1/schema.graphql': {
      schema: schema1Endpoint,
      plugins: ['schema-ast'],
    },
    './src/graphql/generated/schema2/': {
      documents: './src/graphql/schema2/**/*.{ts,tsx}',
      schema: schema2Endpoint,
      preset: 'client',
      presetConfig: {
        gqlTagName: 'gqlSchema2',
      },
      config: {
        useTypeImports: true,
      },
    },
    './src/graphql/generated/schema2/schema.graphql': {
      schema: schema2Endpoint,
      plugins: ['schema-ast'],
    },
  },
};

export default config;
tsconfig.json

...
"plugins": [
  {
    "name": "@0no-co/graphqlsp",
    "schema": "./src/graphql/generated/schema1/schema.graphql",
    "disableTypegen": true,
    "templateIsCallExpression": true,
    "template": "gqlSchema1"
  }
  {
    "name": "@0no-co/graphqlsp",
    "schema": "./src/graphql/generated/schema2/schema.graphql",
    "disableTypegen": true,
    "templateIsCallExpression": true,
    "template": "gqlSchema2"
  }
],
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant