RStankov / SearchObjectGraphQL

GraphQL plugin for SearchObject gem
MIT License
159 stars 25 forks source link

Using new syntax with `connection_type` type #9

Closed AlanFoster closed 5 years ago

AlanFoster commented 5 years ago

Hey, I've just tried updating to the latest GraphQL Ruby Syntax and I've had no luck with .connection_type being specified:

module Types
  class QueryType < GraphQL::Schema::Object
    field :categories_working, [Types::CategoryType], function: Resolvers::CategorySearch

    # Doesn't appear to work:
    field :categories_not_working, Types::CategoryType.connection_type, function: Resolvers::CategorySearch
  end
end

When run the following query for categories_not_working within graphiql it responds with a stack trace:

image

Text:

{
  "status": 500,
  "error": "Internal Server Error",
  "exception": "#<NoMethodError: undefined method `edge_nodes' for #<Category::ActiveRecord_Relation:0x00007faf1cb71da8>>",
  "traces": {

But not supplying connection_type works as expected:

image

AlanFoster commented 5 years ago

I've created a branch here as an example of the updated syntax, and the two queries:

https://github.com/RStankov/SearchObjectGraphQL/compare/master...AlanFoster:9-updated-connection-type-syntax-issue?expand=1

Any help would be appreciated :+1:

RStankov commented 5 years ago

Hey thanks for reporting. Will try to fix this in this weeked.

RStankov commented 5 years ago

Hey, the solution is to change the type in the search resolver to Types::CategoryType.connection_type:

module Resolvers
  class CategorySearch < Resolvers::BaseSearchResolver
    type Types::CategoryType.connection_type