@envelop/core 2.4.1 → 2.4.3-alpha-62b6e087.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -65,6 +65,9 @@ const useMaskedErrors = (opts) => {
65
65
  : undefined,
66
66
  onPluginInit(context) {
67
67
  context.registerContextErrorHandler(({ error, setError }) => {
68
+ if (error instanceof graphql_1.GraphQLError === false && error instanceof Error) {
69
+ error = new graphql_1.GraphQLError(error.message, undefined, undefined, undefined, undefined, error);
70
+ }
68
71
  setError(format(error, message, isDev));
69
72
  });
70
73
  },
@@ -60,6 +60,9 @@ export const useMaskedErrors = (opts) => {
60
60
  : undefined,
61
61
  onPluginInit(context) {
62
62
  context.registerContextErrorHandler(({ error, setError }) => {
63
+ if (error instanceof GraphQLError === false && error instanceof Error) {
64
+ error = new GraphQLError(error.message, undefined, undefined, undefined, undefined, error);
65
+ }
63
66
  setError(format(error, message, isDev));
64
67
  });
65
68
  },
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@envelop/core",
3
- "version": "2.4.1",
3
+ "version": "2.4.3-alpha-62b6e087.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
7
7
  },
8
8
  "dependencies": {
9
- "@envelop/types": "2.3.0"
9
+ "@envelop/types": "2.3.1"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
@@ -34,7 +34,7 @@
34
34
  "exports": {
35
35
  ".": {
36
36
  "require": {
37
- "types": "./typings/index.d.ts",
37
+ "types": "./typings/index.d.cts",
38
38
  "default": "./cjs/index.js"
39
39
  },
40
40
  "import": {
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "./*": {
50
50
  "require": {
51
- "types": "./typings/*.d.ts",
51
+ "types": "./typings/*.d.cts",
52
52
  "default": "./cjs/*.js"
53
53
  },
54
54
  "import": {
@@ -0,0 +1,6 @@
1
+ import { GetEnvelopedFn, ComposeContext, Plugin } from '@envelop/types';
2
+ import { PluginOrDisabledPlugin } from './enable-if.cjs';
3
+ export declare function envelop<PluginsType extends Plugin<any>[]>(options: {
4
+ plugins: Array<PluginOrDisabledPlugin>;
5
+ enableInternalTracing?: boolean;
6
+ }): GetEnvelopedFn<ComposeContext<PluginsType>>;
@@ -0,0 +1,14 @@
1
+ import { Plugin } from '@envelop/types';
2
+ /**
3
+ * This enum is used only internally in order to create nominal type for the disabled plugin
4
+ */
5
+ declare enum EnableIfBranded {
6
+ DisabledPlugin = 0
7
+ }
8
+ export declare type PluginOrDisabledPlugin = Plugin<any> | EnableIfBranded.DisabledPlugin;
9
+ export declare function isPluginEnabled(t: PluginOrDisabledPlugin): t is Plugin;
10
+ /**
11
+ * Utility function to enable a plugin.
12
+ */
13
+ export declare function enableIf<PluginContextType = {}>(condition: boolean, plugin: Plugin<PluginContextType> | (() => Plugin<PluginContextType>)): PluginOrDisabledPlugin;
14
+ export {};
@@ -0,0 +1,13 @@
1
+ export * from '@envelop/types';
2
+ export * from './create.cjs';
3
+ export * from './utils.cjs';
4
+ export * from './plugins/use-envelop.cjs';
5
+ export * from './plugins/use-logger.cjs';
6
+ export * from './plugins/use-timing.cjs';
7
+ export * from './plugins/use-schema.cjs';
8
+ export * from './plugins/use-error-handler.cjs';
9
+ export * from './plugins/use-extend-context.cjs';
10
+ export * from './plugins/use-payload-formatter.cjs';
11
+ export * from './plugins/use-masked-errors.cjs';
12
+ export * from './plugins/use-immediate-introspection.cjs';
13
+ export * from './enable-if.cjs';
@@ -0,0 +1,12 @@
1
+ import { ArbitraryObject, EnvelopContextFnWrapper, GetEnvelopedFn, Plugin, DefaultContext, Maybe } from '@envelop/types';
2
+ import { GraphQLSchema } from 'graphql';
3
+ export declare type EnvelopOrchestrator<InitialContext extends ArbitraryObject = ArbitraryObject, PluginsContext extends ArbitraryObject = ArbitraryObject> = {
4
+ init: (initialContext?: Maybe<InitialContext>) => void;
5
+ parse: EnvelopContextFnWrapper<ReturnType<GetEnvelopedFn<PluginsContext>>['parse'], InitialContext>;
6
+ validate: EnvelopContextFnWrapper<ReturnType<GetEnvelopedFn<PluginsContext>>['validate'], InitialContext>;
7
+ execute: ReturnType<GetEnvelopedFn<PluginsContext>>['execute'];
8
+ subscribe: ReturnType<GetEnvelopedFn<PluginsContext>>['subscribe'];
9
+ contextFactory: EnvelopContextFnWrapper<ReturnType<GetEnvelopedFn<PluginsContext>>['contextFactory'], PluginsContext>;
10
+ getCurrentSchema: () => Maybe<GraphQLSchema>;
11
+ };
12
+ export declare function createEnvelopOrchestrator<PluginsContext extends DefaultContext>(plugins: Plugin[]): EnvelopOrchestrator<any, PluginsContext>;
@@ -0,0 +1,2 @@
1
+ import { GetEnvelopedFn, Plugin } from '@envelop/types';
2
+ export declare const useEnvelop: (envelop: GetEnvelopedFn<any>) => Plugin<any>;
@@ -0,0 +1,4 @@
1
+ import { Plugin, DefaultContext } from '@envelop/types';
2
+ import { GraphQLError } from 'graphql';
3
+ export declare type ErrorHandler = (errors: readonly GraphQLError[], context: Readonly<DefaultContext>) => void;
4
+ export declare const useErrorHandler: <ContextType>(errorHandler: ErrorHandler) => Plugin<ContextType>;
@@ -0,0 +1,5 @@
1
+ import { Plugin } from '@envelop/types';
2
+ export declare type ContextFactoryFn<TResult = unknown, TCurrent = unknown> = (currentContext: TCurrent) => TResult | Promise<TResult>;
3
+ declare type UnwrapAsync<T> = T extends Promise<infer U> ? U : T;
4
+ export declare const useExtendContext: <TContextFactory extends (...args: any[]) => any>(contextFactory: TContextFactory) => Plugin<UnwrapAsync<ReturnType<TContextFactory>>>;
5
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from '@envelop/types';
2
+ /**
3
+ * In case a GraphQL operation only contains introspection fields the context building can be skipped completely.
4
+ * With this plugin any further context extensions will be skipped.
5
+ */
6
+ export declare const useImmediateIntrospection: () => Plugin;
@@ -0,0 +1,11 @@
1
+ import { Plugin } from '@envelop/types';
2
+ import { envelopIsIntrospectionSymbol } from '../utils.cjs';
3
+ declare type LoggerPluginOptions = {
4
+ logFn: typeof console.log;
5
+ skipIntrospection?: boolean;
6
+ };
7
+ declare type InternalPluginContext = {
8
+ [envelopIsIntrospectionSymbol]?: true;
9
+ };
10
+ export declare const useLogger: (rawOptions?: LoggerPluginOptions) => Plugin<InternalPluginContext>;
11
+ export {};
@@ -0,0 +1,39 @@
1
+ import { Plugin } from '@envelop/types';
2
+ import { GraphQLError, GraphQLErrorExtensions } from 'graphql';
3
+ export declare const DEFAULT_ERROR_MESSAGE = "Unexpected error.";
4
+ export declare class EnvelopError extends GraphQLError {
5
+ constructor(message: string, extensions?: GraphQLErrorExtensions);
6
+ }
7
+ export declare type FormatErrorHandler = (error: GraphQLError | unknown, message: string, isDev: boolean) => GraphQLError;
8
+ export declare const formatError: FormatErrorHandler;
9
+ export declare type UseMaskedErrorsOpts = {
10
+ /** The function used for format/identify errors. */
11
+ formatError?: FormatErrorHandler;
12
+ /** The error message that shall be used for masked errors. */
13
+ errorMessage?: string;
14
+ /**
15
+ * Additional information that is forwarded to the `formatError` function.
16
+ * The default value is `process.env['NODE_ENV'] === 'development'`
17
+ */
18
+ isDev?: boolean;
19
+ /**
20
+ * Whether parse errors should be processed by this plugin.
21
+ * In general it is not recommend to set this flag to `true`
22
+ * as a `parse` error contains useful information for debugging a GraphQL operation.
23
+ * A `parse` error never contains any sensitive information.
24
+ * @default false
25
+ */
26
+ handleParseErrors?: boolean;
27
+ /**
28
+ * Whether validation errors should processed by this plugin.
29
+ * In general we recommend against setting this flag to `true`
30
+ * as a `validate` error contains useful information for debugging a GraphQL operation.
31
+ * A `validate` error contains "did you mean x" suggestions that make it easier
32
+ * to reverse-introspect a GraphQL schema whose introspection capabilities got disabled.
33
+ * Instead of disabling introspection and masking validation errors, using persisted operations
34
+ * is a safer solution for avoiding the execution of unwanted/arbitrary operations.
35
+ * @default false
36
+ */
37
+ handleValidationErrors?: boolean;
38
+ };
39
+ export declare const useMaskedErrors: (opts?: UseMaskedErrorsOpts) => Plugin;
@@ -0,0 +1,4 @@
1
+ import { Plugin, TypedExecutionArgs } from '@envelop/types';
2
+ import { ExecutionResult } from 'graphql';
3
+ export declare type FormatterFunction = (result: ExecutionResult<any, any>, args: TypedExecutionArgs<any>) => false | ExecutionResult<any, any>;
4
+ export declare const usePayloadFormatter: (formatter: FormatterFunction) => Plugin;
@@ -0,0 +1,5 @@
1
+ import { GraphQLSchema } from 'graphql';
2
+ import { DefaultContext, Maybe, Plugin } from '@envelop/types';
3
+ export declare const useSchema: (schema: GraphQLSchema) => Plugin;
4
+ export declare const useLazyLoadedSchema: (schemaLoader: (context: Maybe<DefaultContext>) => GraphQLSchema) => Plugin;
5
+ export declare const useAsyncSchema: (schemaPromise: Promise<GraphQLSchema>) => Plugin;
@@ -0,0 +1,21 @@
1
+ import { Plugin } from '@envelop/types';
2
+ import { DocumentNode, ExecutionArgs, GraphQLResolveInfo, Source, SubscriptionArgs } from 'graphql';
3
+ import { envelopIsIntrospectionSymbol } from '../utils.cjs';
4
+ export declare type ResultTiming = {
5
+ ms: number;
6
+ ns: number;
7
+ };
8
+ export declare type TimingPluginOptions = {
9
+ skipIntrospection?: boolean;
10
+ onContextBuildingMeasurement?: (timing: ResultTiming) => void;
11
+ onExecutionMeasurement?: (args: ExecutionArgs, timing: ResultTiming) => void;
12
+ onSubscriptionMeasurement?: (args: SubscriptionArgs, timing: ResultTiming) => void;
13
+ onParsingMeasurement?: (source: Source | string, timing: ResultTiming) => void;
14
+ onValidationMeasurement?: (document: DocumentNode, timing: ResultTiming) => void;
15
+ onResolverMeasurement?: (info: GraphQLResolveInfo, timing: ResultTiming) => void;
16
+ };
17
+ declare type InternalPluginContext = {
18
+ [envelopIsIntrospectionSymbol]?: true;
19
+ };
20
+ export declare const useTiming: (rawOptions?: TimingPluginOptions) => Plugin<InternalPluginContext>;
21
+ export {};
@@ -0,0 +1,7 @@
1
+ import { ArbitraryObject } from '@envelop/types';
2
+ import { EnvelopOrchestrator } from './orchestrator.cjs';
3
+ declare const tracingSymbol: unique symbol;
4
+ export declare function traceOrchestrator<TInitialContext extends ArbitraryObject, TPluginsContext extends ArbitraryObject>(orchestrator: EnvelopOrchestrator<TInitialContext, TPluginsContext>): EnvelopOrchestrator<TInitialContext & {
5
+ [tracingSymbol]?: {};
6
+ }, TPluginsContext>;
7
+ export {};
@@ -0,0 +1,4 @@
1
+ import { GraphQLSchema } from 'graphql';
2
+ export declare const trackedSchemaSymbol: unique symbol;
3
+ export declare const resolversHooksSymbol: unique symbol;
4
+ export declare function prepareTracedSchema(schema: GraphQLSchema | null | undefined): void;
@@ -0,0 +1,33 @@
1
+ import { ASTNode, DocumentNode, OperationDefinitionNode, Source, ExecutionResult, SubscriptionArgs, ExecutionArgs } from 'graphql';
2
+ import { AsyncIterableIteratorOrValue, ExecuteFunction, SubscribeFunction, PromiseOrValue, DefaultContext, OnExecuteDoneEventPayload, OnExecuteDoneHookResult, OnExecuteDoneHookResultOnNextHook } from '@envelop/types';
3
+ export declare const envelopIsIntrospectionSymbol: unique symbol;
4
+ export declare function isOperationDefinition(def: ASTNode): def is OperationDefinitionNode;
5
+ export declare function isIntrospectionOperation(operation: OperationDefinitionNode): boolean;
6
+ export declare function isIntrospectionDocument(document: DocumentNode): boolean;
7
+ export declare function isIntrospectionOperationString(operation: string | Source): boolean;
8
+ /**
9
+ * Utility function for making a subscribe function that handles polymorphic arguments.
10
+ */
11
+ export declare const makeSubscribe: (subscribeFn: (args: SubscriptionArgs) => PromiseOrValue<AsyncIterableIterator<ExecutionResult>>) => SubscribeFunction;
12
+ export declare function mapAsyncIterator<T, O>(source: AsyncIterable<T>, mapper: (input: T) => Promise<O> | O): AsyncGenerator<O>;
13
+ /**
14
+ * Utility function for making a execute function that handles polymorphic arguments.
15
+ */
16
+ export declare const makeExecute: (executeFn: (args: ExecutionArgs) => PromiseOrValue<AsyncIterableIteratorOrValue<ExecutionResult>>) => ExecuteFunction;
17
+ /**
18
+ * Returns true if the provided object implements the AsyncIterator protocol via
19
+ * implementing a `Symbol.asyncIterator` method.
20
+ *
21
+ * Source: https://github.com/graphql/graphql-js/blob/main/src/jsutils/isAsyncIterable.ts
22
+ */
23
+ export declare function isAsyncIterable<TType>(maybeAsyncIterable: unknown): maybeAsyncIterable is AsyncIterable<TType>;
24
+ /**
25
+ * A utility function for handling `onExecuteDone` hook result, for simplifying the handling of AsyncIterable returned from `execute`.
26
+ *
27
+ * @param payload The payload send to `onExecuteDone` hook function
28
+ * @param fn The handler to be executed on each result
29
+ * @returns a subscription for streamed results, or undefined in case of an non-async
30
+ */
31
+ export declare function handleStreamOrSingleExecutionResult<ContextType = DefaultContext>(payload: OnExecuteDoneEventPayload<ContextType>, fn: OnExecuteDoneHookResultOnNextHook<ContextType>): void | OnExecuteDoneHookResult<ContextType>;
32
+ export declare function finalAsyncIterator<TInput>(source: AsyncIterable<TInput>, onFinal: () => void): AsyncGenerator<TInput>;
33
+ export declare function errorAsyncIterator<TInput>(source: AsyncIterable<TInput>, onError: (err: unknown) => void): AsyncGenerator<TInput>;