-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ced8f43
commit beae27a
Showing
15 changed files
with
125 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { SetMetadata } from '@nestjs/common'; | ||
import { PLUGIN_METADATA } from '../graphql.constants'; | ||
|
||
/** | ||
* Decorator that marks a class as a Apollo plugin. | ||
*/ | ||
export function Plugin(): ClassDecorator { | ||
return (target: Function) => { | ||
SetMetadata(PLUGIN_METADATA, true)(target); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './base-explorer.service'; | ||
export * from './gql-arguments-host'; | ||
export * from './gql-execution-context'; | ||
export * from './plugins-explorer.service'; | ||
export * from './resolvers-explorer.service'; | ||
export * from './scalars-explorer.service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper'; | ||
import { ModulesContainer } from '@nestjs/core/injector/modules-container'; | ||
import { GRAPHQL_MODULE_OPTIONS, PLUGIN_METADATA } from '../graphql.constants'; | ||
import { GqlModuleOptions } from '../interfaces/gql-module-options.interface'; | ||
import { BaseExplorerService } from './base-explorer.service'; | ||
|
||
@Injectable() | ||
export class PluginsExplorerService extends BaseExplorerService { | ||
constructor( | ||
private readonly modulesContainer: ModulesContainer, | ||
@Inject(GRAPHQL_MODULE_OPTIONS) | ||
private readonly gqlOptions: GqlModuleOptions, | ||
) { | ||
super(); | ||
} | ||
|
||
explore() { | ||
const modules = this.getModules( | ||
this.modulesContainer, | ||
this.gqlOptions.include || [], | ||
); | ||
return this.flatMap<any>(modules, instance => this.filterPlugins(instance)); | ||
} | ||
|
||
filterPlugins<T = any>(wrapper: InstanceWrapper<T>) { | ||
const { instance } = wrapper; | ||
if (!instance) { | ||
return undefined; | ||
} | ||
const metadata = Reflect.getMetadata(PLUGIN_METADATA, instance.constructor); | ||
return metadata ? instance : undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters