Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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