Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
create function
# frozen_string_literal: true
class CreateFunction < GraphQL::Function
attr_reader :type
def initialize(model)
@model = model
@type = ModelType.new(model) # creates a graphql type from a model
end
def arguments
fields = @type.all_fields.select do |field|
# some logic for which fields we want to expose
end
args = fields.map { |field| [field.name, field.type] }
args.map { |a| GraphQL::Argument.from_dsl(*a) }.mash { |a| [a.name, a] }
end
def call(_obj, args, ctx)
# parse and check the args
# check ctx for some authorization stuff
@model.create(args)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.