Unnest graphql query

graphql

#1

I have the following query:

{
  nodes(id: spotify:track:6SYdgNzbH6QuFfdlPn3rkc){
    id 
    name 
    artist{name}
  }
}

Which produces:

{
	"data": {
		"nodes": {
			"artist": {
				"name": "The Veils"
			},
			"id": "spotify:track:6SYdgNzbH6QuFfdlPn3rkc",
			"name": "Jesus for the Jugular"
		}
	}
}

Is there a way to truncate the results so they are not nested. Something like:

{
	"data": {
		"nodes": {
			"artist": "The Veils",
			"id": "spotify:track:6SYdgNzbH6QuFfdlPn3rkc",
			"name": "Jesus for the Jugular"
		}
	}
}

Thanks. Brandon


#2

There is no way to achieve this currently, but it can be implemented with a simple directive, for example:

{
  nodes(id: spotify:track:6SYdgNzbH6QuFfdlPn3rkc){
    id 
    name 
    artist @unnest {name}
  }
}

I opened an issue to track the progress.


#3

Thanks. I can flatten outside of Cayley in the mean time.