20
votes

Is there any way of enabling special characters in GraphQL schema (e.g., /, :, @ in the field names)?

And if there isn't (which I suspect is the case) do you have an idea what would be relatively easiest way to modify the node.js code (https://github.com/graphql/graphql-js) to achieve such functionality?

1
For those that down voted this without bothering to be helpful and educate, I hope you feel proud of yourself as you got to feel superior by showing that you know why this is not a good idea without even explaining why. - otissv
Thanks, @otissv. Yes - bad, bad stackoverflow-ers! ;) - szymon
@otissv Downvoting doesn't mean that at all, it can mean a variety of things, like poor research or unclear question. Their isn't enough downvoting on this site. - Martin Dawson
@MartinDawson Given the variety reasons for downvoting, downvoting without explation is pointless and unhelpful. A simple comment as "downvoted - unclear question" is far more constructive. Else it only indcates that something is wrong. And to downvote this question would mean you know the answer. A simple "research graphql spec" comment would point in the right direction. Maybe if there where more downvoting with explations you wouldn't feel there isn't enough downvoting on this site. - otissv

1 Answers

21
votes

I would recommend against doing in this. graphql-js follows the grammatical form stated in the graphql specification. Such a change would be a break away from the specification and your schema would no longer work with graphql tools. The parser would throw an invalid schema because these characters have special meaning in graphql.

GraphQL Spec

Punctuator:: one of ! $ ( ) ... : = @ [ ] { | }
GraphQL documents include punctuation in order to describe structure. GraphQL is a data description language and not a programming language, therefore GraphQL lacks the punctuation often used to describe mathematical expressions.

http://facebook.github.io/graphql/#sec-Punctuators

Name :: /[_A-Za-z][_0-9A-Za-z]*/
GraphQL query documents are full of named things: operations, fields, arguments, directives, fragments, and variables. All names must follow the same grammatical form. Names in GraphQL are case‐sensitive. That is to say name, Name, and NAME all refer to different names. Underscores are significant, which means other_name and othername are two different names. Names in GraphQL are limited to this ASCII subset of possible characters to support interoperation with as many other systems as possible.

http://facebook.github.io/graphql/#sec-Names