question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

e2e tests: Undefined type error. Provide explicit type for the "user" of the "AuthResolver" class.

See original GitHub issue

Bug

Steps to reproduce

Expected behaviour

e2e tests passed

Actual behaviour

$ jest --config ./test/jest-e2e.json
 FAIL  test/app.resolver.e2e-spec.ts
  ● AppResolver (e2e) › helloWorld (Query)

    Undefined type error. Make sure you are providing an explicit type for the "user" of the "AuthResolver" class.

      at TypeMetadataStorageHost.compileExternalFieldResolverMetadata (../node_modules/@nestjs/graphql/dist/schema-builder/storages/type-metadata.storage.js:256:23)
      at ../node_modules/@nestjs/graphql/dist/schema-builder/storages/type-metadata.storage.js:240:22
          at Array.forEach (<anonymous>)
      at TypeMetadataStorageHost.compileFieldResolverMetadata (../node_modules/@nestjs/graphql/dist/schema-builder/storages/type-metadata.storage.js:229:18)
      at TypeMetadataStorageHost.compile (../node_modules/@nestjs/graphql/dist/schema-builder/storages/type-metadata.storage.js:144:14)
      at GraphQLSchemaFactory.<anonymous> (../node_modules/@nestjs/graphql/dist/schema-builder/graphql-schema.factory.js:38:57)
      at ../node_modules/@nestjs/graphql/node_modules/tslib/tslib.js:114:75
      at Object.__awaiter (../node_modules/@nestjs/graphql/node_modules/tslib/tslib.js:110:16)

  ● AppController (e2e) › /hello/:name (GET)

    Undefined type error. Make sure you are providing an explicit type for the "user" of the "AuthResolver" class.

[...]

How can I fix this? Thank you!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
lparolaricommented, Oct 7, 2020

After diving a bit into the problem and reading this illuminating issue https://github.com/nestjs/graphql/issues/226, I found that my problem is due to this portion of code

https://github.com/fivethree-team/nestjs-prisma-starter/blob/d628befcf507f4c7ab7b0fb55697ef997063e40e/src/resolvers/auth/auth.resolver.ts#L46-L49

and in particular to

https://github.com/fivethree-team/nestjs-prisma-starter/blob/d628befcf507f4c7ab7b0fb55697ef997063e40e/src/resolvers/auth/auth.resolver.ts#L46

where, as the error message says, I’m not providing an explicit type for “user”.

Fix

Import the user model and add the type explicitly to the decorator for the user method.

import { User } from '../../models/user.model';
@ResolveField('user', (of) => User)   // <-- modify this
async user(@Parent() auth: Auth) {
  return await this.auth.getUserFromToken(auth.accessToken);
}
1reaction
lparolaricommented, Oct 12, 2020

@marcjulian Sure, just did it. I hope it might help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Undefined type error. Make sure you are providing an ...
Error : Undefined type error. Make sure you are providing an explicit type for the "user" of the "Transaction" class.
Read more >
type-graphql/Lobby - Gitter
Error : Unable to infer GraphQL type from TypeScript reflection system. You need to provide explicit type for 'hasStaging' of 'DeploysCategory' class.
Read more >
Nest.js GraphQL Integration Testing Tutorial - YouTube
In this video, we learn how to write integration tests against a GraphQL server in Nest.js.
Read more >
Release 9.19.7 Internet Systems Consortium
or an error is received, at which point the user's original recursive ... The format of the data is type- and sometimes class-specific....
Read more >
An E2E test scenario in NestJS for a GraphQL mutation - Selleo
A function to set up the app for the E2E's test suite: ... DocumentStatus } from 'src/document/entities/document.type' import { GoogleStorageService } from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found