Reputation: 15205
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".
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? 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.
Upvotes: 2
Views: 669
Reputation: 15205
I found the problem. In terminalType.js
I had:
import DriverType from './DriverType';
Should be:
import DriverType from './driverType';
Lower case "d" is correct.
UPDATE
Here's what I think is happening. Nodejs caches imports. So importing the same file multiple times always returns the same instance. However, I believe that, while import
is not case-sensitive caching is. So calling with a different case on the filename returns a new and different instance.
Upvotes: 1