@envelop/immediate-introspection 0.0.1-alpha-20220824152235-afd061e6

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/README.md ADDED
@@ -0,0 +1 @@
1
+ ## `@envelop/immediate-introspection`
package/cjs/index.js ADDED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useImmediateIntrospection = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const OnNonIntrospectionFieldReachedValidationRule = (onNonIntrospectionField) => ctx => {
6
+ const rootQueryType = ctx.getSchema().getQueryType();
7
+ const rootMutationType = ctx.getSchema().getMutationType();
8
+ const rootSubscriptionType = ctx.getSchema().getSubscriptionType();
9
+ return {
10
+ Field(field) {
11
+ const parentType = ctx.getParentType();
12
+ const isQuery = parentType === rootQueryType;
13
+ const isMutation = parentType === rootMutationType;
14
+ const isSubscription = parentType === rootSubscriptionType;
15
+ if ((isQuery && !field.name.value.startsWith('__')) || isMutation || isSubscription) {
16
+ onNonIntrospectionField();
17
+ return graphql_1.BREAK;
18
+ }
19
+ return undefined;
20
+ },
21
+ };
22
+ };
23
+ const fastIntroSpectionSymbol = Symbol('fastIntrospection');
24
+ /**
25
+ * In case a GraphQL operation only contains introspection fields the context building can be skipped completely.
26
+ * With this plugin any further context extensions will be skipped.
27
+ */
28
+ const useImmediateIntrospection = () => {
29
+ return {
30
+ onValidate({ addValidationRule }) {
31
+ let isIntrospectionOnly = true;
32
+ addValidationRule(OnNonIntrospectionFieldReachedValidationRule(() => {
33
+ isIntrospectionOnly = false;
34
+ }));
35
+ return function afterValidate({ extendContext }) {
36
+ if (isIntrospectionOnly) {
37
+ extendContext({ [fastIntroSpectionSymbol]: true });
38
+ }
39
+ };
40
+ },
41
+ onContextBuilding({ context, breakContextBuilding }) {
42
+ if (context[fastIntroSpectionSymbol]) {
43
+ // hijack and skip all other context related stuff.
44
+ // We dont need a context!
45
+ breakContextBuilding();
46
+ }
47
+ },
48
+ };
49
+ };
50
+ exports.useImmediateIntrospection = useImmediateIntrospection;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
package/esm/index.js ADDED
@@ -0,0 +1,46 @@
1
+ import { BREAK } from 'graphql';
2
+ const OnNonIntrospectionFieldReachedValidationRule = (onNonIntrospectionField) => ctx => {
3
+ const rootQueryType = ctx.getSchema().getQueryType();
4
+ const rootMutationType = ctx.getSchema().getMutationType();
5
+ const rootSubscriptionType = ctx.getSchema().getSubscriptionType();
6
+ return {
7
+ Field(field) {
8
+ const parentType = ctx.getParentType();
9
+ const isQuery = parentType === rootQueryType;
10
+ const isMutation = parentType === rootMutationType;
11
+ const isSubscription = parentType === rootSubscriptionType;
12
+ if ((isQuery && !field.name.value.startsWith('__')) || isMutation || isSubscription) {
13
+ onNonIntrospectionField();
14
+ return BREAK;
15
+ }
16
+ return undefined;
17
+ },
18
+ };
19
+ };
20
+ const fastIntroSpectionSymbol = Symbol('fastIntrospection');
21
+ /**
22
+ * In case a GraphQL operation only contains introspection fields the context building can be skipped completely.
23
+ * With this plugin any further context extensions will be skipped.
24
+ */
25
+ export const useImmediateIntrospection = () => {
26
+ return {
27
+ onValidate({ addValidationRule }) {
28
+ let isIntrospectionOnly = true;
29
+ addValidationRule(OnNonIntrospectionFieldReachedValidationRule(() => {
30
+ isIntrospectionOnly = false;
31
+ }));
32
+ return function afterValidate({ extendContext }) {
33
+ if (isIntrospectionOnly) {
34
+ extendContext({ [fastIntroSpectionSymbol]: true });
35
+ }
36
+ };
37
+ },
38
+ onContextBuilding({ context, breakContextBuilding }) {
39
+ if (context[fastIntroSpectionSymbol]) {
40
+ // hijack and skip all other context related stuff.
41
+ // We dont need a context!
42
+ breakContextBuilding();
43
+ }
44
+ },
45
+ };
46
+ };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@envelop/immediate-introspection",
3
+ "version": "0.0.1-alpha-20220824152235-afd061e6",
4
+ "sideEffects": false,
5
+ "peerDependencies": {
6
+ "@envelop/core": "2.5.1-alpha-20220824152235-afd061e6",
7
+ "@sentry/node": "^6 || ^7",
8
+ "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
9
+ },
10
+ "dependencies": {},
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/n1ru4l/envelop.git",
14
+ "directory": "packages/plugins/immediate-introspection"
15
+ },
16
+ "author": "Saihajpreet Singh <saihajpreet.singh@gmail.com>",
17
+ "license": "MIT",
18
+ "main": "cjs/index.js",
19
+ "module": "esm/index.js",
20
+ "typings": "typings/index.d.ts",
21
+ "typescript": {
22
+ "definition": "typings/index.d.ts"
23
+ },
24
+ "type": "module",
25
+ "exports": {
26
+ ".": {
27
+ "require": {
28
+ "types": "./typings/index.d.cts",
29
+ "default": "./cjs/index.js"
30
+ },
31
+ "import": {
32
+ "types": "./typings/index.d.ts",
33
+ "default": "./esm/index.js"
34
+ },
35
+ "default": {
36
+ "types": "./typings/index.d.ts",
37
+ "default": "./esm/index.js"
38
+ }
39
+ },
40
+ "./*": {
41
+ "require": {
42
+ "types": "./typings/*.d.cts",
43
+ "default": "./cjs/*.js"
44
+ },
45
+ "import": {
46
+ "types": "./typings/*.d.ts",
47
+ "default": "./esm/*.js"
48
+ },
49
+ "default": {
50
+ "types": "./typings/*.d.ts",
51
+ "default": "./esm/*.js"
52
+ }
53
+ },
54
+ "./package.json": "./package.json"
55
+ }
56
+ }
@@ -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,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;