Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-03-2020 07:13 AM
Hello,
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 u.name AS name, collect(id(connection)) AS connections")
}
Thanks in advance for any help.
04-03-2020 08:27 AM
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 u.name AS name, collect(id(connection)) AS connections RETURN u.name , connections")
04-03-2020 02:35 PM
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.
Thanks
04-04-2020 05:59 AM
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.
04-06-2020 08:19 AM
Ok I see - Thanks for the reply
04-16-2020 01:56 AM
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?
07-28-2020 11:16 AM
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.
Alexis
All the sessions of the conference are now available online