Skip to content

Prisma-binding produces incorrect types for nullable update mutations #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
FrankSandqvist opened this issue Jun 14, 2018 · 7 comments
Closed
Assignees

Comments

@FrankSandqvist
Copy link

For a type with a nullable field, I should be able to send a mutation to update any of the nullable fields to null.

E.g.

ctx.db.mutation.updateCompany({
    where: { slug: "myCompany" },
    data: { vatNumber: null }
}, info);

However this yields a typescript error “Type ‘null’ is not assignable to type ‘string | undefined’.” This is because Prisma-binding produces incorrect types for the update input:

export interface CompanyUpdateInput {
  slug?: String
  name?: String
  vatNumber?: String
  businessId?: String
}

The nullable fields (vatNumber & businessId) should have the union type String | null, so I can null them if I wish.

https://www.prisma.io/forum/t/prisma-binding-produces-incorrect-types-for-nullable-update-mutations/3771

Best,
Frank

@FrankSandqvist
Copy link
Author

FrankSandqvist commented Jun 14, 2018

Or as nilan suggested String | null | undefined.

I suppose either

field?: Type | null
or
field: Type | null | undefined
could work?

@mattferrin
Copy link

mattferrin commented Aug 2, 2018

I had to do:

    const data: any = { vatNumber: null };

    ctx.db.mutation.updateCompany(
      {
        where: { slug: "myCompany" },
        data
      },
      info
    );

@agonbina
Copy link

You can also use null! to turn the null into a never type, which is accepted for any type. Obviously this does not solve the actual problem, which is that the autogenerated type is plain wrong.

@nemcek
Copy link

nemcek commented Oct 8, 2018

Any update on fixing generated types?

@maticzav
Copy link
Collaborator

Hey 👋, I believe this issue is no longer in sync with the current version of prisma-binding. In need for gaining a better overview of the issues facing the current version, I'll close it.

Feel free to reopen the issue if you believe we should further discuss its content. 🙂

@nemcek
Copy link

nemcek commented Nov 29, 2018

Hey @maticzav I don't see how this is out of sync.
Using prisma-binding@2.2.8 with datamodel as

type Post {
  id: ID! @unique
  title: String!
  body: String
}

The generated types are:

// ...
export interface Post extends Node {
  id: ID_Output
  title: String
  body?: String
}
// ...
export interface PostCreateInput {
  title: String
  body?: String
}
// ...
export interface PostUpdateInput {
  title?: String
  body?: String
}

No nullable types anywhere.
I think this should be resolved in graphql-binding and not prisma-binding as people can use graphql-binding to generate types for their own bindings.

@timsuchanek timsuchanek reopened this Dec 3, 2018
@schickling
Copy link
Contributor

🎉 This issue has been resolved in version 2.2.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants