Type-graphql: Generating schema error

Created on 31 May 2018  路  5Comments  路  Source: MichalLytek/type-graphql

Attempts to load all resolvers fail with Generating schema error

async function bootstrap() {
  const schema = await buildSchema({
    resolvers: [__dirname + "/**/*.resolver.ts"],
  });

  // other initialization code, like creating http server
}
Question Solved

Most helpful comment

It appears that GeneratingSchemaError.details needs to be logged explicitly under these circumstances since it is not logged when a UnhandledPromiseRejectionWarning occurs.

Workaround

Before

export async function generateSchema(): Promise<GraphQLSchema> {
  return buildSchema({
    resolvers: [FunResolver]
  })

```
UnhandledPromiseRejectionWarning: Error: Generating schema error
... (no details)

## After
```ts
export async function generateSchema(): Promise<GraphQLSchema> {
  try {
    const schema = await buildSchema({
      resolvers: [FunResolver]
    })

    return schema
  } catch (e) {
    console.error(e)
    throw e
  }
}
GeneratingSchemaError: Generating schema error
...
details: [
    GraphQLError: Type Query must define one or more fields.

All 5 comments

GeneratingSchemaError has a details property of type ReadonlyArray<GraphQLError>.
I think that it might be useful in debugging the reason of this error 馃槈

@snaquaye
Have you figured out what was the problem?
Could you paste here the content of details property with GraphQL errors?

My bad! Trying to debug it, i noticed it is now working.

@snaquaye Do you remember what your actually solution was here?

It appears that GeneratingSchemaError.details needs to be logged explicitly under these circumstances since it is not logged when a UnhandledPromiseRejectionWarning occurs.

Workaround

Before

export async function generateSchema(): Promise<GraphQLSchema> {
  return buildSchema({
    resolvers: [FunResolver]
  })

```
UnhandledPromiseRejectionWarning: Error: Generating schema error
... (no details)

## After
```ts
export async function generateSchema(): Promise<GraphQLSchema> {
  try {
    const schema = await buildSchema({
      resolvers: [FunResolver]
    })

    return schema
  } catch (e) {
    console.error(e)
    throw e
  }
}
GeneratingSchemaError: Generating schema error
...
details: [
    GraphQLError: Type Query must define one or more fields.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

MichalLytek picture MichalLytek  路  3Comments

laukaichung picture laukaichung  路  3Comments

winuxue picture winuxue  路  4Comments

robertchung97 picture robertchung97  路  3Comments

reilem picture reilem  路  3Comments