[英]Setting up ruby-graphql: UserType not found
I'm trying to make graphql-ruby working on my rails app. 我正在尝试在我的Rails应用程序上运行graphql-ruby。 So far I got everything set up more or less, but when I go to the /graphiql page in my browser, I don't have access to my custom UserType (the predefined test case worked before, though. I'm getting this error message in the network tab of the developer tools: NoMethodError in GraphqlController#execute undefined method `UserType' for # GraphQL::Define::TypeDefiner:0x007fa3728b2348
到目前为止,我已经或多或少地进行了所有设置,但是当我进入浏览器中的/ graphiql页面时,我无权访问自定义UserType(不过,预定义的测试用例之前已经起作用了。我遇到了此错误开发人员工具的网络标签中的错误消息: GraphqlController#execute #GraphQL :: Define :: TypeDefiner:0x007fa3728b2348的未定义方法'UserType'中的NoMethodError
Can you help me? 你能帮助我吗?
My schema is defined as following: (leaves_messenger_schema.rb) 我的架构定义如下:(leaves_messenger_schema.rb)
LeavesMessengerSchema = GraphQL::Schema.define do
mutation(Types::MutationType)
query(Types::QueryType)
end
My UserType is defined as follows: (types/user_type.rb) 我的用户类型定义如下:(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
and my UserType (types/user_type.rb): 和我的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
my routes.rb is defined as per generator. 我的route.rb被定义为每个生成器。 That should be correct since I can navigate to the graphiql page and the test case worked.
这应该是正确的,因为我可以导航到graphiql页面,并且测试用例可以正常工作。
Thanks a lot for any advice you can give me! 非常感谢您可以给我的任何建议!
i think you made a typo, try to change your code from this 我认为您输入有误,请尝试从中更改代码
field :viewer, types.UserType do
to field :viewer, Types::UserType do
field :viewer, types.UserType do
到field :viewer, Types::UserType do
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.