Variable type casting helper #73

Open
josh opened this Issue Feb 15, 2017 · 1 comment

Projects

None yet

1 participant

@josh
Member
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!) {
  # ...
}
GRAPHQL

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

CC: @mikrobi @cheshire137

@josh
Member
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