Amplify-cli: Nested Typescript Types are not generated as Types

Created on 13 May 2020  路  2Comments  路  Source: aws-amplify/amplify-cli

Describe the bug
When running amplify codegen with Typescript option, if the Schema contains nested Types, they will be generated as plain objects with no proper Type.

Amplify CLI Version
4.19.0

To Reproduce
Consider the following Schema:

type Query { 
    listTest(from: AWSDateTime!, to: AWSDateTime!): myTypeConnection 
} 
type myTypeConnection {
    items: [myType]
    nextToken: String
}
type myType {
    id: ID! some_string: String!
    some_date: AWSDateTime!
}
 ```
The resulting codegen TS file will contain:

export type ListTestQuery = {
listTest: {
__typename: "myTypeConnection",
items: Array< {
__typename: "myType",
id: string,
some_string: string,
some_date: string
} | null > | null,
nextToken: string | null,
} | null,
};

**Expected behavior**
Since we defined proper types in GraphQL schema, I expected all GraphQL types to be transpiled into Typescript Types. Something like:

export type MyType {
id: string,
some_string: string,
some_date: string
}

export type MyTypeConnection {
items: Array< MyType | null > | null,
nextToken: string | null,
}

export type ListTestQuery = {
listTest: MyTypeConnection | null,
};
```

Desktop (please complete the following information):

  • OS: Ubuntu 18.04.4 LTS
  • Node v11.15.0

Additional context
If this is not a bug kindly let me know and I'll open a feature request. I see no reason why any Type defined in the Schema can't become a Type in generated Typescript code, especially since the addition of the --max-depth which I tried to no avail. Thus, I consider this a bug.

Thanks in advance

code-gen enhancement

Most helpful comment

I've been using this package to help, https://graphql-code-generator.com/docs/plugins/typescript, and to me it seems the output is the same as if you run this tool with onlyOperationTypes: true configured in its options. I think Amplify uses the same plugin under the hood so I wonder if this can be made configurable?

All 2 comments

I've been using this package to help, https://graphql-code-generator.com/docs/plugins/typescript, and to me it seems the output is the same as if you run this tool with onlyOperationTypes: true configured in its options. I think Amplify uses the same plugin under the hood so I wonder if this can be made configurable?

+1 I also hope that this feature will be considered since it would be really helpful if they are generated as type.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amlcodes picture amlcodes  路  3Comments

ReidWeb picture ReidWeb  路  3Comments

onlybakam picture onlybakam  路  3Comments

davo301 picture davo301  路  3Comments

kangks picture kangks  路  3Comments