Skip to content

Instantly share code, notes, and snippets.

@onedebos
Last active March 26, 2020 16:19
Show Gist options
  • Save onedebos/dd447bf5c081c003386241e01e569cbc to your computer and use it in GitHub Desktop.
Save onedebos/dd447bf5c081c003386241e01e569cbc to your computer and use it in GitHub Desktop.
module Types
class QueryType < Types::BaseObject
field :summary, [Types::SummaryType], null: false
field :all_countries, [Types::CountryType], null: false
field :find_country, [CountryType], null: true do
argument :country_name, String, required: true
end
field :all_countries_limit, [CountryType], null: false do
argument :per_page, Integer, required: false, default_value: 10
argument :start, Integer, required: false, default_value: 1
end
field :country_filter, [CountryType], null: false do
argument :text, String, required: true
end
def all_countries_limit(per_page:,start:)
country = Country.limit(per_page).offset(start - 1)
end
def all_countries
Country.all.order(country_name: :asc)
end
def country_filter(text:)
Country.where("country_name LIKE ?", "%#{text.downcase.capitalize}%")
end
def summary
Summary.all
end
def find_country(country_name:)
country_name = country_name.downcase
Country.where(country_name: country_name.capitalize)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment