Skip to content

Hasura action codegen may generate invalid typescript if reserved symbols are used as scalars #6544

@beepsoft

Description

@beepsoft

In my data model I use Postgresql "bigint" ID-s and and tried to use the same types in an action like this:

type Mutation {
  doSomething (
    arg: SampleInput!
  ): SampleOutput
}

scalar bigint

input SampleInput {
  id : bigint!
}

type SampleOutput {
  id : bigint!
}

For this I tried generating code using the typescript-express codegen:

type Maybe<T> = T | null

type bigint = string

type Mutation = {
  doSomething?: Maybe<SampleOutput>
}

type doSomethingArgs = {
  arg: SampleInput
}

type SampleOutput = {
  id: bigint
}

type SampleInput = {
  id: bigint
}

The

type bigint = string

line results in a Type alias name cannot be 'bigint'.(2457) typescript error. It turns out bigint is a reserved javascript symbol.

Here's just the offending line in a ts playground

https://www.typescriptlang.org/play?ts=4.1.3#code/KYDwDg9gTgLgBDAnmYcBGBLA5hgdvAXjgGcYo8sAoIA

https://graphql-code-generator.com/ solves this by defining and using scalar types like this:

export type Scalars = {
  bigint: any;
};

export type SampleInput = {
  id: Scalars['bigint'];
};

Would it be possible to make something similar in tha Hasura action codegen so that the output won't have clashes with reserved names?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions