easygraphql-tester icon indicating copy to clipboard operation
easygraphql-tester copied to clipboard

TypeError: Cannot read property 'type' of undefined

Open engineersamuel opened this issue 4 years ago • 4 comments
trafficstars

I have a valid Query that passes with tester.test however when I tester.mock with a fixture, then I'm seeing:

TypeError: Cannot read property 'type' of undefined
      at validateFixture (node_modules/easygraphql-tester/utils/fixture.js:50:27)
      at validateFixture (node_modules/easygraphql-tester/utils/fixture.js:100:19)

I debugged and it appears the issue is related to a simple name of type String which the mocker has no selectedType, hence the error at this line: https://github.com/EasyGraphQL/easygraphql-tester/blob/master/utils/fixture.js#L46

  if (schema[selectedType.type]) {

If I simply add a null check, all my tests pass:

  if (selectedType && schema[selectedType.type]) {

I'm happy to open a PR here, but I'd first want a core dev here to weigh in on what might be the issue and if this would be a valid check to simply add a null check on selectedType

engineersamuel avatar Apr 19 '21 19:04 engineersamuel

Thanks for creating this issue! can you share a quick example to reproduce it please! thanks!

estrada9166 avatar Apr 19 '21 20:04 estrada9166

@estrada9166 Sure thing, here it is: https://github.com/engineersamuel/easygraphqlrepro with instructions.

engineersamuel avatar Apr 20 '21 14:04 engineersamuel

Thanks for sharing it! what I can notice is that you are missing on the GraphQL schema, the field storageAccountName that is being tried to be mock

If you update it for - it may work

type StorageDirectory {
  name: String!
  storageAccountName: String!
  files(sampleSize: Int): [StorageFile]
}

Definitely something that can be improves is the error message in this case in case you want to open a PR!

estrada9166 avatar Apr 21 '21 00:04 estrada9166

Ahhh, great catch! Not sure on my bandwidth for a PR here, but let's leave this open and I'll try to get to it.

engineersamuel avatar Apr 21 '21 17:04 engineersamuel