@envelop/core
Advanced tools
Comparing version
44
index.js
@@ -302,2 +302,6 @@ 'use strict'; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
function isPromise(obj) { | ||
return obj != null && obj.then; | ||
} | ||
@@ -1092,15 +1096,44 @@ function createEnvelopOrchestrator(plugins) { | ||
const useLazyLoadedSchema = (schemaLoader) => { | ||
let schemaSet$; | ||
return { | ||
onEnveloped({ setSchema, context }) { | ||
setSchema(schemaLoader(context)); | ||
const schema$ = schemaLoader(context); | ||
if (isPromise(schema$)) { | ||
schemaSet$ = schema$.then(schemaObj => { | ||
setSchema(schemaObj); | ||
}); | ||
} | ||
else { | ||
setSchema(schema$); | ||
} | ||
}, | ||
onExecute() { | ||
if (schemaSet$) { | ||
return schemaSet$; | ||
} | ||
return undefined; | ||
}, | ||
}; | ||
}; | ||
const useAsyncSchema = (schemaPromise) => { | ||
const useAsyncSchema = (schema$) => { | ||
let schemaSet$; | ||
return { | ||
onPluginInit({ setSchema }) { | ||
schemaPromise.then(schemaObj => { | ||
setSchema(schemaObj); | ||
}); | ||
if (isPromise(schema$)) { | ||
schemaSet$ = schema$.then(schemaObj => { | ||
setSchema(schemaObj); | ||
}); | ||
} | ||
else { | ||
setSchema(schema$); | ||
} | ||
}, | ||
onContextBuilding() { | ||
return () => { | ||
if (schemaSet$) { | ||
return schemaSet$; | ||
} | ||
return undefined; | ||
}; | ||
}, | ||
}; | ||
@@ -1301,2 +1334,3 @@ }; | ||
exports.isPluginEnabled = isPluginEnabled; | ||
exports.isPromise = isPromise; | ||
exports.makeExecute = makeExecute; | ||
@@ -1303,0 +1337,0 @@ exports.makeSubscribe = makeSubscribe; |
{ | ||
"name": "@envelop/core", | ||
"version": "2.3.1", | ||
"version": "2.3.2-alpha-e3ced2d.0", | ||
"sideEffects": false, | ||
@@ -5,0 +5,0 @@ "peerDependencies": { |
import { GraphQLSchema } from 'graphql'; | ||
import { DefaultContext, Maybe, Plugin } from '@envelop/types'; | ||
import { DefaultContext, Maybe, Plugin, PromiseOrValue } from '@envelop/types'; | ||
export declare const useSchema: (schema: GraphQLSchema) => Plugin; | ||
export declare const useLazyLoadedSchema: (schemaLoader: (context: Maybe<DefaultContext>) => GraphQLSchema) => Plugin; | ||
export declare const useAsyncSchema: (schemaPromise: Promise<GraphQLSchema>) => Plugin; | ||
export declare const useLazyLoadedSchema: (schemaLoader: (context: Maybe<DefaultContext>) => PromiseOrValue<GraphQLSchema>) => Plugin; | ||
export declare const useAsyncSchema: (schema$: PromiseOrValue<GraphQLSchema>) => Plugin; |
@@ -34,1 +34,2 @@ import { ASTNode, DocumentNode, OperationDefinitionNode, Source, ExecutionResult, SubscriptionArgs, ExecutionArgs } from 'graphql'; | ||
export declare function errorAsyncIterator<TInput>(source: AsyncIterable<TInput>, onError: (err: unknown) => void): AsyncGenerator<TInput>; | ||
export declare function isPromise<T>(obj: any): obj is Promise<T>; |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
112281
1.8%2806
2.48%2
100%