【发布时间】:2017-07-17 06:26:05
【问题描述】:
我正在尝试为我的 API 定义我的架构。我遇到了一个问题,每个资源都有许多不同的部分。理想情况下,我只想说sections是一个JSON对象,而不是定义sections中的所有不同模块。有没有办法我可以做到这一点?据我所知,似乎没有使用 graphql-tools 的 JSON 类型定义
// 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 的很多好处。例如,您不会获得该对象的自动类型检查(如果您已设置)。