0

I'm new to QraphQL and I found some best practices for module system in apollo-server but I can't find anything for express-graphql!

I'm using GraphQLSchema instead of buildSchema. and when I'm trying to split my code into different modules, it will sticks in NodeJs circular dependencies error (returns empty object).

As a GraphQL expert, which one do you recommend? apollo-server or express-graphql? and if you recommend express-graphql, which method do you recommend? GraphQLSchema or buildSchema?

and also what is the best way for splitting my schema for every one of these methods?

Pouya Jabbarisani
  • 1,084
  • 3
  • 16
  • 29
  • 1
    Working with `GraphQLSchema` should be fine. What is important is that if you recursion in your type system put the recursive types in a thunk (function without arguments) like so `type: () => RecursiveType` on both sides. Now this type can be undefined during definition time. – Herku Apr 17 '20 at 11:13
  • 1
    If you don't use ES modules but `require` it can be even trickier. Here you have to reference the whole module and refrain from destructuring early: `const rec = require('RecursiveType')`, `type: () => rec.RecursiveType`. – Herku Apr 17 '20 at 11:16
  • @Herku but the problem is just here! I'm getting empty object but I'm not using recursive types and I'm using thunk! but I'm still getting empty object error in graphiql – Pouya Jabbarisani Apr 17 '20 at 13:18
  • Then, this seems to be a problem unrelated to GraphQL and related to Node.js' module resolution algorithm. Without you sharing precisely how you import files and your file structure I don't think I can help you :( – Herku Apr 18 '20 at 14:22

1 Answers1

0

Using apollo-server-express, helped me to do many kinds of stuff like this one.

Pouya Jabbarisani
  • 1,084
  • 3
  • 16
  • 29