26

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?

szymon
  • 307
  • 1
  • 3
  • 9
  • 9
    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 Aug 18 '17 at 13:08
  • Thanks, @otissv. Yes - bad, bad stackoverflow-ers! ;) – szymon Aug 18 '17 at 14:21
  • @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 Feb 25 '18 at 18:14
  • 5
    @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 Feb 27 '18 at 08:53

1 Answers1

26

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

otissv
  • 815
  • 1
  • 10
  • 17
  • 1
    I see, thanks for your response! I'll surely need to reconsider my goals, but my basic intention is to support some form of namespace mechanism (loosely around the lines of https://medium.com/@oleg.ilyenko/graphql-namespaces-proposal-2a097ce81d2a) and offer the possibility of generating responses containing special keys such us "dc:title" or "@id", potentially useful when applying GraphQL to linked data. – szymon Aug 18 '17 at 14:02
  • 1
    To namespace something like `authors/create` you would need to write your own parser. Not worth it and it won't be compatible with the rest of graphql. The way I do it is, prefix methods with the type name using camelcase, e.g `authorsCreate`. `@` sign is a special character and so is `:`. `/` is not allowed in the current spec so is a good candidate. But you could use `_` to separate which won't break current parsers – otissv Aug 18 '17 at 14:25
  • @szymon if this answers your question, please mark as answered. – otissv Aug 19 '17 at 05:44