Skip to content

Instantly share code, notes, and snippets.

@jenny-codes
Last active May 30, 2019 02:51
Show Gist options
  • Select an option

  • Save jenny-codes/288a10ac60b43befd344650ed4b19464 to your computer and use it in GitHub Desktop.

Select an option

Save jenny-codes/288a10ac60b43befd344650ed4b19464 to your computer and use it in GitHub Desktop.
# app/graphql/types/category_type.rb
class CategoryType < GraphQL::Schema::Object
field :key, String, null: true
field :name, String, null: false
field :icon_url, String, null: true
field :related_categories,
[CategoryType],
null: false,
resolver: Resolvers::RelatedCategoryResolver
def name
object.display_name
end
def icon_url
CategoryResolver.icon_url(object, context)
end
end
class CategoryResolver
# ...
def icon_url(object, context)
# business logic here
object.icon&.image_url
end
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment