question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`[String!]!` is translating to typescript type `Array<Scalars['String']> | Scalars['String']`

See original GitHub issue

Issue workflow progress

Progress of the issue based on the Contributor Workflow

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:

  1. 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
}
  1. My GraphQL operations:
mutation createNewProject(
  $description: String!
  $name: String!
  $subtitle: String!
  $tags: [String!]!
  ) {
  createProject(
      description: $description
      name: $name
      subtitle: $subtitle
      tags: $tags
  ) {
      response
      message
  }
}
  1. 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:closed
  • Created a year ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

3reactions
falkenhawkcommented, Jul 5, 2022

I believe this is expected, because of input coercion for lists: https://spec.graphql.org/June2018/#sec-Type-System.List

2reactions
ardatancommented, Aug 7, 2022

I think we can close this issue then 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found