@envelop/types
Advanced tools
Comparing version 1.5.0 to 1.5.1
import type { DocumentNode, ExecutionArgs, ExecutionResult, GraphQLError, GraphQLResolveInfo, GraphQLSchema, ParseOptions, Source, SubscriptionArgs, ValidationRule } from 'graphql'; | ||
import { Maybe, PromiseOrValue } from './utils'; | ||
import { Maybe, PromiseOrValue, AsyncIterableIteratorOrValue } from './utils'; | ||
import { DefaultContext } from './context-types'; | ||
import { AsyncIterableIteratorOrValue, ExecuteFunction, ParseFunction, ValidateFunction, ValidateFunctionParameter } from '@envelop/core'; | ||
import { SubscribeFunction } from './graphql'; | ||
import { ExecuteFunction, ParseFunction, ValidateFunction, ValidateFunctionParameter, SubscribeFunction } from './graphql'; | ||
import { Plugin } from './plugin'; | ||
@@ -7,0 +6,0 @@ export declare type DefaultArgs = Record<string, unknown>; |
@@ -7,2 +7,1 @@ export * from './context-types'; | ||
export * from './utils'; | ||
export * from './async-utils'; |
36
index.js
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
/** | ||
* Returns true if the provided object implements the AsyncIterator protocol via | ||
* implementing a `Symbol.asyncIterator` method. | ||
* | ||
* Source: https://github.com/graphql/graphql-js/blob/main/src/jsutils/isAsyncIterable.ts | ||
*/ | ||
function isAsyncIterable(maybeAsyncIterable) { | ||
return (maybeAsyncIterable != null && | ||
typeof maybeAsyncIterable === 'object' && | ||
typeof maybeAsyncIterable[Symbol.asyncIterator] === 'function'); | ||
} | ||
/** | ||
* A utility function for hanlding `onExecuteDone` hook result, for simplifying the hanlding of AsyncIterable returned from `execute`. | ||
* | ||
* @param payload The payload send to `onExecuteDone` hook function | ||
* @param fn The handler to be executed on each result | ||
* @returns a subscription for streamed results, or undefined in case of an non-async | ||
*/ | ||
function handleStreamOrSingleExecutionResult(payload, fn) { | ||
if (isAsyncIterable(payload.result)) { | ||
return { onNext: fn }; | ||
} | ||
else { | ||
fn({ | ||
args: payload.args, | ||
result: payload.result, | ||
setResult: payload.setResult, | ||
}); | ||
return undefined; | ||
} | ||
} | ||
exports.handleStreamOrSingleExecutionResult = handleStreamOrSingleExecutionResult; | ||
exports.isAsyncIterable = isAsyncIterable; |
{ | ||
"name": "@envelop/types", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"sideEffects": false, | ||
@@ -5,0 +5,0 @@ "peerDependencies": { |
@@ -1,3 +0,2 @@ | ||
import { OnEnvelopedHook } from '@envelop/core'; | ||
import { OnContextBuildingHook, OnExecuteHook, OnParseHook, OnPluginInitHook, OnSchemaChangeHook, OnSubscribeHook, OnValidateHook } from './hooks'; | ||
import { OnEnvelopedHook, OnContextBuildingHook, OnExecuteHook, OnParseHook, OnPluginInitHook, OnSchemaChangeHook, OnSubscribeHook, OnValidateHook } from './hooks'; | ||
export interface Plugin<PluginContext extends Record<string, any> = {}> { | ||
@@ -4,0 +3,0 @@ /** |
Sorry, the diff of this file is not supported yet
23426
10
595