javascript - 如何向 "GraphQL schema language"中的字段添加说明

标签 javascript graphql apollo-server

我有一个 graphql 模式,其中的一个片段如下所示:

type User {
    username: String!
    password: String!
}

在graphiql中,有一个描述字段,但它总是说“ self 描述”。如何向模式添加描述?

最佳答案

如果您使用的是 GraphQL.js 0.7.0 或更高版本,您只需在要描述的字段、类型或参数之前直接添加注释即可。例如:

# A type that describes the user
type User {
     # The user's username, should be typed in the login field.
     username: String!
     # The user's password.
     password: String!
}

在 0.7.0 版本以下无法在模式语言中添加描述。

更新:从版本 v0.12.3 开始,您应该使用string literals

"""
A type that describes the user. Its description might not 
fit within the bounds of 80 width and so you want MULTILINE
"""
type User {
     "The user's username, should be typed in the login field."
     username: String!
     "The user's password."
     password: String!

}

关于javascript - 如何向 "GraphQL schema language"中的字段添加说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39962867/

相关文章:

javascript - d3 单击处理程序不适用于传单 map 层

graphql - GraphQL 中的空白是否重要?

Apollo 客户端 GraphQL 在 Next.js getStaticProps 上创建静态页面

javascript - 如何使用 Jquery Web 服务绑定(bind) div

javascript - 如何向express.js 页面添加 Angular ?

postgresql - 运行 mix ecto.setup 命令时连接被拒绝,使用 asdf 安装的软件包

javascript - 如何调试ApolloServer的上下文函数?

express - Apollo Server Express : Request entity too large

javascript - CodeIgniter - 如何保存下拉所选值并在返回页面时设置它

graphql - 为什么我的 Apollo 缓存更新没有反射(reflect)在我的查询中?