Why does an argument need to be passed with this query for it to work?

(John) #1

im a fairly inexperienced coder so this question might be obvious to u guys.
Currently trying to set up the schema with makeAugmentedSchema, but I want to create the resolver functions and queries myself (both for a later purpose in the app but also just for practice and learning).

So the Q: Why does 1 work but not 2?

openTrades(isOpen: Boolean): [Trade]
statement: "MATCH (t:Trade) WHERE t.isOpen = $isOpen RETURN t"

openTrades: [Trade]
statement: "MATCH (t:Trade {isOpen: true}) RETURN t"

(William Lyon) #2

Both look correct to me. Are they both fields on the Query type? Are you getting an error with the second option?

(John) #3

Yes they are both fields on the QueryType.

This is the error msg:

"message": "Invalid input ',': expected whitespace, comment or an expression (line 1, column 76 (offset: 75))\n"WITH apoc.cypher.runFirstColumn("MATCH (t:Trade {isOpen: true}) RETURN t", , True) AS x UNWIND x AS trade"\n

(William Lyon) #4

Ah - I believe that is related to this issue, which has been fixed in master and will be available in the next release.

The problem is that if a parameter is not specified then we don't insert a blank object resulting in a syntax error in the generated Cypher statement. The fix should be released in the next few days, but in the mean time you can avoid this error by ensuring a parameter is used, for example this should work:

openTrades(ignoreMe: String = ""): [Trade]
  statement: "MATCH (t:Trade {isOpen: true}) RETURN t"