Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-16-2020 07:44 AM
I started learning GRANDstack and I'm using the GRANDstack starter.
I have connected my Neo4j database to this starter.I would like to do something like this:
Here I displayed titles of articles having the community id 996.
What I would like to do is to be able, in the user interface, to display bloc like the image, and each blocs will be each community (for example the first bloc will be the community 996)
I would like to use a precise Cypher request in order to display articles by clusters (community in the request) in the user interface.
MATCH (a:ARTICLE)
WITH a, collect(a.community) as community
ORDER BY a.community
RETURN community, count(a), a.title
The graphql schema has all the types required.
I pasted this request in the schema.graphql.
type Query {
communities: Int! @cypher(statement:"
MATCH (a:ARTICLE)
WITH a, collect(a.community) as community
RETURN community, count(a), a.title")
}
I don't know if it is the good way to do it. If it is what do I have to do next ?
And if not where do I have to put this request in the GRANDstack starter ?
10-16-2020 08:41 AM
You defined your query as returning an int, but your cypher returns 3 fields so i don't think that's gonna work how you'd expect. as i was writing the next part of this answer i realized your intent could be one of several and i didn't want to guess. for the example you have; i'd change it to
type Query {
communityCount: Int! @cypher(statement:"
MATCH (a:ARTICLE)
WITH a, collect(a.community) as community
RETURN size(community)")
}
10-16-2020 08:47 AM
Thank you for your answer. Yes I would like to be able to display the titles by clusters id.
So I try to aggregate title by community
10-16-2020 08:57 AM
How about
type community{
title:string
count:Int
}
type query{
communityCount: [community] @cypher(statement:"
MATCH (a:ARTICLE)
WITH a, collect(a.community) as community
RETURN {title:a.title, count:size(community)}" )
}
10-16-2020 09:08 AM
Thank you for your answer, I tried but it doesn't work.
I would like to do something like this:
Here I displayed titles of articles having the community id 996.
What I would like to do is to be able, in the user interface, to display bloc like the image, and each blocs will be each community (for example the first bloc will be the community 996)
10-16-2020 09:32 AM
when you say "it didn't work" can you elaborate ?
to limit by community you might consider adding a parameter to the query. something like this
type query{
communityCount(communityNumber:ID!): [community] @cypher(statement:"
MATCH (a:ARTICLE)
WHERE a.community = $communityNumber
WITH a, collect(a.community) as community
RETURN {title:a.title, count:size(community)}" )
}
10-16-2020 09:38 AM
This type doesn't work in my schema.
type community{
title:string
count:Int,
}
If I consider a parameter, do I have to do like a foor loop next ? To display each communities separately in the user interface.
10-16-2020 10:16 AM
no comma of course on that type. and i presume that in general the answer is yes, but that is the case regardless of this approach.
All the sessions of the conference are now available online