GraphQLError { message: 'Cannot read property \'req\' of undefined' ....
CoonHouse opened this issue · 11 comments
Hello Ben,
Great tutorial!
My jest tests are failing with the following error:
GraphQLError { message: 'Cannot read property \'req\' of undefined' .....
It seems to go wrong on @Ctx() { req }: IMyContext,
in the resolvers. Like req
doesn't exist in Ctx.
It only happens with tests. Running the application everything is working fine.
Thanks and regards,
Wilco
are you creating a dummy req here https://github.com/benawad/type-graphql-series/blob/master/src/test-utils/gCall.ts#L24
No I didn't! Wonder how I missed that one, sorry. Think I should watch the video again. ;)
Thanks for your help!
I have another question.
I have some enum values in my resolvers. Do you know how I can pass those into the 'data' object in the test?
Thanks and regards,
Wilco
what trouble are you having passing an enum value in?
I have the following test:
it('Create new Arena', async () => {
const result = await GraphQLCall({
source: createArenaMutation,
variableValues: {
data: {
.............
location: ArenaLocation.Indoor,
...........
},
},
})
I get the following error:
Expected type ArenaLocation at value.location; did you mean Indoor or Outdoor?
I also tried passing the values directly like
location: "Indoor",
and
location: "indoor",
The enum is:
export enum ArenaLocation {
Indoor = 'indoor',
Outdoor = 'outdoor',
}
Regards
so you have a typescript enum not a graphql one?
Ehh, I don't know, I followed the documentation from Type-GraphQL
and I assume your calling registerEnumType
I would think passing it in as a string would work
Yes, I am calling registerEnumType
and when I debug it's actually hit. Passing in strings didn't work, I'm going to do some more research.
Thanks for your time!
regards
This way it's working!
it('Create new Arena', async () => {
const result = await GraphQLCall({
source: createArenaMutation,
variableValues: {
data: {
.............
location: "Indoor" as ArenaLocation,
...........
},
},
})
regards
Wilco
Nice!