2017-09-25 5 views
0

グラフの再生中に、has_many :troughというデータセットを取得する際に問題が発生しました。Rails Grapql has_many接続エラー

コンソルになったエラーイムがある:

query{ 
    items{ 
    id 
    title 
    collections{ 
     id 
    } 
    } 
} 

私は私が期待するようクエリがデータを返さないことを確認することができますが、私は持っている: は私のクエリがどのように見える

POST "/graphql" for 127.0.0.1 at 2017-09-25 19:28:24 -0400 
Processing by GraphqlController#execute as */* 
    Parameters: {"query"=>"query{\n items{\n id\n title\n collections{\n  id\n }\n }\n}", "variables"=>nil, "graphql"=>{"query"=>"query{\n items{\n id\n title\n collections{\n  id\n }\n }\n}", "variables"=>nil}} 
    Item Load (0.7ms) SELECT `items`.* FROM `items` 
    Collection Load (0.6ms) SELECT `collections`.* FROM `collections` INNER JOIN `collection_item_crosses` ON `collections`.`id` = `collection_item_crosses`.`collection_id` WHERE `collection_item_crosses`.`item_id` = 1 LIMIT 11 
Completed 500 Internal Server Error in 79ms (ActiveRecord: 4.0ms) 



    CACHE Collection Load (0.0ms) SELECT `collections`.* FROM `collections` INNER JOIN `collection_item_crosses` ON `collections`.`id` = `collection_item_crosses`.`collection_id` WHERE `collection_item_crosses`.`item_id` = 1 LIMIT 11 [["item_id", 1], ["LIMIT", 11]] 
NoMethodError (undefined method `id' for #<Collection::ActiveRecord_Associations_CollectionProxy:0x007f6a38317d98> 
Did you mean? ids): 

app/controllers/graphql_controller.rb:12:in `execute' 

開始未定義のメソッドエラーが何を指しているのかは分かりません。

コレクションタイプ:

Types::CollectionType = GraphQL::ObjectType.define do 
    name 'Collection' 

    field :id, !types.Int 
    field :collection_name, !types.String 
    field :collection_description, types.String 
    field :items, -> { Types::ItemType } 
    field :collectionItems, -> { Types::CollectionItemCrossType } 
end 

答えて

0

:itemsフィールドがコレクションです。他のタイプのGraphQL::ListTypeの略!types[]

Types::CollectionType = GraphQL::ObjectType.define do 
    name 'Collection' 

    field :items, !types[Types::ItemType] 
    field :collectionItems, !types[Types::CollectionItemCrossType] 
end 

:だから宣言は次のようになります。