cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Neo4j-graphql-java translator

Hi all,

I'm trying to use neo4j-graphql-java to translate graphql queries into cypher statements, using the movie example.

My schema.graphqls:
type Query {
hello: String!
person(name: String): Person
}

type Movie {
title: String!
released: Int
tagline: String
}

type Person {
name: String!
born: Int
movies: [Movie]
}

My code to do the translation:
String query = "{\n" +
" person(name: $personName) {\n" +
" name\n" +
" born\n" +
" }\n" +
"}";
Translator translator = new Translator(schema);
Map<String, String> params = new HashMap<>();
params.put("personName", "Tom Hanks");
List<Translator.Cypher> cyphers = translator.translate(query, params);
Driver driver = GraphDatabase.driver("bolt://localhost:7687", AuthTokens.basic("neo4j", "secret"));
StatementResult result = driver.session().run(cyphers.get(0).getQuery());

The translation (Cypher object) is:

MATCH (person:Person) WHERE person.name = $personName RETURN person { .name,.born } AS person

and I can see there's params in it: "personName" -> "Tom Hanks"

However the result of the execution is empty, it's actually complaining about not finding params:
"Expected parameter(s): personName"

What did I miss? Could anyone please explain what's the common practice to do this?

Thanks!

You Wu

1 REPLY 1

Use List<Translator.Cypher> cypherList = translator.translate(query);.
Parameters are resolved from the query itself and doesn't need to be passed with the query to the query translator.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online