Graphql: GraphQLGatewayModule to provide schema at Gateway level

Created on 14 Apr 2021  路  2Comments  路  Source: nestjs/graphql

I'm submitting a...

Feature request

Current behavior

Is there any callback in the GraphQLGatewayModule which provides us with the schema in return on the gateway level ?

Expected behavior

Use the schema returned at the gateway level as input to the GraphQL to rest plugin

Minimal reproduction of the problem with instructions

@Module({
imports: [
GraphQLGatewayModule.forRoot({
server: {
// ... Apollo server options
cors: true,
},
gateway: {
serviceList: [
{ name: 'user', url: userSvcUri },
{ name: 'shipment', url: shipmentSvcUri },
],
},
}),
],
})

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

I would like to use the schema in https://www.npmjs.com/package/graphql2rest.

Environment

Nest version: 7.6.13

Most helpful comment

Please correct me if I'm wrong, but:

It's probably not possible or at least quite hard to achieve, since for GraphqlModule or GraphqlFederationModule there are either GraphqlSchemaHost.schema getter or (a bit dirty) app.get(GraphqlFederationModule).apolloServer['schema'] hack (see https://github.com/nestjs/graphql/pull/1482), because (schema + root resolvers) object with type of GraphQLSchema is created and stored in underlying apolloServer and get called there. On the other hand gateway utilizes "datasource" classes, such as RemoteGraphQLDataSource and does computation of the schema "on fly" in requestContext scope at the same time when it builds queryPlan and executes all underlying requests to get requested data. This might not be correct for other datasources tho

TL;DR there is no constant and fully reliable schema to get from gateway server due to underlying implementation with query plans and data fetches it makes, at least when using RemoteGraphqlDataSource

All 2 comments

Please correct me if I'm wrong, but:

It's probably not possible or at least quite hard to achieve, since for GraphqlModule or GraphqlFederationModule there are either GraphqlSchemaHost.schema getter or (a bit dirty) app.get(GraphqlFederationModule).apolloServer['schema'] hack (see https://github.com/nestjs/graphql/pull/1482), because (schema + root resolvers) object with type of GraphQLSchema is created and stored in underlying apolloServer and get called there. On the other hand gateway utilizes "datasource" classes, such as RemoteGraphQLDataSource and does computation of the schema "on fly" in requestContext scope at the same time when it builds queryPlan and executes all underlying requests to get requested data. This might not be correct for other datasources tho

TL;DR there is no constant and fully reliable schema to get from gateway server due to underlying implementation with query plans and data fetches it makes, at least when using RemoteGraphqlDataSource

@Maklestiguan answer is correct 馃憤

Was this page helpful?
0 / 5 - 0 ratings