Graphql-tools: mergeTypeDefs Error in TypeScript - TypeError: types.map is not a function

Created on 2 Jun 2020  Â·  3Comments  Â·  Source: ardatan/graphql-tools

Hey there! I previously used graphql-merge-schema for a JS Node project and it worked well. Now I ported the exact same structure and code to a new TS Node project while replacing the deprecated graphql-merge-schema with this new @graphql-tools/merge and @graphql-tools/load-files, but I can't make it work. It gives me this error:

path\.yarn\$$virtual\@graphql-tools-merge-virtual-844afcb3de\0\cache\@graphql-tools-merge-npm-6.0.5-5996f75e00-3.zip\node_modules\@graphql-tools\merge\index.cjs.js:710
        .map(type => {
         ^

TypeError: types.map is not a function
    at mergeGraphQLTypes (path\.yarn\$$virtual\@graphql-tools-merge-virtual-844afcb3de\0\cache\@graphql-tools-merge-npm-6.0.5-5996f75e00-3.zip\node_modules\@graphql-tools\merge\index.cjs.js:710:10)
    at mergeTypeDefs (path\.yarn\$$virtual\@graphql-tools-merge-virtual-844afcb3de\0\cache\@graphql-tools-merge-npm-6.0.5-5996f75e00-3.zip\node_modules\@graphql-tools\merge\index.cjs.js:689:22)
    at Object.<anonymous> (path\dist\typeDefs\index.js:6:19)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.module_1.Module._load (path\.pnp.js:17350:14)
    at Module.require (internal/modules/cjs/loader.js:852:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (path\dist\app.js:3:18)

My structure is as follow:
image
My typeDefs folder's index.ts:

const path = require('path');
const { mergeTypeDefs } = require('@graphql-tools/merge');
const { loadFiles } = require('@graphql-tools/load-files');

export default mergeTypeDefs(
  loadFiles(path.join(__dirname, '.'), {
    recursive: true,
  }), {
    all: true,
  },
);

My resolvers folder's index.ts:

const path = require('path');
const { mergeResolvers } = require('@graphql-tools/merge');
const { loadFiles } = require('@graphql-tools/load-files');

export default mergeResolvers(
  loadFiles(path.join(__dirname, '.'), {
    recursive: true,
  }),
);

And in my app.ts, I import them as follow:

const typeDefs = require('./typeDefs');
const resolvers = require('./resolvers');

Why am I getting this error? How to solve it? Am I doing something wrong? Thanks!

waiting for answer

Most helpful comment

I updated the migration docs. Thanks for opening this issue!

All 3 comments

Could you try loadFilesSync?

Thanks, that solved the problem. I don't know if you have to modify the docs or not, thanks by the way.
In addition, I couldn't make my code work because of a kinda bug in Apollo Server, but I have to issue it there. Thanks again!

I updated the migration docs. Thanks for opening this issue!

Was this page helpful?
0 / 5 - 0 ratings