设置ruby-graphql:找不到UserType

时间:2017-10-15 13:41:33

标签: ruby-on-rails ruby graphql

我正在尝试让graphql-ruby在我的rails应用程序上运行。到目前为止,我已经或多或少地设置了所有设置,但是当我在浏览器中访问/ graphiql页面时,我无法访问我的自定义UserType(虽然之前预定义的测试用例有效。我收到此错误开发人员工具的网络选项卡中的消息: GraphlcController #exe中的 NoMethodError #的未定义方法`UserType' GraphQL ::定义:: TypeDefiner:0x007fa3728b2348

你能帮帮我吗?

我的架构定义如下:(leaves_messenger_schema.rb)

LeavesMessengerSchema = GraphQL::Schema.define do
  mutation(Types::MutationType)
  query(Types::QueryType)
end

我的UserType定义如下:(types / user_type.rb)

Types::QueryType = GraphQL::ObjectType.define do
  name "Query"

  field :viewer, types.UserType do
    resolve ->(obj, args, ctx) {
      ctx[User.last]
    }
  end
end

和我的UserType(types / user_type.rb):

Types::UserType = GraphQL::ObjectType.define do
  name 'User'
  description 'A user'

  field :id, types.String
  field :email, types.String
end

我的routes.rb定义为每个生成器。这应该是正确的,因为我可以导航到graphiql页面并且测试用例有效。

非常感谢您给我的任何建议!

1 个答案:

答案 0 :(得分:1)

我认为您输错了,尝试从此

更改您的代码

field :viewer, types.UserType dofield :viewer, Types::UserType do

相关问题