Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Use ? for nullable fields #25

Closed
timsuchanek opened this issue Aug 20, 2018 · 0 comments · Fixed by #26
Closed

Use ? for nullable fields #25

timsuchanek opened this issue Aug 20, 2018 · 0 comments · Fixed by #26

Comments

@timsuchanek
Copy link
Contributor

If you have a type that includes an optional field, the following is generated right now:

export interface PlaceRoot {
  id: string
  name: string
  size: PLACE_SIZES | null
  maxGuests: number
}

This means that the resolver needs to return an explicit null value:

const resolvers = {
  size: () => null
}

However, graphqljs allows returning undefined for a nullable value.
This makes implementations easier, as we don't need to return an explicit null anymore.

To make this possible, the only difference is turning | null into ?:

export interface PlaceRoot {
  id: string
  name: string
  size?: PLACE_SIZES
  maxGuests: number
}

I just tested it in TypeScript 2.9.2 - ? allows both undefined and null.

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

Successfully merging a pull request may close this issue.

1 participant