@envelop/core 1.8.0-alpha-2354554.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 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
@@ -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
@@ -1184,4 +1184,41 @@ const useMaskedErrors = (opts) => {
1184
1184
  };
1185
1185
  };
1186
1186
 
1187
- 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, useLazyLoadedSchema, useLogger, useMaskedErrors, usePayloadFormatter, useSchema, useTiming };
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-2354554.0",
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-2354554.0"
9
+ "@envelop/types": "1.6.0-alpha-f56d3a3.0"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",