简体   繁体   中英

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".

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM