I want to use dependency injection with graphql-ruby.
I.e.
module CustomerCredits
module Types
class QueryType < GraphQL::Schema::Object
description 'The query root of this schema'
field :filter_users, [Types::UserType], null: false do
argument :parameters, InputTypes::UserFilterParameters, required: true
end
# resolvers
def filter_users(arguments)
repo = UserRepository.new(complex_arguments) # I want to inject the dependency UserRepository
repo.filtered_users(**arguments[:parameters])
end
end
end
end
Using dependency injection in initialize
is not possible, because QueryType
is instantiated by graphql-ruby.