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

Make ValueSpec nullable by default #16

Open
jamesmacaulay opened this issue May 9, 2017 · 0 comments
Open

Make ValueSpec nullable by default #16

jamesmacaulay opened this issue May 9, 2017 · 0 comments

Comments

@jamesmacaulay
Copy link
Owner

Right now all GraphQL.Request.Builder.ValueSpec values are NonNull by default, and a nullable function is provided if you want to make nullable ValueSpecs. This was the natural thing to do in Elm, because wrapping the decoder with Json.Decoder.nullable is easy, and doing the reverse is more awkward.

Unfortunately, this choice of default is more error-prone if you aren't somehow validating your queries against your target schema.* If a field is nullable in the schema and you use the default non-null spec for it, the decoder will work as long as the values you encounter happen to be non-null. This can set you up for a nasty surprise in production when your non-null decoder encounters its first null value.

For the next major release, I'd like to switch this around and have nullable as the default. The error condition for using the default incorrectly will then become simply having to deal with an extra Maybe that you didn't have to before.

* Of course, you "should be" validating your queries against your schema, but the package doesn't help with this yet, and in any event the package should be as free of footguns as possible.

@jamesmacaulay jamesmacaulay added this to the 2.0 milestone May 9, 2017
@jamesmacaulay jamesmacaulay self-assigned this May 9, 2017
@jamesmacaulay jamesmacaulay changed the title Make ValueSpecs nullable by default Make ValueSpec nullable by default May 9, 2017
@jamesmacaulay jamesmacaulay removed their assignment May 9, 2017
@jamesmacaulay jamesmacaulay removed this from the 2.0 milestone Nov 10, 2017
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

1 participant