Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Unable to use null properties in queries and mutations with TypeScript #2235

Closed
mctep opened this issue Apr 18, 2018 · 5 comments
Closed

Unable to use null properties in queries and mutations with TypeScript #2235

mctep opened this issue Apr 18, 2018 · 5 comments
Assignees

Comments

@mctep
Copy link

mctep commented Apr 18, 2018

Bug Report

Current behavior

It is impossible to mutate to null or to query by null values in TypeScript.

Reproduction

// datamodel.graphql
type Record {
  field: String
}
ctx.db.query.records({
  where: {
    field: null // Compile Error [ts]  Type 'null' is not assignable to type 'string | undefined'.
  }
});

ctx.db.mutation.updateRecord({
  data: {
    field: null // Compile Error [ts]  Type 'null' is not assignable to type 'string | undefined'.
  }
})

Expected behavior?

Input types should use nullable values for optional fields.

@danielkcz
Copy link
Contributor

danielkcz commented Apr 23, 2018

Yea, just run into this. Typescript bindings are incorrectly generated for non-required fields. I believe that issue is on this line where it doesn't include | null in case of nullable field.

https://github.com/graphql-binding/graphql-static-binding/blob/8ddd494704ee224850e6c825c4ea5da1bb464814/src/generators/graphcool-ts.ts#L262

Duplicate: graphql-binding/graphql-static-binding#75

@divyenduz
Copy link
Contributor

Thanks for reporting this one. This is resolved in prisma-binding 2.0. Please refer to the migration guide.

@FrankSandqvist
Copy link

Is prisma-binding 2.0 supposed to make update inputs that are have union types with the type and null?

I updated to 2, but it still just makes them optional (instead of nullable)

@marktani
Copy link
Contributor

In terms of GraphQL, nullable and optional is the same thing.
Are you talking about the TS types? If so, please bring this up in a new issue over at https://github.com/prismagraphql/prisma-binding 🙂

Commenting in closed issues is discouraged as it is easily lost in the sea of GitHub notifications. New issues are easier to keep in mind.

@FrankSandqvist
Copy link

FrankSandqvist commented Jun 14, 2018

Ah, thanks for replying. I made a topic in the graphql-forum further describing my problem. I can also make an issue in the repo, but first I want to make sure I'm not doing something completely wrong

Cheers

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

No branches or pull requests

6 participants