Skip to content

Commit

Permalink
Support unchecked scalars input by a generator option
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalLytek committed Jan 27, 2021
1 parent e85e9b4 commit 737e230
Show file tree
Hide file tree
Showing 146 changed files with 3,535 additions and 704 deletions.
38 changes: 38 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,44 @@ const server = new ApolloServer({
});
```

### Unchecked scalars input

GraphQL does not support input unions, hence it's not possible to support both normal inputs and unchecked scalars input at the same time like the Prisma does.

If you prefer simplicity over more sophisticated solutions like `connectOrCreate`, you can to provide the `useUncheckedScalarInputs` generator option:

```prisma
generator typegraphql {
provider = "typegraphql-prisma"
output = "../prisma/generated/type-graphql"
useUncheckedScalarInputs = true
}
```

This way there will be generate input classes with relation id fields, instead of the normal "nested" inputs for creating/updating relations, e.g.:

```ts
@TypeGraphQL.InputType({
isAbstract: true,
})
export class PostUncheckedCreateInput {
@TypeGraphQL.Field(_type => String, {
nullable: false,
})
title!: string;

@TypeGraphQL.Field(_type => TypeGraphQL.Int, {
nullable: false,
})
authorId!: number;

@TypeGraphQL.Field(_type => TypeGraphQL.Int, {
nullable: true,
})
editorId?: number | undefined;
}
```

### Nest JS

In order to use generated types and resolvers classes in NestJS, you need to use the [official `typegraphql-nestjs` package](https://github.com/MichalLytek/typegraphql-nestjs). This module allows for basic integration of TypeGraphQL with NestJS. You can find an example in the [`examples/4-nest-js` folder](https://github.com/MichalLytek/typegraphql-prisma/tree/main/examples/4-nest-js).
Expand Down
Loading

0 comments on commit 737e230

Please sign in to comment.