dotansimha / graphql-code-generator

A tool for generating code based on a GraphQL schema and GraphQL operations (query/mutation/subscription), with flexible support for custom plugins.
https://the-guild.dev/graphql/codegen/
MIT License
10.81k stars 1.32k forks source link

Disable fragmentMasking not working #10006

Closed nemonemi closed 3 months ago

nemonemi commented 3 months ago

Which packages are impacted by your issue?

No response

Describe the bug

Previously, when generating types from the graphql schema I would get a normal and expected type:

export type SomeMutation = { __typename: 'Mutation', myProject: { __typename: 'MyProject',... } | { __typename: 'MyProjectClosedError', message: string } | { __typename: 'MyProjectNotFoundError', message: string } | { __typename: 'SupplierNotFound', message: string } };

Now, the query contains fragments, but until now they were just a means of optimizing the queries.

After updating Codegen and MSW, I now get this:

export type SomeMutation = { __typename: 'Mutation', myProject: (
    { __typename: 'MyProject' }
    & { ' $fragmentRefs'?: { 'ProjectFirstLevelPropertiesFragmentFragment': ProjectFirstLevelPropertiesFragmentFragment;'ProjectSupplierFragmentFragment': ProjectSupplierFragmentFragment;'ProjectWorkflowStepsFragmentFragment': ProjectWorkflowStepsFragmentFragment } }
  ) | { __typename: 'MyProjectClosedError', message: string } | { __typename: 'MyProjectNotFoundError', message: string } | { __typename: 'SupplierNotFound', message: string } };

It's not just the structure that changed, but the whole model. This is not usable, any longer.

Your Example Website or App

I hope it is not needed, and it's just a configuration issue on my part.

Steps to Reproduce the Bug or Issue

...

Expected behavior

I expect that, unless I opt-in for a new behavior explicitly, that the schema is generated as previously.

Screenshots or Videos

No response

Platform

Codegen Config File

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

const config: CodegenConfig = {
  overwrite: true,
  schema: 'libs/mocks/orchestrator-mocks/src/mocks/schema.graphql',
  documents: ['apps/**/*.graphql', 'apps/**/*.ts', 'libs/**/*.graphql', 'libs/**/*.ts'],
  generates: {
    'libs/mocks/orchestrator-schema/generated/': {
      preset: 'client',
      plugins: ['typescript-msw'],
      config: {
        futureProofEnums: false,
        fetcher: 'graphql-request',
        enumsAsConst: true,
        scalars: { Date: 'DateScalar', DateTime: 'Date' },
        nonOptionalTypename: true,
        presetConfig: {
          fragmentMasking: false
        }
      },
    },
    'libs/mocks/orchestrator-schema/generated/graphql.schema.json': {
      plugins: ['introspection'],
    },
  },
};

Additional context

No response

nemonemi commented 3 months ago

Please disregard this. I passed the property wrong.

It should be:

generates: {
  presetConfig: {
        fragmentMasking: false
      }
}

Instead of:

generates: {
  config: {
    presetConfig: {
        fragmentMasking: false
      }
  }
}