ardatan / graphql-import-node

Import 'graphql' files in NodeJS
80 stars 14 forks source link

Jest import looses doc.loc.source due to JSON.stringify #13

Open emmanuelbuah opened 4 years ago

emmanuelbuah commented 4 years ago

Per issue laid out in https://github.com/apollographql/graphql-tag/issues/115, stringifying gql DocumentNode loose doc.loc.source property since its not enumerable anymore.

Looking at the code, jest import utilizes stringification which makes it so the returned DocuemntNote encounters errors such as https://github.com/apollographql/graphql-tag/issues/64 when used with graphql-tag.

I'd recommend patching the jest code to apply the same/similar fix in https://github.com/apollographql/graphql-tag/pull/65 to address the issue.

HriBB commented 3 years ago

I'm getting a similar error with graphql-import-node and jest:

Unable to create News schema!
Cannot read property 'prev' of undefined
TypeError: Cannot read property 'prev' of undefined

      at getLeadingCommentBlock (../../node_modules/graphql/utilities/extendSchema.js:713:30)
      at getDescription (../../node_modules/graphql/utilities/extendSchema.js:694:20)
      at buildType (../../node_modules/graphql/utilities/extendSchema.js:546:23)
      at extendSchemaImpl (../../node_modules/graphql/utilities/extendSchema.js:138:120)
      at Object.buildASTSchema (../../node_modules/graphql/utilities/buildASTSchema.js:56:51)
      at buildSchemaFromTypeDefinitions (../../dist/schema/src/buildSchemaFromTypeDefinitions.js:9:18)
      at Object.makeExecutableSchema (../../dist/schema/src/makeExecutableSchema.js:64:18)
      at Object.<anonymous>.exports.createSchema (src/news/createSchema.ts:55:20)
      at Object.<anonymous> (test/app.test.ts:13:22)
      at Object.<anonymous>.exports.createSchema (src/news/createSchema.ts:61:11)
      at Object.<anonymous> (test/app.test.ts:13:22)

Error appears only in tests. If I use gql it works.