Skip to content

Commit

Permalink
feat: non-breaking GraphQL Engine
Browse files Browse the repository at this point in the history
  • Loading branch information
saihaj committed Aug 17, 2022
1 parent ad5f346 commit 15abb85
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/core/src/create.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { GetEnvelopedFn, ComposeContext, Plugin, ArbitraryObject } from '@envelop/types';
import { isPluginEnabled, PluginOrDisabledPlugin } from './enable-if.js';
import { createEnvelopOrchestrator, EnvelopOrchestrator } from './orchestrator.js';
import { createEnvelopOrchestrator, EnvelopOrchestrator, GraphQLEngine } from './orchestrator.js';
import { traceOrchestrator } from './traced-orchestrator.js';

export function envelop<PluginsType extends Plugin<any>[]>(options: {
plugins: Array<PluginOrDisabledPlugin>;
enableInternalTracing?: boolean;
engine?: typeof GraphQLEngine;
}): GetEnvelopedFn<ComposeContext<PluginsType>> {
const plugins = options.plugins.filter(isPluginEnabled);
let orchestrator = createEnvelopOrchestrator<ComposeContext<PluginsType>>(plugins);
let orchestrator = createEnvelopOrchestrator<ComposeContext<PluginsType>>(plugins, options.engine);

if (options.enableInternalTracing) {
orchestrator = traceOrchestrator(orchestrator);
Expand Down
23 changes: 22 additions & 1 deletion packages/core/src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,31 @@ export type EnvelopOrchestrator<
getCurrentSchema: () => Maybe<GraphQLSchema>;
};

export const GraphQLEngine = ({
parseFn,
executeFn,
validateFn,
subscribeFn,
}: {
parseFn?: typeof parse;
executeFn?: typeof execute;
validateFn?: typeof validate;
subscribeFn?: typeof subscribe;
}) => {
return {
parse: parseFn ?? parse,
execute: executeFn ?? execute,
validate: validateFn ?? validate,
subscribe: subscribeFn ?? subscribe,
};
};

export function createEnvelopOrchestrator<PluginsContext extends DefaultContext>(
plugins: Plugin[]
plugins: Plugin[],
engine: typeof GraphQLEngine = GraphQLEngine
): EnvelopOrchestrator<any, PluginsContext> {
let schema: GraphQLSchema | undefined | null = null;
const { parse, execute, validate, subscribe } = engine({});
let initDone = false;
const onResolversHandlers: OnResolverCalledHook[] = [];
for (const plugin of plugins) {
Expand Down

0 comments on commit 15abb85

Please sign in to comment.