【发布时间】:2019-05-17 21:24:27
【问题描述】:
我正在尝试使用 Rails 创建使用 GraphQL,并且一直在遵循一些指南,其中最新的是:https://medium.com/@UnicornAgency/you-should-be-using-graphql-a-ruby-introduction-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
如果我在其中添加代码,则代码不起作用,如果我按照上述完全替换,代码也不起作用。
有什么想法吗?
【问题讨论】:
标签: ruby-on-rails graphql