merge-graphql-schemas
merge-graphql-schemas copied to clipboard
Unable to merge GraphQL type ... undefined is not iterable (for a duplicate type)
Using [email protected], I was trying to call something like:
import {mergeTypes} from 'merge-graphql-schemas';
(async () => {
mergeTypes(
await Promise.all([
fs.readFile('schema1.graphql'),
fs.readFile('schema2.graphql'),
]),
);
})();
I got an error like:
Error: Unable to merge GraphQL type "MyType": undefined is not iterable (cannot read property Symbol(Symbol.iterator))
at mergeType (/.../app/node_modules/@graphql-toolkit/schema-merging/index.cjs.js:675:19)
at /.../app/node_modules/@graphql-toolkit/schema-merging/index.cjs.js:717:30
at Array.reduce (<anonymous>)
at mergeGraphQLNodes (/.../app/node_modules/@graphql-toolkit/schema-merging/index.cjs.js:706:18)
at mergeGraphQLTypes (/.../app/node_modules/@graphql-toolkit/schema-merging/index.cjs.js:856:25)
at Object.mergeTypeDefs (/.../app/node_modules/@graphql-toolkit/schema-merging/index.cjs.js:755:22)
at mergeTypes (/.../app/node_modules/merge-graphql-schemas/dist/index.cjs.js:24:26)
...
I was trying to introduce type MyType {} in schema1.graphql but that exact type already existed in schema2.graphql.
This error message should be more informative. RIP my last hour.
merge-graphql-schemas has been deprecated as you can see in https://github.com/Urigo/merge-graphql-schemas/blob/master/README.md We recommend you to start using GraphQL Tools instead;
https://www.graphql-tools.com/docs/migration-from-merge-graphql-schemas/
Since I have the solution, I just wanted to post it here so that someone else could search and find it. I was trying to search for this error and not finding anything.
Ultimately, I'd hope the newer lib has a better error message but I'm not able to migrate my app at this time.
@kumar303
Since I have the solution, I just wanted to post it here so that someone else could search and find it. I was trying to search for this error and not finding anything.
You have just saved me an hour :) thanks for the explanation!