Graphql: UnhandledPromiseRejectionWarning: Error: Type Query must define one or more fields.

Created on 20 Jun 2019  路  3Comments  路  Source: nestjs/graphql

I'm submitting a...


[ ] Regression 
[-] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior


I get the error as subject when I npm run start:dev with the below GraphQLModule Import

import { GraphQLModule } from '@nestjs/graphql';

@Module({
  imports: [
   ...
    GraphQLModule.forRoot({
      typePaths: ['./**/*.graphql'],
    }),
   ...
  ],

The below is full error message.

[0] (node:9932) UnhandledPromiseRejectionWarning: Error: Type Query must define one or more fields.
[0]     at assertValidSchema (C:\Users\jahn\Documents\AngularProject\gfm-rest-api\node_modules\graphql\type\validate.js:80:11)
[0]     at assertValidExecutionArguments (C:\Users\jahn\Documents\AngularProject\gfm-rest-api\node_modules\graphql\execution\execute.js:146:35)
[0]     at executeImpl (C:\Users\jahn\Documents\AngularProject\gfm-rest-api\node_modules\graphql\execution\execute.js:67:3)
[0]     at Object.execute (C:\Users\jahn\Documents\AngularProject\gfm-rest-api\node_modules\graphql\execution\execute.js:62:256)
[0]     at Object.generateSchemaHash (C:\Users\jahn\Documents\AngularProject\gfm-rest-api\node_modules\apollo-server-core\src\utils\schemaHash.ts:11:18)
[0]     at new ApolloServerBase (C:\Users\jahn\Documents\AngularProject\gfm-rest-api\node_modules\apollo-server-core\src\ApolloServer.ts:326:23)
[0]     at new ApolloServer (C:\Users\jahn\Documents\AngularProject\gfm-rest-api\node_modules\apollo-server-express\src\ApolloServer.ts:84:5)
[0]     at GraphQLModule.<anonymous> (C:\Users\jahn\Documents\AngularProject\gfm-rest-api\node_modules\@nestjs\graphql\dist\graphql.module.js:115:33)
[0]     at Generator.next (<anonymous>)
[0]     at fulfilled (C:\Users\jahn\Documents\AngularProject\gfm-rest-api\node_modules\@nestjs\graphql\dist\graphql.module.js:16:58)
[0] (node:9932) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
[0] (node:9932) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Expected behavior


Running without error.

Minimal reproduction of the problem with instructions

  1. import the below in app.module.ts
import { GraphQLModule } from '@nestjs/graphql';

@Module({
  imports: [
   ...
    GraphQLModule.forRoot({
      typePaths: ['./**/*.graphql'],
    }),
   ...
  ],
  1. npm run start:dev

Environment

package.json

  "scripts": {
    "build": "tsc -p tsconfig.build.json",
    "format": "prettier --write \"src/**/*.ts\"",
    "start": "ts-node -r tsconfig-paths/register src/main.ts",
    "start:dev": "concurrently --handle-input \"wait-on dist/main.js && nodemon\" \"tsc -w -p tsconfig.build.json\" ",
    "start:debug": "nodemon --config nodemon-debug.json",
    "prestart:prod": "rimraf dist && npm run build",
    "start:prod": "node dist/main.js",
    "lint": "tslint -p tsconfig.json -c tslint.json",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json"
  },
  "dependencies": {
    "@nestjs/common": "^6.3.1",
    "@nestjs/core": "^6.3.1",
    "@nestjs/graphql": "^6.2.4",
    "@nestjs/platform-express": "^6.3.1",
    "@nestjs/typeorm": "^6.1.2",
    "apollo-server-express": "^2.6.3",
    "bcryptjs": "^2.4.3",
    "class-transformer": "^0.2.3",
    "class-validator": "^0.9.1",
    "dotenv": "^8.0.0",
    "graphql": "^14.3.1",
    "graphql-tools": "^4.0.4",
    "jsonwebtoken": "^8.5.1",
    "pg": "^7.11.0",
    "reflect-metadata": "^0.1.12",
    "rimraf": "^2.6.2",
    "rxjs": "^6.3.3",
    "typeorm": "^0.2.18"
  },
  "devDependencies": {
    "@nestjs/testing": "^6.3.1",
    "@types/bcryptjs": "^2.4.2",
    "@types/express": "^4.16.0",
    "@types/graphql": "^14.2.1",
    "@types/jest": "^23.3.13",
    "@types/jsonwebtoken": "^8.3.2",
    "@types/node": "^10.12.18",
    "@types/supertest": "^2.0.7",
    "concurrently": "^4.1.0",
    "jest": "^23.6.0",
    "nodemon": "^1.18.9",
    "prettier": "^1.15.3",
    "supertest": "^3.4.1",
    "ts-jest": "24.0.2",
    "ts-node": "8.1.0",
    "tsconfig-paths": "3.8.0",
    "tslint": "5.16.0",
    "typescript": "3.4.3",
    "wait-on": "^3.2.0"
  },

nodemon.json

{
  "watch": ["src"],
  "ext": "*",
  "ignore": ["src/**/*.spec.ts"],
  "exec": "ts-node -r tsconfig-paths/register src/main.ts"
}

Most helpful comment

As the error says, you need to define at least one Query?

It can't start a GraphQL server if it doesn't have any defined resolvers.

All 3 comments

As the error says, you need to define at least one Query?

It can't start a GraphQL server if it doesn't have any defined resolvers.

@marcus-sa

Yeah! I was stupid :)

Thanks for letting me know.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cschroeter picture cschroeter  路  3Comments

ghost picture ghost  路  5Comments

galkin picture galkin  路  4Comments

harm-less picture harm-less  路  4Comments

rkutca picture rkutca  路  3Comments