GraphQL query returning list of objects

In the schema.graphql file, I'd like to define a type Query that returns a String with a list of Objects.
Let's say I have a query defined as below, how should I set the return type [String, listofConnections ] ?

type Query {
myQuery(id: Int): [String, listofConnections ] @cypher(statement: "Match (u:User.... WHERE id(u)=$id RETURN AS name, collect(id(connection)) AS connections")

Thanks in advance for any help.

Hi @Eclipsetalk,

although I have no good knowledge of graphql, however I see that there is some issue in the cypher query. Can you give a try with below change:
statement: "Match (u:User{id(u):$id}) -[.... With AS name, collect(id(connection)) AS connections RETURN , connections")

Thanks for thew reply - The question is not about the cypher query. I didn't state it entirely. My problem is how to return a custom type like an array of list in a GraphQL query.

You're not going to be able to return two separate things from your cypher query like that with GraphQL. You can return a JSON like object back if you like but you can only return a single scalar type, schema type, or object back from the query. It may be possible to use a Union of some sort but I haven't seen that use case.

Ok I see - Thanks for the reply

Hi Eric,

There is no conception of tuples in GraphQL type system. There are JSON-like "object" types, whose elements can be scalars or other (nested) JSON-like object types, and these can either be singular or multiple (lists of types or scalars).

You can absolutely return something akin to atuple, you just define a type with two fields:

type X {
  a String
  b [OtherType]

and as a result X is equivalent to your pair/tuple.

GraphQL mutations or queries can return one-off types like this, it doesn't have to match an existing Node object shape in your Neo4j instance.

BUT! You are working with the constraints of the GraphQL plugin, rather than neo4j-graphql-js, right?

Hi Benjamin,

How would you go about returning a tuple in Cypher to match that Graphql type? I have been trying but can't figure it out.