【问题标题】:Error with GraphQL Rails (GraphQL::ObjectType can't define '“Query”'")GraphQL Rails 出错(GraphQL::ObjectType 无法定义“查询”)
【发布时间】: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


    【解决方案1】:

    我贴错了该死的引号:

    description “A list of all the movies”

    当然应该是:

    description "A list of all the movies"

    是的,我知道通过输入代码我会学得更好,所以认为自己学会了。

    【讨论】:

      猜你喜欢
      • 2018-06-28
      • 1970-01-01
      • 2020-07-04
      • 2017-06-16
      • 2019-05-08
      • 1970-01-01
      • 2021-12-03
      • 1970-01-01
      • 2018-03-25
      相关资源
      最近更新 更多