Graphql: mix the code first and the schema first approach

Created on 6 Jun 2020  路  8Comments  路  Source: nestjs/graphql

I'm submitting a...


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

Current behavior


I have a plugin that automatically generates a graphql schema from my database and stores it in schema.graphql in the root directory.
Now this is the schema first approach. But I would like to add more resolvers that are not included in the generated schema.

Expected behavior


So I would like to mix schema first approach and code first approach.

Minimal reproduction of the problem with instructions


I have the automatically generated schema.graphql file and create an additional resolver HelloResolver

@Resolver("Hello")
export class HelloResolver {
  @Query(()=>String)
  hello() {
    return "hello";
  }
}

and import the module

GraphQLModule.forRoot({
      typePaths: ["./schema.graphql","./schema2.graphql"],
      autoSchemaFile:"./schema2.graphql"
    })

but now when I start the server I get the error message
UnhandledPromiseRejectionWarning: Error: "Mutation" defined in resolvers, but not in schema
The file schema2.graphql is created without any problems but including schema.graphql and schema2.graphql does not seem to work.

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


It should be possible to mix the code first and the schema first approach.

Thank you!

Environment


Nest version: 7.1.2


For Tooling issues:
- Node version: v10.19.0  
- Platform:  Linux

Others:

Most helpful comment

@renehauck I don't think you should close an issue if you find an ugly workaround :D It should be working seamlessly out of the box. It's a crucial functionality for those who want to gradually migrate from schema approach to code first

All 8 comments

@renehauck Have you found any solution for this?

@PedramMarandi
yes, I found something, but it's not as nice. You have to import the GraphQLModule with "include" a second time:

@Module({
  imports: [
    GraphQLModule.forRoot({
      autoSchemaFile:"./schema2.graphql",
      include: [HelloModule],
    }),
    GraphQLModule.forRoot({
      typePaths: ["./schema.graphql","./schema2.graphql"],
      include: [OtherModule,HelloModule],
    }),
    HelloModule,
   OtherModule
  ],
  controllers: [AppController],
  providers: [AppService],
})

@renehauck I don't think you should close an issue if you find an ugly workaround :D It should be working seamlessly out of the box. It's a crucial functionality for those who want to gradually migrate from schema approach to code first

I have the same Problem,any one can give some helpe?

sorry @beshanoe, yes I will reopen

thanks @renehauck
@erwzqsdsdsf what we decided to do for now is to add a second GraphQLModule with a different endpoint like /graphql2 and started migrating some queries and entities to it, and then on the client side we intercept the request to see which query it's requesting and route it to either /graphql or /graphql2 until we migrate everything to the graphql2

It would be nice if we could mix both approaches.

There are no plans to implement this feature in the foreseeable future.

Was this page helpful?
0 / 5 - 0 ratings