aws-amplify / aws-amplify/amplify-codegen

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

Open
#920 2 comments 0 reactions 0 assignees View on GitHub
amplify-codegen bug transferred
Dominant language
TypeScript
Stars
59
Forks
64
PR merge metrics
No merged PRs in 30d

Description

### Environment information

```plain text
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:
```bash
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:
```bash
npm install -g ampx
```
2. **Run** the codegen command in your project:
```bash
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.