Skip to content
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

Feature Request: Transform Nulls to Undefined for Prisma Query #993

Open
adarnon opened this issue Dec 12, 2020 · 1 comment
Open

Feature Request: Transform Nulls to Undefined for Prisma Query #993

adarnon opened this issue Dec 12, 2020 · 1 comment

Comments

@adarnon
Copy link

adarnon commented Dec 12, 2020

The CRUD implementation should expose a way to convert null | undefined to undefined. This would be useful especially for situations where we want to directly pass a where query.

For example, let's say I want to implement a custom resolver for a CRUD query. I can write:

t.crud.myModel({
  resolve(root, args, ctx, info) {
    const model = ctx.prisma.myModel.findUnique({ where: args.where });
    // ... Do something with the result...
    return model;
  }
})

Currently, this is not possible because of null | undefined incompatibilities. Both value might be received from GQL, but Prisma only allows undefined for fields we wish to ignore in the where query. TypeScript won't compile in strict mode, and I assume that in runtime that might even cause bugs.

Internally, the plugin's default resolvers use a custom function to convert null | undefined to undefined: https://github.com/graphql-nexus/nexus-plugin-prisma/blob/6c8801c6e1d99bfdb73a7c1c89db9607712b0e01/src/null.ts

At the very least, this function should be easily available for use. Additionally, maybe there should be a flag to have this transform done on inputs before they are pass to our resolver? Another solution would be to allow us to call the original resolver (as a 5th argument to the resolver function), so we can do some pre/post manipulation on the result.

@HendrikJan
Copy link

I guess that this is related to #863

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

No branches or pull requests

2 participants