Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
wdrain
Helper I
Helper I

How would do you escape a variable name with a Hypen in a GraphQL query string?

I am able to connect to GraphQL restapi with a variable name with space using a GraphQL query string by prefixing and suffixing the variable name with a \ (backslash) and 2 double quotes "". 

name: "Custom Tag"
i.e.   name: \""Custom Tags\""  => works successfuly escaping with the \ backslash and 2 double quotes ""

However a variable name GraphQL Query containing  a  "-" hypen or dash will not work and I need help troubleshooting.

 

name:"Custom - Tag2"
i.e. name:\""Custom - Tag2\"" => Does not work, because of the hypen and I don't know how to escape this?



1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @wdrain ,
According to your description, in GraphQL, variable names cannot contain hyphens or dashes because they are not valid characters for identifiers.1 This is due to possible ambiguity in parsing, as hyphens may be interpreted as subtraction operators in many programming languages. If you need to keep hyphens in the value, you can try to do so, but the variable name itself should follow valid naming conventions.

{
  customTag2: "Custom - Tag2"
}

 

Queries and Mutations | GraphQL
[question] why names cannot contain dash '-' · Issue #479 · graphql/graphql-spec · GitHub

 

Best regards,
Albert He


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @wdrain ,
According to your description, in GraphQL, variable names cannot contain hyphens or dashes because they are not valid characters for identifiers.1 This is due to possible ambiguity in parsing, as hyphens may be interpreted as subtraction operators in many programming languages. If you need to keep hyphens in the value, you can try to do so, but the variable name itself should follow valid naming conventions.

{
  customTag2: "Custom - Tag2"
}

 

Queries and Mutations | GraphQL
[question] why names cannot contain dash '-' · Issue #479 · graphql/graphql-spec · GitHub

 

Best regards,
Albert He


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

Top Solution Authors