Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-12-2020 06:11 PM
Hello everyone I believe I have a simple problem but I can’t seem to solve it. I am using Graphql with Neo4j. I want to simply count relationships and put that capability in my graphql schema using the “CALL graphql.idl()” procedure and the “@cypher”directive,my code is as follows
CALL graphql.idl(
"
type User{
userSocialFollowsCount:@cypher(statement:”MATCH (u:User)-[:FOLLOWS_ON_SOCIALS]->(o:User) WITH u,count(o) as rels WHERE rels > 1 RETURN rels”)
}
"
)
``
Iv also tried this example from the internet
CALL graphql.idl("
type User{
degree: Int @cypher(statement: "RETURN SIZE((this)-->())")
}
"
)
I am getting a syntax error in the Neo4j browser but I don’t understand where exactly the problem is.. I want to update my schema to be able to count relationships using the procedure.
I having installed the FULL APOC manually to the Graphene Database & they have confirmed it is installed okay ... I checked the version & it is compatible with the instance
What am I doing wrong? How do you use the @cypher directive in a graphql schema with the “CALL graphql.idl()” procedure to update the schema? I want to do it automatically using the procedure but I seem to be missing something.. thanks 🙏
Solved! Go to Solution.
08-14-2020 06:54 PM
I have found the solution from the Github issue I was using double quotes throughout instead of single quotes to inclose the schema command
08-13-2020 05:20 AM
I think the answer to this question will give you a base to solve yours. Give it a shot:
also: Even those this is an older article it's got some good info:
08-13-2020 06:01 AM
Thanks for the reference well explained and simplified but I am getting the following exception
"
Failed to invoke procedure graphql.idl
: Caused by: java.lang.RuntimeException: Error parsing IDL expected {'[', 'fragment', 'query', 'mutation', 'subscription', 'schema', 'scalar', 'type', 'interface', 'implements', 'enum', 'union', 'input', 'extend', 'directive', NAME} got '@' line 20 column 23
"
08-13-2020 07:07 AM
Ok can you please show me the query you're using in your schema please?
08-13-2020 08:40 AM
graphql.idl(“
type User {
userFollows:@cypher(statement:”MATCH (n)-[r:User_Follows]->() RETURN COUNT(r)”)
}
“)
08-13-2020 11:31 AM
This is how I implemented it in my own:
wellCount: Int @cypher (
statement: "MATCH (this)<-[r:DRILLED_ON]-(:Well) with this, count(r) as rel_cnt return rel_cnt"
)
08-13-2020 11:51 AM
I have re-adapted it to:
graphql.idl(“
type User {
followsCount:Int @cypher (
statement: "MATCH (this)<-[r:FOLLOWS_ON_SOCIALS]-(:User) with this, count(r) as rel_cnt return rel_cnt"
)
}
“)
I am getting the following error
Invalid input 'M': expected whitespace, '.', node labels, '[', "=~", IN, STARTS, ENDS, CONTAINS, IS, '^', '*', '/', '%', '+', '-', '=', '~', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR, ',' or ')' (line 20, column 13 (offset: 574)) "statement: "MATCH (this)<-[r:FOLLOWS_ON_SOCIALS]-(:User) with this, count(r) as rel_cnt return rel_cnt""
08-13-2020 12:05 PM
I’m not super sure how your schema is constructed but it looks like it’s not quite right. Is it in a schema.graphql file?
08-13-2020 12:46 PM
when I run CALL graphql.schema()
I get a schema and the schema generation command CALL graphql.idl()
runs when I omit the field with the "@cypher" directive on the relevant Node type
08-14-2020 04:43 AM
You might try it the way that the project is set up on the GRANDstack example and have it in a schema.graphql file. It seems that the graphql.idl isn't playing well with Neo4j.
08-14-2020 05:18 AM
08-14-2020 05:58 AM
Here's a link to a project that @William_Lyon is working on currently that has a great video series along with it. https://github.com/johnymontana/willow-grandstack/tree/master/api/src In it you can see how the schema.graphql file is set up and used.
Sorry I mean use the schema.graphql file not the graphql-schema.js
08-14-2020 03:47 PM
thanks but I am using the plugin on desktop and I think thats a Java/kotlin kind of set up... its just not working the graphql plugin on desktop with cypher
08-14-2020 06:54 PM
I have found the solution from the Github issue I was using double quotes throughout instead of single quotes to inclose the schema command
08-14-2020 03:48 PM
I have even downgraded and re-installed APOC .. still not working
08-15-2020 04:59 AM
Glad you got it figured out. Though the original question was about how to handle counting relationships.
All the sessions of the conference are now available online