【发布时间】:2018-10-25 09:31:24
【问题描述】:
我正在尝试制作一个 GraphQL API,但也通过dry-rb_autoinject 实现依赖注入。我设法通过控制器和上下文来做到这一点。这是我的测试 QueryType。
Types::QueryType = GraphQL::ObjectType.define do
name "Query"
# Add root-level fields here.
# They will be entry points for queries on your schema.
# TODO: remove me
field :testField, types.String do
description "An example field added by the generator"
resolve ->(obj, args, ctx) {
ctx[:services][:output_service].()
}
end
end
我只是在 graphql_controller 中做
class GraphqlController < ApplicationController
include IMPORT[:output_service]
def execute
...
services: {
output_service: output_service
}
...
但是这个解决方案似乎不是很好,因为我导入了所有服务,即使是我不需要的当前字段。有没有更好的方法,也许不是通过上下文?
【问题讨论】:
标签: ruby-on-rails ruby graphql graphql-ruby dry-rb