ruby-on-rails - GraphQL Rails 出错(GraphQL::ObjectType 无法定义“查询”)
问题描述
我正在尝试使用 Rails 创建使用 GraphQL,并且一直在遵循一些指南,其中最新的是:https ://medium.com/@UnicornAgency/you-should-be-using-graphql-a-ruby-介绍-9b1de3b001dd
我创建了一个简单的“电影”模型
我已经添加gem 'graphql'
冉Bundle Install
冉 rails g graphql:install
冉Bundle Install
然后我更新query_type.rb
为:
Types::QueryType = GraphQL::ObjectType.define do
name “Query”
# Add root-level fields here.
# They will be entry points for queries on your schema.
field :allMovies do
type types[Types::MovieType]
description “A list of all the movies”
resolve -> (obj, args, ctx) {
Movie.all
}
end
field :movie do
type Types::MovieType
description “Return a movie”
argument :id, !types.ID
resolve -> (obj, args, ctx) { Movie.find(args[:id]) }
end
end
movie_type.rb
好像:
module Types
class MovieType < Types::BaseObject
name “Movie”
field :id, !types.ID
field :title, !types.String
field :description, types.String
end
end
但是,当我启动服务器并转到时,localhost:3000/graphql
我收到以下消息。"GraphQL::ObjectType can't define '“Query”'"
我注意到的是,当我最初打开query_type.rb
它时,它有以下代码,我在网上看到的所有教程都没有提及:
module Types
class QueryType < Types::BaseObject
end
end
如果我在其中添加代码,则代码不起作用,如果我按照上面的方式完全替换,代码也不起作用。
有任何想法吗?
解决方案
推荐阅读
- powershell - PSRemoting 参数 RunAsAdministrator '参数集无法解析' 错误
- python - 在字典列表中查找和编辑值的最快方法
- .htaccess - 修改 .htaccess 以直接在浏览器中打开 .txt.gz 文件
- django - 从 bitbucket 管道部署到谷歌应用引擎时如何运行 django 迁移?
- java - Spring数据重复键值
- java - Elatsic 缓存 - redis - 写入 ~30-40 K 键后无法连接 - 连接池问题
- azure-devops - Azure DevOps:管道无法使用来自工件的 NuGet 包
- java - 无法使用源选项编译 Java 11 代码
- r - 变异变量以使用管道和用户定义的函数创建是/否
- flutter - Flutter - 具有动态状态变量的动态切换按钮