GraphQL Rails 出错(GraphQL::ObjectType 无法定义"查询"")



我正在尝试创建使用Rails的GraphQl,并且一直在遵循几个指南,其中最新的是:https://medium.com/@unicornagency/you-should - 使用graphql-a-a-ruby-Instruction-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

如果我在此内添加代码,则代码将不起作用,如果我完全替换了上述代码。

完全替换。

有什么想法?

我粘贴了错误的引号:

description “A list of all the movies”

当然应该是:

description "A list of all the movies"

是的,我知道我会通过输入代码来学习更好的学习,因此请考虑自己学会。

最新更新