-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regarding circular dependencies #126
Comments
There is no need to import Book to where Author is, just combine them at schema.js. Since the order of graphQL file is unaffected with it. |
I think the error you're getting because |
Thanks for the replies it turns out that all it need was some rubber ducking to realise the issue. All I needed to do is handle circular dependencies node style, export before require. Like this: // file: Author.js
module.exports = () => [Author, Book];
const Book = require('./Book');
const Author = `
type Author {
name: String
books: [Book]
}
`;
// -----------------------------------
// file: Book.js
module.exports = () => [Book, Author];
const Author = require('./Author');
const Book = `
type Book {
title: String
author: Author
}
`;
// -----------------------------------
// file: schema.js
const Author = require('./Author');
const RootQuery = `
type RootQuery {
author(name: String): Author
}
`;
const SchemaDefinition = `
schema {
query: RootQuery
}
`;
const schema = makeExecutableSchema({
typeDefs: [SchemaDefinition, RootQuery, Author],
resolvers: {}
}); |
If anyone wants to see this in a working project - https://github.com/eddyerburgh/express-graphql-boilerplate |
…ateway Update enterprise gateway
…ateway Update enterprise gateway
This how I understood how to handle circular dependencies, wrap in function & return array. Reference: http:https://dev.apollodata.com/tools/graphql-tools/generate-schema.html
So if I do this:
It will result in the following error:
I'm sure I misunderstood something and any help pointing me in the right direction is highly appreciated.
The text was updated successfully, but these errors were encountered: