class Tapioca::Dsl::Compilers::GraphqlMutation
~~~
end
def resolve(body:, post_id:); end
sig { params(body: String, post_id: String).returns(T.untyped) }
class CreateComment
# typed: true
# create_comment.rbi
~~~rbi
this compiler will produce the RBI file ‘notify_user_job.rbi` with the following content:
~~~
end
end
# …
def resolve(body:, post_id:)
argument :post_id, ID, required: true
argument :body, String, required: true
class CreateComment < GraphQL::Schema::Mutation
~~~rb
For example, with the following `GraphQL::Schema::Mutation` subclass:<br><br>(graphql-ruby.org/api-doc/2.0.11/GraphQL/Schema/Mutation).
`Tapioca::Dsl::Compilers::GraphqlMutation` generates RBI files for subclasses of
def argument_type(argument, constant)
def argument_type(argument, constant) return "T.untyped" unless argument Helpers::GraphqlTypeHelper.type_for_argument(argument, constant) end
def decorate
def decorate return unless constant.method_defined?(:resolve) method_def = constant.instance_method(:resolve) return if signature_of(method_def) # Skip if the mutation already has an inline sig arguments = constant.all_argument_definitions return if arguments.empty? arguments_by_name = arguments.to_h { |a| [a.keyword.to_s, a] } params = compile_method_parameters_to_rbi(method_def).map do |param| name = param.param.name argument = arguments_by_name.fetch(name, nil) create_typed_param(param.param, argument_type(argument, constant)) end root.create_path(constant) do |mutation| mutation.create_method("resolve", parameters: params, return_type: "T.untyped") end end
def gather_constants
def gather_constants all_classes.select { |c| GraphQL::Schema::Mutation > c && GraphQL::Schema::RelayClassicMutation != c } end