graphql-import-node icon indicating copy to clipboard operation
graphql-import-node copied to clipboard

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

Open emmanuelbuah opened this issue 5 years ago • 1 comments

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.

emmanuelbuah avatar Aug 11 '20 20:08 emmanuelbuah

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.

HriBB avatar Nov 13 '20 03:11 HriBB