Using $ in a string in a dataweave expression

38 Views Asked by At

I'm writting an GraphQL query and i have to use $like but i get a Syntax Error: Unexpected from the GraphQl service how can i use $like like a string without having this error ?

i try this :

'funquery(filter:"{\"++ vars.filter++\":{\"$like\":\"++ vars.value ++\"}}") {
#values to get
}'

but this get me an error from the dataweave : Unable to resolve reference of: 'like'. So i try this :

'funquery(filter:"{\"++ vars.filter++\":{\"\$like\":\"++ vars.value ++\"}}") {
#values to get
}'

and with this i got Syntax Error: Unexpected <EOF>

1

There are 1 best solutions below

0
aled On

I suspect that you are trying to output a GraphQL query that replaces the values of the variable and leaves them between quotes. If that is the case the quotes are incorrectly balanced in your script. Also GraphQL is not JSON, so using JSON as the output format may break quoting. Try using application/java to return a string with the query:

%dw 2.0
output application/java
var varFilter="abc"
var varValue="def"
---
"funquery(filter:{\"" ++ varFilter ++ "\":{\"\$like\":\"" ++ varValue ++ "\"}}) {
#values to get
}"

The output is a string:

funquery(filter:{"abc":{"$like":"def"}}) {
#values to get
}