class Tapioca::Dsl::Compilers::GraphqlInputObject
: [ConstantType = singleton(GraphQL::Schema::InputObject)]
~~~
end
def post_id; end
sig { returns(String) }
def body; end
sig { returns(String) }
class CreateCommentInput
# typed: true
# create_comment.rbi
~~~rbi
this compiler will produce the RBI file ‘notify_user_job.rbi` with the following content:
~~~
end
argument :post_id, ID, required: true
argument :body, String, required: true
class CreateCommentInput < GraphQL::Schema::InputObject
~~~rb
For example, with the following `GraphQL::Schema::InputObject` subclass:<br><br>(graphql-ruby.org/api-doc/2.0.11/GraphQL/Schema/InputObject).
`Tapioca::Dsl::Compilers::GraphqlInputObject` generates RBI files for subclasses of
def decorate
@override
def decorate # Skip methods explicitly defined in code arguments = constant.all_argument_definitions.select do |argument| method_defined_by_graphql?(argument.keyword.to_s) end return if arguments.empty? root.create_path(constant) do |input_object| arguments.each do |argument| name = argument.keyword.to_s input_object.create_method( name, return_type: Helpers::GraphqlTypeHelper.type_for_argument(argument, constant), ) end end end
def gather_constants
@override
def gather_constants all_classes.select { |c| GraphQL::Schema::InputObject > c } end
def graphql_input_object_argument_source_file
def graphql_input_object_argument_source_file @graphql_input_object_argument_source_file ||= GraphQL::Schema::InputObject.method(:argument).source_location&.first #: String? end
def method_defined_by_graphql?(method_name)
def method_defined_by_graphql?(method_name) method_file = constant.instance_method(method_name).source_location&.first !!(method_file && graphql_input_object_argument_source_file == method_file) end