Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQLError { message: 'Cannot read property \'req\' of undefined' .... #11

Open
CoonHouse opened this issue Mar 11, 2019 · 11 comments
Open

Comments

@CoonHouse
Copy link

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

@benawad
Copy link
Owner

benawad commented Mar 11, 2019

@CoonHouse
Copy link
Author

No I didn't! Wonder how I missed that one, sorry. Think I should watch the video again. ;)

Thanks for your help!

@CoonHouse
Copy link
Author

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

@benawad
Copy link
Owner

benawad commented Mar 12, 2019

what trouble are you having passing an enum value in?

@CoonHouse
Copy link
Author

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

@benawad
Copy link
Owner

benawad commented Mar 13, 2019

so you have a typescript enum not a graphql one?

@CoonHouse
Copy link
Author

Ehh, I don't know, I followed the documentation from Type-GraphQL

@benawad
Copy link
Owner

benawad commented Mar 13, 2019

and I assume your calling registerEnumType

I would think passing it in as a string would work

@CoonHouse
Copy link
Author

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

@CoonHouse
Copy link
Author

This way it's working!

  it('Create new Arena', async () => {
    const result = await GraphQLCall({
      source: createArenaMutation,
      variableValues: {
        data: {
          .............
          location: "Indoor" as ArenaLocation,
          ...........
        },
      },
    })

regards

Wilco

@benawad
Copy link
Owner

benawad commented Mar 13, 2019

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants