You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 3, 2021. It is now read-only.
This issue requests support for a cypher template literal tag for use in writing the Cypher statement argument of @cypher directive fields. Using a cypher tag would result in support for Cypher syntax highlighting in any editor using an extension that provides highlighting support for it, such as the Cypher Query Langauge Tools for Neo4j extension for Visual Studio Code.
This would result in a smoother experience when reading and writing Cypher within a GraphQL schema using @cypher fields, especially for multi-line Cypher statements. A GraphQL block string is currently used to support a multi-line String type directive argument. This results in an absense of syntax highlighting support within such arguments. In the Federation example for the inventory service, the @cypher statement for the shippingEstimate field on the Product entity would normally be as follows:
Situation
shippingEstimate: Int@requires(fields: "weight price")
@cypher(statement: """ CALL apoc.when($price > 900, // free for expensive items 'RETURN 0 AS value', // estimate is based on weight 'RETURN $weight * 0.5 AS value', { price: $price, weight: $weight }) YIELD value RETURN value.value """)
An implementation for a cypher tag template for the statement argument of a @cypher directive might look like:
Implementation
exportconstcypher=(statement, ...substitutions)=>{// Get the array of string literalsconstliterals=statement.raw;// Add each substitution inbetween allconstcomposed=substitutions.reduce((composed,substitution,index)=>{// Add the string literalcomposed.push(literals[index]);// Add the substitution proceeding itcomposed.push(substitution);returncomposed;},[]);// Add the last literalcomposed.push(literals[literals.length-1]);// Return the Cypher statement string as a GraphQL block string// for the `@cypher` directive statement argumentreturn`statement: """${composed.join('')}"""`;};
Example
With the Cypher statement argument being provided as the result of the above cypher tag implementation, we could write the shippingEstimate's @cypher statement within another string literal with the tag, used as an embedded expression within the string literal containing the GraphQL schema SDL (which is the case when using a gql tag). The Cypher would then be appropriately highlighted in an editor with Cypher language support for the tag.
shippingEstimate: Int@requires(fields: "weight price")
@cypher(${cypher`
CALL apoc.when($price > 900,
// free for expensive items
'RETURN 0 AS value',
// estimate is based on weight
'RETURN $weight * 0.5 AS value',
{
price: $price,
weight: $weight
})
YIELDvalueRETURNvalue.value
`})
This issue requests support for a
cypher
template literal tag for use in writing the Cypherstatement
argument of@cypher
directive fields. Using acypher
tag would result in support for Cypher syntax highlighting in any editor using an extension that provides highlighting support for it, such as the Cypher Query Langauge Tools for Neo4j extension for Visual Studio Code.This would result in a smoother experience when reading and writing Cypher within a GraphQL schema using
@cypher
fields, especially for multi-line Cypher statements. A GraphQL block string is currently used to support a multi-line String type directive argument. This results in an absense of syntax highlighting support within such arguments. In the Federation example for the inventory service, the@cypher
statement for the shippingEstimate field on theProduct
entity would normally be as follows:Situation
An implementation for a
cypher
tag template for thestatement
argument of a@cypher
directive might look like:Implementation
Example
With the Cypher statement argument being provided as the result of the above
cypher
tag implementation, we could write theshippingEstimate
's@cypher
statement within another string literal with the tag, used as an embedded expression within the string literal containing the GraphQL schema SDL (which is the case when using agql
tag). The Cypher would then be appropriately highlighted in an editor with Cypher language support for the tag.Using the Cypher Query Langauge Tools for Neo4j extension for Visual Studio Code:
Additional possibilities
Statements as variables
The Cypher statement of a
@cypher
directive using acypher
tag could also be elevated to avariable, which could be imported.
matchUsers.js
typeDefs.js
Validation and analysis
A Cypher statement using a
cypher
tag could be processed using additional behaviours addedto its implementation, such as validation and analysis.
The text was updated successfully, but these errors were encountered: