Skip to content

--statement-typename-introspection=false Flag Fails to Remove __typename in Generated Types #920

@mnai01

Description

@mnai01

Environment information

System:
  OS: Windows 10 10.0.19045
  CPU: (8) x64 Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz
  Memory: 14.02 GB / 31.95 GB
Binaries:
  Node: 20.11.1 - F:\Program Files\nodejs\node.EXE     
  Yarn: undefined - undefined
  npm: 10.2.4 - F:\Program Files\nodejs\npm.CMD        
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.5.1
  @aws-amplify/backend: 1.11.0
  @aws-amplify/backend-auth: 1.4.2
  @aws-amplify/backend-cli: 1.4.5
  @aws-amplify/backend-data: 1.3.0
  @aws-amplify/backend-deployer: 1.1.12
  @aws-amplify/backend-function: 1.10.0
  @aws-amplify/backend-output-schemas: 1.4.0
  @aws-amplify/backend-output-storage: 1.1.4
  @aws-amplify/backend-secret: 1.1.5
  @aws-amplify/backend-storage: 1.2.4
  @aws-amplify/cli-core: 1.2.1
  @aws-amplify/client-config: 1.5.4
  @aws-amplify/deployed-backend-client: 1.5.0
  @aws-amplify/form-generator: 1.0.3
  @aws-amplify/model-generator: 1.0.11
  @aws-amplify/platform-core: 1.4.0
  @aws-amplify/plugin-types: 1.6.0
  @aws-amplify/sandbox: 1.2.8
  @aws-amplify/schema-generator: 1.2.6
  aws-amplify: 6.10.2
  aws-cdk: 2.173.4
  aws-cdk-lib: 2.172.0
  typescript: 5.7.2
No AWS environment variables
No CDK environment variables

Describe the bug

When running the following command:

npx ampx generate graphql-client-code \
  --out ./src/store/api/generated \
  --format graphql-codegen \
  --statement-typename-introspection=false

the generated TypeScript types still contain __typename fields, even though --statement-typename-introspection=false is supposed to prevent them. Meanwhile, the actual client.models.* responses from Amplify do not include these __typename properties, leading to mismatched shapes in the generated types vs. the returned data.

Reproduction steps

  1. Install or update Amplify / ampx:
    npm install -g ampx
  2. Run the codegen command in your project:
    npx ampx generate graphql-client-code \
      --out ./src/store/api/generated \
      --format graphql-codegen \
      --statement-typename-introspection=false
  3. Observe that the generated files in ./src/store/api/generated still include __typename fields.
  4. Compare the returned objects from client.models.* (which do not include __typename) to the generated types (which do include it) and note the mismatch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    amplify-codegenIssues on amplify-codegenbugSomething isn't workingtransferredIssue has been transferred from another Amplify repository

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions