@envelop/core
Advanced tools
Comparing version 0.3.1 to 0.3.2-alpha-e01c930.0
@@ -1,5 +0,5 @@ | ||
import { Envelop, Plugin } from '@envelop/types'; | ||
export declare function envelop(options: { | ||
plugins: Plugin[]; | ||
import { GetEnvelopedFn, ComposeContext, Plugin } from '@envelop/types'; | ||
export declare function envelop<PluginsType extends Plugin<any>[]>(options: { | ||
plugins: PluginsType; | ||
enableInternalTracing?: boolean; | ||
}): Envelop; | ||
}): GetEnvelopedFn<ComposeContext<PluginsType>>; |
30
index.js
@@ -70,2 +70,3 @@ 'use strict'; | ||
const replaceSchema = (newSchema, ignorePluginIndex = -1) => { | ||
prepareTracedSchema(newSchema); | ||
schema = newSchema; | ||
@@ -113,6 +114,6 @@ if (initDone) { | ||
const customParse = beforeCallbacks.parse.length | ||
? sharedObj => (source, parseOptions) => { | ||
? initialContext => (source, parseOptions) => { | ||
let result = null; | ||
let parseFn = graphql.parse; | ||
const context = sharedObj; | ||
const context = initialContext; | ||
const afterCalls = []; | ||
@@ -260,3 +261,3 @@ for (const onParse of beforeCallbacks.parse) { | ||
for (const onSubscribe of beforeCallbacks.subscribe) { | ||
const after = onSubscribe({ | ||
const after = await onSubscribe({ | ||
subscribeFn, | ||
@@ -318,3 +319,3 @@ setSubscribeFn: newSubscribeFn => { | ||
let stopCalled = false; | ||
const after = onExecute({ | ||
const after = await onExecute({ | ||
executeFn, | ||
@@ -387,3 +388,2 @@ setExecuteFn: newExecuteFn => { | ||
}, | ||
prepareSchema: () => prepareTracedSchema(schema), | ||
parse: customParse, | ||
@@ -415,2 +415,3 @@ validate: customValidate, | ||
parse: (ctx = {}) => { | ||
ctx._envelopTracing = ctx._envelopTracing || {}; | ||
const actualFn = orchestrator.parse(ctx); | ||
@@ -428,2 +429,3 @@ return (...args) => { | ||
validate: (ctx = {}) => { | ||
ctx._envelopTracing = ctx._envelopTracing || {}; | ||
const actualFn = orchestrator.validate(ctx); | ||
@@ -508,14 +510,10 @@ return (...args) => { | ||
const getEnveloped = (initialContext = {}) => { | ||
// DOTAN: Maybe this could be done as part of onSchemaChange instead of here? | ||
orchestrator.prepareSchema(); | ||
if (options.enableInternalTracing) { | ||
initialContext._envelopTracing = {}; | ||
} | ||
const typedOrchestrator = orchestrator; | ||
return { | ||
parse: orchestrator.parse(initialContext), | ||
validate: orchestrator.validate(initialContext), | ||
contextFactory: orchestrator.contextFactory(initialContext), | ||
execute: orchestrator.execute, | ||
subscribe: orchestrator.subscribe, | ||
schema: orchestrator.schema, | ||
parse: typedOrchestrator.parse(initialContext), | ||
validate: typedOrchestrator.validate(initialContext), | ||
contextFactory: typedOrchestrator.contextFactory(initialContext), | ||
execute: typedOrchestrator.execute, | ||
subscribe: typedOrchestrator.subscribe, | ||
schema: typedOrchestrator.schema, | ||
}; | ||
@@ -522,0 +520,0 @@ }; |
@@ -1,13 +0,12 @@ | ||
import { EnvelopContextFnWrapper, Plugin } from '@envelop/types'; | ||
import { execute, GraphQLSchema, parse, subscribe, validate } from 'graphql'; | ||
import { ArbitraryObject, EnvelopContextFnWrapper, GetEnvelopedFn, Plugin } from '@envelop/types'; | ||
import { GraphQLSchema } from 'graphql'; | ||
import { Maybe } from 'graphql/jsutils/Maybe'; | ||
export declare type EnvelopOrchestrator = { | ||
parse: EnvelopContextFnWrapper<typeof parse, any>; | ||
validate: EnvelopContextFnWrapper<typeof validate, any>; | ||
execute: typeof execute; | ||
subscribe: typeof subscribe; | ||
contextFactory: EnvelopContextFnWrapper<(context?: any) => any, any>; | ||
export declare type EnvelopOrchestrator<InitialContext extends ArbitraryObject = ArbitraryObject, PluginsContext extends ArbitraryObject = ArbitraryObject> = { | ||
parse: EnvelopContextFnWrapper<ReturnType<GetEnvelopedFn<PluginsContext>>['parse'], InitialContext>; | ||
validate: EnvelopContextFnWrapper<ReturnType<GetEnvelopedFn<PluginsContext>>['validate'], InitialContext>; | ||
execute: ReturnType<GetEnvelopedFn<PluginsContext>>['execute']; | ||
subscribe: ReturnType<GetEnvelopedFn<PluginsContext>>['subscribe']; | ||
contextFactory: EnvelopContextFnWrapper<ReturnType<GetEnvelopedFn<PluginsContext>>['contextFactory'], PluginsContext>; | ||
schema: Maybe<GraphQLSchema>; | ||
prepareSchema: () => void; | ||
}; | ||
export declare function createEnvelopOrchestrator(plugins: Plugin[]): EnvelopOrchestrator; | ||
export declare function createEnvelopOrchestrator<PluginsContext = any>(plugins: Plugin[]): EnvelopOrchestrator<any, PluginsContext>; |
{ | ||
"name": "@envelop/core", | ||
"version": "0.3.1", | ||
"version": "0.3.2-alpha-e01c930.0", | ||
"sideEffects": false, | ||
@@ -9,3 +9,3 @@ "peerDependencies": { | ||
"dependencies": { | ||
"@envelop/types": "0.2.1" | ||
"@envelop/types": "0.2.2-alpha-e01c930.0" | ||
}, | ||
@@ -12,0 +12,0 @@ "repository": { |
@@ -1,2 +0,2 @@ | ||
import { Envelop, Plugin } from '@envelop/types'; | ||
export declare const useEnvelop: (envelop: Envelop) => Plugin; | ||
import { GetEnvelopedFn, Plugin } from '@envelop/types'; | ||
export declare const useEnvelop: (envelop: GetEnvelopedFn<any>) => Plugin<any>; |
import { Plugin } from '@envelop/types'; | ||
export declare type ContextFactoryFn = (currentContext: unknown) => unknown; | ||
export declare const useExtendContext: (contextFactory: ContextFactoryFn) => Plugin; | ||
export declare type ContextFactoryFn<TResult = unknown> = (currentContext: unknown) => TResult | Promise<TResult>; | ||
declare type UnwrapAsync<T> = T extends Promise<infer U> ? U : T; | ||
export declare const useExtendContext: <TContextFactory extends (...args: any[]) => any>(contextFactory: TContextFactory) => Plugin<UnwrapAsync<ReturnType<TContextFactory>>>; | ||
export {}; |
@@ -0,2 +1,5 @@ | ||
import { ArbitraryObject } from 'packages/types/src/get-enveloped'; | ||
import { EnvelopOrchestrator } from './orchestrator'; | ||
export declare function traceOrchestrator(orchestrator: EnvelopOrchestrator): EnvelopOrchestrator; | ||
export declare function traceOrchestrator<TInitialContext extends ArbitraryObject, TPluginsContext extends ArbitraryObject>(orchestrator: EnvelopOrchestrator<TInitialContext, TPluginsContext>): EnvelopOrchestrator<TInitialContext & { | ||
_envelopTracing?: {}; | ||
}, TPluginsContext>; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
170563
+ Added@envelop/types@0.2.2-alpha-e01c930.0(transitive)
- Removed@envelop/types@0.2.1(transitive)