Variable type casting helper #73

josh opened this Issue Feb 15, 2017 · 1 comment


None yet

1 participant

josh commented Feb 15, 2017

ActiveRecord has some nice (and some dangerous) params type casting features. This allows you to pass a string "0" or "1" to an attribute that is a boolean in the database and have it cast to a true boolean.

Since GraphQL variables have declared types, we should be able to handle this at the controller layer and cast this input before sending it to the backend.

Sketch API:

FooQuery = <<-'GRAPHQL'
query($bool: Boolean!, $int: Int!) {
  # ...

variables = Client.cast_variables(FooQuery, { bool: "1", int: "42" })
variables #=> { bool: true, int: 42 }

CC: @mikrobi @cheshire137

josh commented Feb 15, 2017

I'm realizing this is similar to the validation case posted in #43.

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