2
votes

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.

1
This doesn't have anything to do with cycles, but without the rest of your schema code, it's impossible to tell what the problem is. It looks like you're somehow adding the Driver type twice, or you copy-pasted the type definition, but forgot to change 'name' somewhere.helfer
If I remove drivers from TerminalType the error goes away. If I remove homeTerminal from DriverType it does not go away. I suppose that's a clue.Tim Scott
There is definitely only one GraphQLObjectType with name of "Driver".Tim Scott

1 Answers

0
votes

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.