Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

feat: add ability to perform package override in config #2077

Merged
merged 1 commit into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Please follow individual releases for more information.

# 1.0.0

### Features

* Added ability to override package name in plugin config ([#2077](https://github.com/aerogear/graphback/pull/2077), fixed by [4cfd68c](https://github.com/aerogear/graphback/pull/2077/commits/4cfd68c8b3aeec44df610525686eedd7f1920ecb))

### Bug Fixes

* Logical `or` filter selector was not mapped correctly in `graphback-runtime-mongo` ([#2034](https://github.com/aerogear/graphback/pull/2034), fixed by [1ebe7e9](https://github.com/aerogear/graphback/pull/2034/commits/1ebe7e9bc8d3a61f0b3ef65b588881d16b7ae63f))
Expand Down
26 changes: 22 additions & 4 deletions packages/graphback/src/loadPlugins.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import { GraphbackPlugin } from "@graphback/core";

export function loadPlugins(pluginConfig: any): GraphbackPlugin[] {
if (!pluginConfig) {
interface PluginDefaultProps {
packageName?: string
}

interface PluginConfigMap {
[pluginName: string]: PluginConfig
}

interface PluginConfig extends PluginDefaultProps {
[key: string]: any
}

export function loadPlugins(pluginConfigMap: PluginConfigMap): GraphbackPlugin[] {
if (!pluginConfigMap) {
return [];
}

const pluginInstances = [];
for (const pluginLabel of Object.keys(pluginConfig)) {
for (const pluginLabel of Object.keys(pluginConfigMap)) {
let pluginName = pluginLabel;
if (pluginLabel.startsWith('graphback-')) {
// Internal graphback plugins needs rename
pluginName = pluginLabel.replace('graphback-', '@graphback/codegen-');
}
const packageName = pluginConfigMap[pluginLabel].packageName;
// override package name
if(packageName){
pluginName = packageName;
}

try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const plugin = require(pluginName);
if (plugin.Plugin) {
const config = pluginConfig[pluginLabel];
const config = pluginConfigMap[pluginLabel];
pluginInstances.push(new plugin.Plugin(config));
}
else {
Expand Down