我想为我的API定义我的模式。我遇到了每个资源都有很多不同部分的问题。理想情况下,我希望能够说节是一个JSON对象,而不是定义节中的所有不同模块。有什么办法可以做到这一点?据我所知,似乎没有被使用graphql-tools
用graphql-tools定义Schema
// Define your types here.
const typeDefs = `
type Resource {
id: ID,
title: String!,
slug: String!,
path: String!,
template: String!,
published: String!,
sections: Sections
}
type Sections {
// ...
}
type Query {
allLinks(filter: LinkFilter): [Link!]!
findResource(filter: ResourceFilter): [Resource!]!
}
`;
JSON标量可以在这里使用,但需要注意的一点是:如果您开始使用JSON标量,则会失去GraphQL的许多好处。例如,你不会为该对象进行自动类型检查(如果你已经设置了)。 – helfer