Skip to content

Commit

Permalink
feat(core): Added the current schema as an argument for api extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
sonntag-philipp committed Oct 26, 2024
1 parent d90a929 commit d0c9d86
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/api/config/configure-graphql-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ async function createGraphQLOptions(
let schema = buildSchema(typeDefs);

getPluginAPIExtensions(configService.plugins, apiType)
.map(e => (typeof e.schema === 'function' ? e.schema() : e.schema))
.map(e => (typeof e.schema === 'function' ? e.schema(schema) : e.schema))
.filter(notNullOrUndefined)
.forEach(documentNode => (schema = extendSchema(schema, documentNode)));
schema = generateListOptions(schema);
Expand Down
9 changes: 6 additions & 3 deletions packages/core/src/plugin/vendure-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ModuleMetadata } from '@nestjs/common/interfaces';
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR, APP_PIPE } from '@nestjs/core';
import { pick } from '@vendure/common/lib/pick';
import { Type } from '@vendure/common/lib/shared-types';
import { DocumentNode, GraphQLScalarType } from 'graphql';
import { DocumentNode, GraphQLScalarType, GraphQLSchema } from 'graphql';

import { RuntimeVendureConfig } from '../config/vendure-config';

Expand Down Expand Up @@ -84,13 +84,16 @@ export interface APIExtensionDefinition {
* }`;
* ```
*/
schema?: DocumentNode | (() => DocumentNode | undefined);
schema?:
| DocumentNode
| (() => DocumentNode | undefined)
| ((schema: GraphQLSchema) => DocumentNode | undefined);
/**
* @description
* An array of resolvers for the schema extensions. Should be defined as [Nestjs GraphQL resolver](https://docs.nestjs.com/graphql/resolvers-map)
* classes, i.e. using the Nest `\@Resolver()` decorator etc.
*/
resolvers?: Array<Type<any>> | (() => Array<Type<any>>);
resolvers?: Array<Type<any>> | (() => Array<Type<any>>) | ((schema: GraphQLSchema) => Array<Type<any>>);
/**
* @description
* A map of GraphQL scalar types which should correspond to any custom scalars defined in your schema.
Expand Down

0 comments on commit d0c9d86

Please sign in to comment.