Feature request
Is there any callback in the GraphQLGatewayModule which provides us with the schema in return on the gateway level ?
Use the schema returned at the gateway level as input to the GraphQL to rest plugin
@Module({
imports: [
GraphQLGatewayModule.forRoot({
server: {
// ... Apollo server options
cors: true,
},
gateway: {
serviceList: [
{ name: 'user', url: userSvcUri },
{ name: 'shipment', url: shipmentSvcUri },
],
},
}),
],
})
I would like to use the schema in https://www.npmjs.com/package/graphql2rest.
Nest version: 7.6.13
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 馃憤
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
GraphqlModuleorGraphqlFederationModulethere are eitherGraphqlSchemaHost.schemagetter 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 ofGraphQLSchemais created and stored in underlyingapolloServerand get called there. On the other hand gateway utilizes "datasource" classes, such asRemoteGraphQLDataSourceand 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 thoTL;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