@envelop/core 1.8.0-alpha-0107392.0 → 1.8.0-alpha-f56d3a3.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.
- package/index.d.ts +1 -0
- package/index.js +44 -6
- package/index.mjs +44 -7
- package/package.json +2 -2
- package/plugins/use-immediate-introspection.d.ts +6 -0
- package/plugins/use-fast-introspection.d.ts +0 -2
package/index.d.ts
CHANGED
|
@@ -9,4 +9,5 @@ export * from './plugins/use-error-handler';
|
|
|
9
9
|
export * from './plugins/use-extend-context';
|
|
10
10
|
export * from './plugins/use-payload-formatter';
|
|
11
11
|
export * from './plugins/use-masked-errors';
|
|
12
|
+
export * from './plugins/use-immediate-introspection';
|
|
12
13
|
export * from './enable-if';
|
package/index.js
CHANGED
|
@@ -477,23 +477,23 @@ function createEnvelopOrchestrator(plugins) {
|
|
|
477
477
|
const afterCalls = [];
|
|
478
478
|
try {
|
|
479
479
|
let context = orchestratorCtx ? { ...initialContext, ...orchestratorCtx } : initialContext;
|
|
480
|
-
let
|
|
480
|
+
let isBreakingContextBuilding = false;
|
|
481
481
|
for (const onContext of beforeCallbacks.context) {
|
|
482
482
|
const afterHookResult = await onContext({
|
|
483
483
|
context,
|
|
484
484
|
extendContext: extension => {
|
|
485
485
|
context = { ...context, ...extension };
|
|
486
486
|
},
|
|
487
|
-
|
|
488
|
-
|
|
487
|
+
breakContextBuilding: () => {
|
|
488
|
+
isBreakingContextBuilding = true;
|
|
489
489
|
},
|
|
490
490
|
});
|
|
491
|
-
if (shortCircuitContext !== undefined) {
|
|
492
|
-
break;
|
|
493
|
-
}
|
|
494
491
|
if (typeof afterHookResult === 'function') {
|
|
495
492
|
afterCalls.push(afterHookResult);
|
|
496
493
|
}
|
|
494
|
+
if (isBreakingContextBuilding === true) {
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
497
|
}
|
|
498
498
|
for (const afterCb of afterCalls) {
|
|
499
499
|
afterCb({
|
|
@@ -1188,6 +1188,43 @@ const useMaskedErrors = (opts) => {
|
|
|
1188
1188
|
};
|
|
1189
1189
|
};
|
|
1190
1190
|
|
|
1191
|
+
const OnNonIntrospectionFieldReachedValidationRule = (onNonIntrospectionField) => () => {
|
|
1192
|
+
return {
|
|
1193
|
+
Field(field) {
|
|
1194
|
+
if (!field.name.value.startsWith('__')) {
|
|
1195
|
+
onNonIntrospectionField();
|
|
1196
|
+
}
|
|
1197
|
+
},
|
|
1198
|
+
};
|
|
1199
|
+
};
|
|
1200
|
+
const fastIntroSpectionSymbol = Symbol('fastIntrospection');
|
|
1201
|
+
/**
|
|
1202
|
+
* In case a GraphQL operation only contains introspection fields the context building can be skipped completely.
|
|
1203
|
+
* With this plugin any further context extensions will be skipped.
|
|
1204
|
+
*/
|
|
1205
|
+
const useImmediateIntrospection = () => {
|
|
1206
|
+
return {
|
|
1207
|
+
onValidate({ addValidationRule }) {
|
|
1208
|
+
let isIntrospectionOnly = true;
|
|
1209
|
+
addValidationRule(OnNonIntrospectionFieldReachedValidationRule(() => {
|
|
1210
|
+
isIntrospectionOnly = false;
|
|
1211
|
+
}));
|
|
1212
|
+
return function afterValidate({ extendContext }) {
|
|
1213
|
+
if (isIntrospectionOnly) {
|
|
1214
|
+
extendContext({ [fastIntroSpectionSymbol]: true });
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
},
|
|
1218
|
+
onContextBuilding({ context, breakContextBuilding }) {
|
|
1219
|
+
if (context[fastIntroSpectionSymbol]) {
|
|
1220
|
+
// hijack and skip all other context related stuff.
|
|
1221
|
+
// We dont need a context!
|
|
1222
|
+
breakContextBuilding();
|
|
1223
|
+
}
|
|
1224
|
+
},
|
|
1225
|
+
};
|
|
1226
|
+
};
|
|
1227
|
+
|
|
1191
1228
|
Object.keys(types).forEach(function (k) {
|
|
1192
1229
|
if (k !== 'default') Object.defineProperty(exports, k, {
|
|
1193
1230
|
enumerable: true,
|
|
@@ -1218,6 +1255,7 @@ exports.useAsyncSchema = useAsyncSchema;
|
|
|
1218
1255
|
exports.useEnvelop = useEnvelop;
|
|
1219
1256
|
exports.useErrorHandler = useErrorHandler;
|
|
1220
1257
|
exports.useExtendContext = useExtendContext;
|
|
1258
|
+
exports.useImmediateIntrospection = useImmediateIntrospection;
|
|
1221
1259
|
exports.useLazyLoadedSchema = useLazyLoadedSchema;
|
|
1222
1260
|
exports.useLogger = useLogger;
|
|
1223
1261
|
exports.useMaskedErrors = useMaskedErrors;
|
package/index.mjs
CHANGED
|
@@ -473,23 +473,23 @@ function createEnvelopOrchestrator(plugins) {
|
|
|
473
473
|
const afterCalls = [];
|
|
474
474
|
try {
|
|
475
475
|
let context = orchestratorCtx ? { ...initialContext, ...orchestratorCtx } : initialContext;
|
|
476
|
-
let
|
|
476
|
+
let isBreakingContextBuilding = false;
|
|
477
477
|
for (const onContext of beforeCallbacks.context) {
|
|
478
478
|
const afterHookResult = await onContext({
|
|
479
479
|
context,
|
|
480
480
|
extendContext: extension => {
|
|
481
481
|
context = { ...context, ...extension };
|
|
482
482
|
},
|
|
483
|
-
|
|
484
|
-
|
|
483
|
+
breakContextBuilding: () => {
|
|
484
|
+
isBreakingContextBuilding = true;
|
|
485
485
|
},
|
|
486
486
|
});
|
|
487
|
-
if (shortCircuitContext !== undefined) {
|
|
488
|
-
break;
|
|
489
|
-
}
|
|
490
487
|
if (typeof afterHookResult === 'function') {
|
|
491
488
|
afterCalls.push(afterHookResult);
|
|
492
489
|
}
|
|
490
|
+
if (isBreakingContextBuilding === true) {
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
493
|
}
|
|
494
494
|
for (const afterCb of afterCalls) {
|
|
495
495
|
afterCb({
|
|
@@ -1184,4 +1184,41 @@ const useMaskedErrors = (opts) => {
|
|
|
1184
1184
|
};
|
|
1185
1185
|
};
|
|
1186
1186
|
|
|
1187
|
-
|
|
1187
|
+
const OnNonIntrospectionFieldReachedValidationRule = (onNonIntrospectionField) => () => {
|
|
1188
|
+
return {
|
|
1189
|
+
Field(field) {
|
|
1190
|
+
if (!field.name.value.startsWith('__')) {
|
|
1191
|
+
onNonIntrospectionField();
|
|
1192
|
+
}
|
|
1193
|
+
},
|
|
1194
|
+
};
|
|
1195
|
+
};
|
|
1196
|
+
const fastIntroSpectionSymbol = Symbol('fastIntrospection');
|
|
1197
|
+
/**
|
|
1198
|
+
* In case a GraphQL operation only contains introspection fields the context building can be skipped completely.
|
|
1199
|
+
* With this plugin any further context extensions will be skipped.
|
|
1200
|
+
*/
|
|
1201
|
+
const useImmediateIntrospection = () => {
|
|
1202
|
+
return {
|
|
1203
|
+
onValidate({ addValidationRule }) {
|
|
1204
|
+
let isIntrospectionOnly = true;
|
|
1205
|
+
addValidationRule(OnNonIntrospectionFieldReachedValidationRule(() => {
|
|
1206
|
+
isIntrospectionOnly = false;
|
|
1207
|
+
}));
|
|
1208
|
+
return function afterValidate({ extendContext }) {
|
|
1209
|
+
if (isIntrospectionOnly) {
|
|
1210
|
+
extendContext({ [fastIntroSpectionSymbol]: true });
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
},
|
|
1214
|
+
onContextBuilding({ context, breakContextBuilding }) {
|
|
1215
|
+
if (context[fastIntroSpectionSymbol]) {
|
|
1216
|
+
// hijack and skip all other context related stuff.
|
|
1217
|
+
// We dont need a context!
|
|
1218
|
+
breakContextBuilding();
|
|
1219
|
+
}
|
|
1220
|
+
},
|
|
1221
|
+
};
|
|
1222
|
+
};
|
|
1223
|
+
|
|
1224
|
+
export { DEFAULT_ERROR_MESSAGE, EnvelopError, enableIf, envelop, envelopIsIntrospectionSymbol, errorAsyncIterator, finalAsyncIterator, formatError, handleStreamOrSingleExecutionResult, isAsyncIterable, isIntrospectionDocument, isIntrospectionOperation, isIntrospectionOperationString, isOperationDefinition, isPluginEnabled, makeExecute, makeSubscribe, mapAsyncIterator, useAsyncSchema, useEnvelop, useErrorHandler, useExtendContext, useImmediateIntrospection, useLazyLoadedSchema, useLogger, useMaskedErrors, usePayloadFormatter, useSchema, useTiming };
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/core",
|
|
3
|
-
"version": "1.8.0-alpha-
|
|
3
|
+
"version": "1.8.0-alpha-f56d3a3.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": "1.6.0-alpha-
|
|
9
|
+
"@envelop/types": "1.6.0-alpha-f56d3a3.0"
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
@@ -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;
|