【发布时间】:2017-01-08 11:26:52
【问题描述】:
通过使用graphql-js,我需要通过迭代一些数据数组来动态创建graphql模式,例如:
[{
name: 'author',
fields: [{
field: 'name'
}, {
field: 'books',
reference: 'book'
}]
}, {
name: 'book',
fields: [{
field: 'title'
}, {
field: 'author',
reference: 'author'
}]
}]
问题是循环引用。当我创建 AuthorType 时,我需要已经创建 BookType,反之亦然。
因此生成的架构应该如下所示:
type Author : Object {
id: ID!
name: String,
books: [Book]
}
type Book : Object {
id: ID!
title: String
author: Author
}
我该如何解决这个问题?
【问题讨论】:
-
使用字段configmapthunk graphql.org/docs/api-reference-type-system
标签: graphql circular-dependency graphql-js circular-reference