-
-
Save palkan/26958308cfbba6ae5d46b0036a2b52bb to your computer and use it in GitHub Desktop.
Custom GraphQL option
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
module CustomField | |
def initialize(*args, **kwargs, &block) | |
@my_custom_option = kwargs.delete(:custom) | |
super(*args, **kwargs, &block) | |
end | |
def resolve_field(obj, args, ctx) | |
return super if @my_custom_option.nil? | |
# do custom logic | |
end | |
end | |
# Extend you base field with custom logic | |
class ExampleType < GraphQL::Schema::Object | |
field_class.prepend(CustomField) | |
# now you can use `custom` option and enhance | |
# the default logic | |
field :name, String, custom: true | |
end | |
# you can also patch GraphQL::Schema::Field class globally | |
GraphQL::Schema::Field.prepend(CustomField) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment