GraphQL 模式中的特殊字符 [英] Special characters in GraphQL schema

查看:71
本文介绍了GraphQL 模式中的特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 GraphQL 模式中启用特殊字符(例如,字段名称中的 /:@)?

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

如果没有(我怀疑是这种情况),您是否知道修改 node.js 代码的相对最简单的方法是什么(https://github.com/graphql/graphql-js) 来实现这样的功能?

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?

推荐答案

我不建议这样做.graphql-js 遵循 graphql 规范中规定的语法形式.这样的更改将脱离规范,您的模式将不再与 graphql 工具一起使用.解析器会抛出一个无效的模式,因为这些字符在 graphql 中有特殊的含义.

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 规范

标点符号::其中之一!$ ( ) ... : = @ [ ] { |}
GraphQL 文档包含标点符号以描述结构.GraphQL 是一种数据描述语言,而不是一种编程语言,因此 GraphQL 缺少经常用于描述数学表达式的标点符号.

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

名称 ::/[_A-Za-z][_0-9A-Za-z]*/
GraphQL 查询文档充满了命名的东西:操作、字段、参数、指令、片段和变量.所有名称都必须遵循相同的语法形式.GraphQL 中的名称区分大小写.也就是说name、Name、NAME都是指不同的名字.下划线很重要,这意味着 other_name 和 othername 是两个不同的名称.GraphQL 中的名称仅限于这个可能字符的 ASCII 子集,以支持与尽可能多的其他系统的互操作.

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

这篇关于GraphQL 模式中的特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆