Still quite new to GraphQL,
The idea is to 'secure' mutations, meaning restricting those to the current user passed in the context. Basic one :
Create = GraphQL::Relay::Mutation.define do
name "AddItem"
input_field :title, !types.String
return_field :item, Types::ItemType
return_field :errors, types[types.String]
resolve -> (object, inputs, ctx) {
if ctx[:current_user]
... do the stuff...
else
...returns an error...
end
}
end
Let's say for one having multiple mutations… this very same conditions would have to be repeated everytime needed.
I'm obviously biased by before_action available in rails; is there something similar available in graphql-ruby ? (like, 'protected mutations', in any case looking to selectively protect specific parts of the available output, in a centralized setup)
Or should the approach be completely different ?
executemethod here gist.github.com/benbonnet/5c8b90eaabf2a3cbf71a6c7f910bade0). That said, I ended up going into postgraphql (postgraphile) for those needs; a huge time-saver that dramatically reduces your graphql code boilerplate, and a real enlightment about many things rails "hides" due to its nature - Ben