UNPKG

@cran/gql.koa

Version:

Cran/GraphQL Koa Server

23 lines (22 loc) 882 B
/* eslint-disable @typescript-eslint/naming-convention */ import { ApolloServer } from "./ApolloServer"; export class DynamicApolloServer extends ApolloServer { schemaFactory; derivedData = new WeakMap(); constructor({ schemaFactory, ...rest }) { super(rest); this.schemaFactory = schemaFactory; } async createGraphQLServerOptions(...args) { const options = await super.createGraphQLServerOptions.apply(this, args); if (this.schemaFactory) { const schema = await this.schemaFactory.apply(null, args); if (!this.derivedData.has(schema)) { this.derivedData.set(schema, this.constructor.prototype .generateSchemaDerivedData.call(this, schema)); } Object.assign(options, await this.derivedData.get(schema)); } return options; } }