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

TypeError: Cannot convert undefined or null to object #27

Closed
DanielKucal opened this issue Jun 7, 2018 · 4 comments
Closed

TypeError: Cannot convert undefined or null to object #27

DanielKucal opened this issue Jun 7, 2018 · 4 comments

Comments

@DanielKucal
Copy link

I have seen those similar issues nestjs/nest#484, nestjs/nest#488 and they seem to be resolved. However, I am on @nestjs/graphql v3.0.0, @nestjs/common and /core v5.0.0 and the following code:

@Module({
	imports: [GraphQLModule]
})
export class GraphQLSetupModule {
	private readonly schema: any;

	constructor(graphQLFactory: GraphQLFactory) {
		this.schema = graphQLFactory.createSchema({
			typeDefs: mergedTypes
		});
	}
}

where mergedTypes is exactly:

schema {
  query: Query
}

type Query {
  countries: [Country]
}

directive @entity on OBJECT

type Country @entity {
  # The id is also the official ISO code of the country.
  _id: ID
  name: String
}

fails with stack trace:

TypeError: Cannot convert undefined or null to object
    at Function.getPrototypeOf (<anonymous>)
    at ResolversExplorerService.filterResolvers (/Users/danielkucal/Applications/someApp/src/node_modules/@nestjs/graphql/dist/resolvers-explorer.service.js:34:34)
    at resolvers.flatMap.instance (/Users/danielkucal/Applications/someApp/src/node_modules/@nestjs/graphql/dist/resolvers-explorer.service.js:27:66)
    at map (/Users/danielkucal/Applications/someApp/src/node_modules/@nestjs/graphql/dist/resolvers-explorer.service.js:31:102)
    at Array.map (<anonymous>)
    at lodash_1.flattenDeep.modules.map.module (/Users/danielkucal/Applications/someApp/src/node_modules/@nestjs/graphql/dist/resolvers-explorer.service.js:31:80)
    at Array.map (<anonymous>)
    at ResolversExplorerService.flatMap (/Users/danielkucal/Applications/someApp/src/node_modules/@nestjs/graphql/dist/resolvers-explorer.service.js:31:45)
    at ResolversExplorerService.explore (/Users/danielkucal/Applications/someApp/src/node_modules/@nestjs/graphql/dist/resolvers-explorer.service.js:27:32)
    at GraphQLFactory.createSchema (/Users/danielkucal/Applications/someApp/src/node_modules/@nestjs/graphql/dist/graphql.factory.js:23:149)
    at new GraphQLSetupModule (/Users/danielkucal/Applications/someApp/src/LHBackend/dist/src/graphql/GraphQLSetupModule.js:27:38)
    at resolveConstructorParams (/Users/danielkucal/Applications/someApp/src/node_modules/@nestjs/core/injector/injector.js:64:84)
    at Injector.resolveConstructorParams (/Users/danielkucal/Applications/someApp/src/node_modules/@nestjs/core/injector/injector.js:86:30)
    at process._tickCallback (internal/process/next_tick.js:178:7)

Any ideas? Thanks in advance!

@cschroeter
Copy link

Works for me. Can you provide an example repo?

@DanielKucal
Copy link
Author

Further debugging shows it's probably caused by not-yet resolved dependency... It uses a resolver which returns a Promise and the error pasted here occurs before and Promise is resolved and instance of that service (for RabbitMQ) is null. It doesn't occur on other developer's Windows machine. Can I know what OS do you use? Maybe there is a relation.

@DanielKucal
Copy link
Author

The problem in our application was that GraphQL schema creation had been placed in a constructor of module instead of configure() lifecycle method. It was working on Windows and Linux, yet not on MacOS.

@lock
Copy link

lock bot commented Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants