dotansimha / graphql-code-generator-community

MIT License
116 stars 153 forks source link

Type-graphql doesn't support a scalar as input argument type #119

Open tatejones opened 3 years ago

tatejones commented 3 years ago

Describe the bug When a mutation argument type contains a scalar property the generated code fails to compile. The scalar is wrapped with either a FixFixture<> or Maybe<> with the error message "Cannot find name ''"

To Reproduce

  1. Create a schema that contains a mutation with with null or non-null argument scalar property (see below)
  2. Generates the following code for the argument.

@TypeGraphQL.ArgsType() export class MutationRemoveUserArgs {

@TypeGraphQL.Field(type => CustomID) id!: FixDecorator; };

Error message: "Cannot find name 'CustomID"

  1. My GraphQL schema:
scalar CustomID

interface Node {
    id: CustomID!
}

type User implements Node {
    id: CustomID!
    username: String!
    email: String!
}

type Mutation {
    removeUser(id: CustomID!): RemoveByIdEmployeePayload
}

type RemoveByIdEmployeePayload {
    id: CustomID!
}
  1. My GraphQL operations:
None
  1. My codegen.yml config file:
schema: schema.graphql
config:
    scalars:
        CustomID: String
generates:
    ./generatedTypeGraphQL.ts:
        plugins:
            - typescript-type-graphql

Expected behavior

Expecting the argument class to be:

@TypeGraphQL.ArgsType() export class MutationRemoveUserArgs {

@TypeGraphQL.Field(type => String) id!: FixDecorator<Scalars['CustomID']>; };

Environment:

tatejones commented 3 years ago

Sandbox https://codesandbox.io/live/7g1qgcz