nestjs / graphql

GraphQL (TypeScript) module for Nest framework (node.js) 🍷
https://docs.nestjs.com/graphql/quick-start
MIT License
1.46k stars 396 forks source link

Support premade schema #49

Closed stevefan1999-personal closed 6 years ago

stevefan1999-personal commented 6 years ago

I'm submitting a...


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

Current behavior

typePaths is mandatory and dominant, without it on graphql.mergeTypes it will throw an error.

Expected behavior

I should be able to use a pre-cooked schema out of the box.

Minimal reproduction of the problem with instructions

    GraphQLModule.forRootAsync({
      imports: [
        TypeGQLModule.forSchema({
          resolvers: [
            DefaultResolver,
            ...ModuleLocator.flattenModuleField('resolvers')
          ],
          pubSub,
          authChecker
        })
      ],
      async useFactory(graphQL: GraphQlBridge): Promise<GqlModuleOptions> {
        const schema: GraphQLSchema = graphQL.buildSchema()

        const playground: any = {
          settings: {
            'editor.cursorShape': 'line'
          }
        }

        return {
          schema,
          introspection: true,
          tracing: true,
          context: ({ req, res }) => ({
            req,
            res
          }),
          playground
        }
      },
      inject: [GraphQlBridge]
    })
  ],

It failed with:

Error: Specified query type "Query" not found in document.
    at E:\typescript-starter\node_modules\graphql\utilities\buildASTSchema.js:184:15
    at Array.forEach (<anonymous>)
    at getOperationTypes (E:\typescript-starter\node_modules\graphql\utilities\buildASTSchema.js:177:27)
    at Object.buildASTSchema (E:\typescript-starter\node_modules\graphql\utilities\buildASTSchema.js:127:36)
    at Object.buildSchemaFromTypeDefinitions (E:\typescript-starter\node_modules\graphql-tools\dist\generate\buildSchemaFromTypeDefinitions.js:24:28)
    at Object.makeExecutableSchema (E:\typescript-starter\node_modules\graphql-tools\dist\makeExecutableSchema.js:27:29)
    at GraphQLFactory.mergeOptions (E:\typescript-starter\node_modules\@nestjs\graphql\dist\graphql.factory.js:30:98)
    at Function.<anonymous> (E:\typescript-starter\node_modules\@nestjs\graphql\dist\graphql.module.js:73:55)
    at Generator.next (<anonymous>)
    at E:\typescript-starter\node_modules\@nestjs\graphql\dist\graphql.module.js:19:71
    at new Promise (<anonymous>)
    at __awaiter (E:\typescript-starter\node_modules\@nestjs\graphql\dist\graphql.module.js:15:12)
    at Object.useFactory [as metatype] (E:\typescript-starter\node_modules\@nestjs\graphql\dist\graphql.module.js:71:68)
    at resolveConstructorParams (E:\typescript-starter\node_modules\@nestjs\core\injector\injector.js:68:55)
    at Injector.resolveConstructorParams (E:\typescript-starter\node_modules\@nestjs\core\injector\injector.js:99:30)
    at process._tickCallback (internal/process/next_tick.js:68:7)

What is the motivation / use case for changing the behavior?

I used MagnusCloudCorp/nestjs-type-graphql instead of the helpers from @nestjs/graphql provided out of the box and TypeGraphQL provided a compiled schema instead of SDL.

Environment


Nest version: 5.1.0

Extra info

This is the reason it failed: https://github.com/nestjs/graphql/blob/b58d3e50dc9672a1047ef192587849fbbfc42281/lib/graphql.factory.ts#L22-L37 My schema option, no matter what are always gonna be Object.assign'd

kamilmysliwiec commented 6 years ago

What exactly would you need to make this working correctly together? The possibility to pass a schema created beforehand?

stevefan1999-personal commented 6 years ago

@kamilmysliwiec Exactly! I tried to implement a quick fix with mergeSchemas.

kamilmysliwiec commented 6 years ago

Just merged and published as 5.1.1

lock[bot] commented 4 years ago

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.