I want to use a given GraphQL query parameter in @cypher
directives that load data for a sub-type.
A simplified version of my schema:
type Query {
find(warrantyNo: String!, locale: String!): Warranty @cypher(statement: """
MATCH (result)-[:HAS]->(:ExternalId {externalId: $warrantyNo}) RETURN result
""", columnName: "result")
}
type Warranty {
locale: String! @cypher(statement: """
return $locale AS result
""", columnName: "result")
title: String @cypher(statement: """
MATCH (this)-[:HAS_VALUE]->(v:TextValue)-[t:HAS_TRANSLATION]->(:Language {isoCode: $locale}) return t.value AS result
""", columnName: "result")
}
As you can see I want to use the $locale
variale in Cypher queries that load data for the Warranty
: is that supported/possible? Right now I get this error message: "Neo4jError: Expected parameter(s): locale"
The variable works for the first Cypher query, but I cannot use it the for Cypher queries required for Warranty
. The locale
property is just a simple test.
And thanks a lot for the great library you provide 
Hi @torsten.kuhnhenne !
From what you're trying to do, I think the best option for you is to use input arguments.
It's worth taking a look at the documentation to see what options are available to you.
Best of luck,
Michael
Hi @michael.webb ,
thanks for the quick response. From my point of view I am using input arguments for the first query and I want to access those arguments in the queries that are automatically triggerd for the loading of the additional data for the sub-type Warranty
.
The GraphQL query is:
query ExampleQuery($warrantyNo: String!, $locale: String!) {
find(warrantyNo: $warrantyNo, locale: $locale) {
title
}
}
Variables:
{
"warrantyNo": "801430101",
"locale": "de"
}
And when the server tries to load title
I end up with the error. From my point of view locale
is not available a input parameter for this query.
Hi @torsten.kuhnhenne
You can use cypherParams
in the server context to forward the query variables to the nested @cypher
directives.
An example:
context: async ({ req }) => ({
token: req.headers.authorization,
cypherParams: {
locale: req.body.variables.locale,
},
}),
Note that token
in my example is not required, but is commonly seen in use within the context
, so I left it in for contextual knowledge.
Hope that helps!
Michael
Hi @michael.webb ,
it is working! Thanks a lot for your great support :-)
Kind regards,
Torsten
1 Like