graphql-ruby-demo icon indicating copy to clipboard operation
graphql-ruby-demo copied to clipboard

Query requires edges

Open AndrewRayCode opened this issue 8 years ago • 2 comments

https://github.com/rmosolgo/graphql-ruby-demo/blob/master/app/graph/queries/readLukesFriends.graphql

Running this query

query readLukesFriends {
  luke: human(id: 1000) {
    friends { name }
  }
}

http://graphql-ruby-demo.herokuapp.com/graphiql?query=%7B%0A%20%20luke%3A%20human(id%3A%201000)%20%7B%0A%20%20%20%20friends%20%7B%20name%20%7D%0A%20%20%7D%0A%7D

Returns

"Field 'name' doesn't exist on type 'CharacterConnection'"

But this query works:

luke: human(id: 1000) {
    friends {
      edges {
        node {
          name
        }
      }
    }
  }

AndrewRayCode avatar Mar 20 '17 03:03 AndrewRayCode

Because friends is a connection. According to Relay Connections Specification, connections must contain an edges field, which is a list type. You can also checkout the type definition here. https://github.com/rmosolgo/graphql-ruby-demo/blob/master/app/graph/types/human_type.rb

mumuWeng avatar Apr 28 '17 14:04 mumuWeng

@mumuWeng Is there any chance this query will work?

query readLukesFriends {
  luke: human(id: 1000) {
    friends { name }
  }
}

What changes need to be made on human_type.rb ?

prihandi avatar Jun 09 '17 03:06 prihandi