Last active
May 30, 2019 02:51
-
-
Save jenny-codes/288a10ac60b43befd344650ed4b19464 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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