aws-amplify / aws-amplify/amplify-codegen
Configure validation of the graphql schema
- Dominant language
- TypeScript
- Stars
- 59
- Forks
- 64
- PR merge metrics
- No merged PRs in 30d
Description
### Before opening, please confirm:
- [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-codegen/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-codegen/blob/main/CONTRIBUTING.md#bugs).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
### How did you install the Amplify CLI?
npm
### If applicable, what version of Node.js are you using?
v18.15.0
### Amplify CLI Version
11.0.3
### What operating system are you using?
Windows
### Amplify Codegen Command
codegen
### Describe the bug
During code generation for typescript types, a union causes type generation to fail due to conflicting types on the schema
### Expected behavior
It generates the correct `graphqlTypes.ts` without issue for conflicting types. If necessary provide configuration to turn off graphql validation for this rule
### Reproduction steps
1. Setup codegen with defaults
2. Use the supplied graphql schema
3. Run `amplify codegen`
### GraphQL schema(s)
```graphql
# Put schemas below this line
schema {
query: Query
}
type Query{
get: [Unioned]
}
union Unioned = Simple | More_Complex
type Complex {
foo: String
}
type More_Complex {
value: Complex
}
type Simple {
value: String
}
```
### Log output
```
# Put your logs below this line
- Generating.../XX/graphql/queries.ts: Fields "value" conflict because they return conflicting types "String" and "Complex". Use different aliases on the fields to fetch both if this was intentional.
.../XX/graphql/queries.ts: Fields "value" conflict because they return conflicting types "String" and "Complex". Use different aliases on the fields to fetch both if this was intentional.
✖ Validation of GraphQL query document failed
```
### Additional information
Here is the output with graphql validation turned off. This is what I want
```
/* tslint:disable */
/* eslint-disable */
// This file was automatically generated and should not be edited.
export type Unioned = Simple | More_Complex
export type Simple = {
__typename: "Simple",
value?: string | null,
};
export type More_Complex = {
__typename: "More_Complex",
value?: Complex | null,
};
export type Complex = {
__typename: "Complex",
foo?: string | null,
};
export type GetQuery = {
get: Array<( {
__typename: "Simple",
value?: string | null,
} | {
__typename: "More_Complex",
value?: {
__typename: string,
foo?: string | null,
} | null,
}
) | null > | null,
};
```
Contributor guide
Assessment
This issue has not been assessed yet.