[英]Cyclic GraphQL Schema Not Working
I have like this: 我有这样的:
//driverType.js
module.exports = new GraphQLObjectType({
name: 'Driver',
fields: () => ({
homeTerminal: {
type: TerminalType,
resolve: resolver(User.HomeTerminal)
}
})
});
and this: 和这个:
//terminalType.js
module.exports = new GraphQLObjectType({
name: 'Terminal',
fields: () => ({
drivers: {
type: new GraphQLList(DriverType),
resolve: resolver(Terminal.Drivers)
}
})
});
I get the error: 我得到错误:
Error: Schema must contain unique named types but contains multiple types named "Driver". 错误:模式必须包含唯一的命名类型,但是包含多个名为“ Driver”的类型。
I found some posts that say that wrapping the fields in a function block will solve it, but as you can see I did that, and it didn't make a difference. 我发现有一些帖子说将字段包装在功能块中可以解决该问题,但是正如您所看到的,我做到了,并且没有任何区别。
Thins kind of cyclic reference should be supported, yes? 应该支持Thins类型的循环引用,是吗? We can let the client will specify the desired depth. 我们可以让客户指定所需的深度。
What am I doing wrong? 我究竟做错了什么?
As a workaround, I could remove homeTerminal
from DriverType and flatten it with primitive fields, but that's rather inelegant. 作为一种解决方法,我可以从DriverType中删除homeTerminal
并使用原始字段对其进行展平,但这相当不雅致。
I found the problem. 我发现了问题。 In terminalType.js
I had: 在terminalType.js
我有:
import DriverType from './DriverType';
Should be: 应该:
import DriverType from './driverType';
Lower case "d" is correct. 小写字母“ d”正确。
UPDATE UPDATE
Here's what I think is happening. 我认为这是正在发生的事情。 Nodejs caches imports. Nodejs缓存导入。 So importing the same file multiple times always returns the same instance. 因此,多次导入同一文件总是返回同一实例。 However, I believe that, while import
is not case-sensitive caching is . 但是,我相信,虽然import
不区分大小写,但是缓存是 。 So calling with a different case on the filename returns a new and different instance. 因此,使用不同的大小写调用文件名将返回一个新的实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.