【发布时间】:2021-02-18 23:26:59
【问题描述】:
我开始使用 graphQl 查询语言并且我使用 GraphQL 模式定义语言作为字符串类型来定义类型,但是我看到其他开发人员使用 GraphQLObjectType 函数,GraphQL 的 JavaScript 参考实现使用它来存储有关模式的信息,我很困惑关于定义模式的最佳方式,我需要知道在什么情况下我们可以使用 GraphQLObjectType
const queryType = new GraphQLObjectType({
name: "Query",
fields: {
posts: {
type: postType
},
author: {
name: "author",
type: authorType,
arguments: { id: { type: new GraphQLNonNull(GraphQLInt) } }
}
}
});
或GraphQL Schema Definition Language
type Author {
id: Int!
firstName: String
lastName: String
posts: [Post]
}type Post {
id: Int!
title: String
author: Author
votes: Int
}type Query {
posts: [Post]
author(id: Int!): Author
}
【问题讨论】:
-
两者都有效,
schema firstvscode first.. 选择您的偏好
标签: javascript graphql