Rails validate whether a Hash comply with a GraphQL Type

44 views Asked by At

GraphQL Type:

module Types
  class UserType < Types::BaseObject
    field :id, GraphQL::Types::ID, null: false
    field :full_name GraphQL::Types::String, null: false
    field :age, GraphQL::Types::Int, null: true
  end
end

Any Hash:

{
   id: 23,
   name: 'Kumar'
}

Question: It is needed to ensure that the hash complies with the type defined.

Why is it needed?

Regardless of the GraphQL query, sometimes it is needed to send same information to a client from other mediums, example: Web Socket.

Here, Rails(Backend) needs to ensure that data sent from both GraphQL query and Web Socket had the same formation. So, It is needed to validate the hash before sending it through Web Socket.

GraphQL Ruby Gem

0

There are 0 answers