`[String!]!` is translating to typescript type `Array<Scalars['String']> | Scalars['String']`
See original GitHub issueIssue workflow progress
Progress of the issue based on the Contributor Workflow
- 1. The issue provides a reproduction available on GitHub, Stackblitz or CodeSandbox
Link to codesandbox: https://codesandbox.io/s/hardcore-tdd-q7uyd1?file=/types.ts
- 2. A failing test has been provided
- 3. A local solution has been provided
- 4. A pull request is pending review
Describe the bug
The graphql type [String!]!
, i.e., a non-nullable array of non-nullable strings, is converted to Array<Scalars['String']> | Scalars['String']
rather than only Array<Scalars['String']>
.
To Reproduce Steps to reproduce the behavior:
- My GraphQL schema:
type ProjectCreateMutation {
response: String!
message: String!
}
type Mutation {
createProject(
description: String!
name: String!
subtitle: String!
tags: [String]!
): ProjectCreateMutation
}
type Query {
getMessage: String
}
- My GraphQL operations:
mutation createNewProject(
$description: String!
$name: String!
$subtitle: String!
$tags: [String!]!
) {
createProject(
description: $description
name: $name
subtitle: $subtitle
tags: $tags
) {
response
message
}
}
- My
codegen.yml
config file:
overwrite: true
schema: schema.graphql
documents: document.ts
generates:
types.ts:
plugins:
- typescript
- typescript-operations
Expected behavior
[String!]!
should be converted to Array<Scalars['String']>
Environment:
- OS: Linux (PopOS)
@graphql-codegen/...
:
{
"dependencies": {
"@graphql-codegen/cli": "2.6.2",
"@graphql-codegen/typescript": "2.4.11",
"@graphql-codegen/typescript-graphql-files-modules": "2.1.1",
"@graphql-codegen/typescript-operations": "2.4.0",
"graphql-request": "^4.3.0",
"graphql": "^16.5.0"
}
}
- NodeJS: v16.14.2
Additional context
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:7
Top Results From Across the Web
Converting a type containing string separated by periods into ...
I want to use TypeScript to make some generic type StringToNestedObject that takes a string like that and outputs a type nested object...
Read more >typesafe-i18n - npm
A fully type-safe and lightweight internationalization library for all your TypeScript and JavaScript projects.. Latest version: 5.18.0, last published: 15 ...
Read more >Make the translation function fully type-safe #1504 - GitHub
TypeScript 4.1 introduces recursive conditional types, and there is a PR open that will enable string type concatenation on the type level.
Read more >Automatically generate Typescript types for your GraphQL ...
Introduction. In this post, I will show you how to automatically generate types for your GraphQL APIs written in Typescript using GraphQL ...
Read more >How To Generate TypeScript Types From GraphQL - DatoCMS
To define types, you should use a GraphQL code generator. This is because it enables you to automatically generate the required TypeScript types ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I believe this is expected, because of input coercion for lists: https://spec.graphql.org/June2018/#sec-Type-System.List
I think we can close this issue then 😃