我想爲我的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