GraphQL::QueryArgument
A simple query argument for resolver module
Installation
Add this line to your application's Gemfile:
gem 'graphql_query_argument'
And then execute:
$ bundle
Or install it yourself as:
$ gem install graphql_query_argument
Usage
require 'graphql/query_argument'
# In your field resolver
# `Products < Resolvers::Base` & a CategoryQueryInputs & a `CompanyType` GraphQL type:
#
module Resolvers
class Products < Resolvers::Base
include GraphQL::QueryArgument
type [Types::ProductType], null: false
query_argument :name, type: [String], required: false do |scope, value|
scope.where(name: value)
end
query_argument :categories, type: Types::CategoryQueryInputs, required: false do |scope, value|
scope.joins(:categories).where(categieies: { **value })
end
end
end
# `CompanyType`
class CompanyType < Types::BaseObject
field :products, null: false, resolver: Resolvers::Products
def products
object.products
end
end
# `CategoryQueryInputs`
module Types
class CategoryQueryInputs < Types::BaseInputObject
argument :name, [String], required: false
end
end