@envelop/core 1.7.1 → 1.7.2-alpha-7ca7cb8.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.js +1 -63
- package/index.mjs +2 -64
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -27,69 +27,8 @@ function enableIf(condition, plugin) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
// import { AfterResolverHook, OnResolverCalledHook, ResolverFn } from '@envelop/types';
|
|
31
31
|
const resolversHooksSymbol = Symbol('RESOLVERS_HOOKS');
|
|
32
|
-
function prepareTracedSchema(schema) {
|
|
33
|
-
if (!schema || schema[trackedSchemaSymbol]) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
schema[trackedSchemaSymbol] = true;
|
|
37
|
-
const entries = Object.values(schema.getTypeMap());
|
|
38
|
-
for (const type of entries) {
|
|
39
|
-
if (!graphql.isIntrospectionType(type) && graphql.isObjectType(type)) {
|
|
40
|
-
const fields = Object.values(type.getFields());
|
|
41
|
-
for (const field of fields) {
|
|
42
|
-
let resolverFn = (field.resolve || graphql.defaultFieldResolver);
|
|
43
|
-
field.resolve = async (root, args, context, info) => {
|
|
44
|
-
if (context && context[resolversHooksSymbol]) {
|
|
45
|
-
const hooks = context[resolversHooksSymbol];
|
|
46
|
-
const afterCalls = [];
|
|
47
|
-
for (const hook of hooks) {
|
|
48
|
-
const afterFn = await hook({
|
|
49
|
-
root,
|
|
50
|
-
args,
|
|
51
|
-
context,
|
|
52
|
-
info,
|
|
53
|
-
resolverFn,
|
|
54
|
-
replaceResolverFn: newFn => {
|
|
55
|
-
resolverFn = newFn;
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
afterFn && afterCalls.push(afterFn);
|
|
59
|
-
}
|
|
60
|
-
try {
|
|
61
|
-
let result = await resolverFn(root, args, context, info);
|
|
62
|
-
for (const afterFn of afterCalls) {
|
|
63
|
-
afterFn({
|
|
64
|
-
result,
|
|
65
|
-
setResult: newResult => {
|
|
66
|
-
result = newResult;
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
catch (e) {
|
|
73
|
-
let resultErr = e;
|
|
74
|
-
for (const afterFn of afterCalls) {
|
|
75
|
-
afterFn({
|
|
76
|
-
result: resultErr,
|
|
77
|
-
setResult: newResult => {
|
|
78
|
-
resultErr = newResult;
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
throw resultErr;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
return resolverFn(root, args, context, info);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
32
|
|
|
94
33
|
const envelopIsIntrospectionSymbol = Symbol('ENVELOP_IS_INTROSPECTION');
|
|
95
34
|
function isOperationDefinition(def) {
|
|
@@ -307,7 +246,6 @@ function createEnvelopOrchestrator(plugins) {
|
|
|
307
246
|
// to allow setting the schema from the onPluginInit callback. We also need to make sure
|
|
308
247
|
// here not to call the same plugin that initiated the schema switch.
|
|
309
248
|
const replaceSchema = (newSchema, ignorePluginIndex = -1) => {
|
|
310
|
-
prepareTracedSchema(newSchema);
|
|
311
249
|
schema = newSchema;
|
|
312
250
|
if (initDone) {
|
|
313
251
|
for (const [i, plugin] of plugins.entries()) {
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from '@envelop/types';
|
|
2
|
-
import {
|
|
2
|
+
import { Kind, visit, BREAK, parse, specifiedRules, validate, execute, subscribe, GraphQLSchema, getOperationAST, GraphQLError } from 'graphql';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* This enum is used only internally in order to create nominal type for the disabled plugin
|
|
@@ -23,69 +23,8 @@ function enableIf(condition, plugin) {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
// import { AfterResolverHook, OnResolverCalledHook, ResolverFn } from '@envelop/types';
|
|
27
27
|
const resolversHooksSymbol = Symbol('RESOLVERS_HOOKS');
|
|
28
|
-
function prepareTracedSchema(schema) {
|
|
29
|
-
if (!schema || schema[trackedSchemaSymbol]) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
schema[trackedSchemaSymbol] = true;
|
|
33
|
-
const entries = Object.values(schema.getTypeMap());
|
|
34
|
-
for (const type of entries) {
|
|
35
|
-
if (!isIntrospectionType(type) && isObjectType(type)) {
|
|
36
|
-
const fields = Object.values(type.getFields());
|
|
37
|
-
for (const field of fields) {
|
|
38
|
-
let resolverFn = (field.resolve || defaultFieldResolver);
|
|
39
|
-
field.resolve = async (root, args, context, info) => {
|
|
40
|
-
if (context && context[resolversHooksSymbol]) {
|
|
41
|
-
const hooks = context[resolversHooksSymbol];
|
|
42
|
-
const afterCalls = [];
|
|
43
|
-
for (const hook of hooks) {
|
|
44
|
-
const afterFn = await hook({
|
|
45
|
-
root,
|
|
46
|
-
args,
|
|
47
|
-
context,
|
|
48
|
-
info,
|
|
49
|
-
resolverFn,
|
|
50
|
-
replaceResolverFn: newFn => {
|
|
51
|
-
resolverFn = newFn;
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
afterFn && afterCalls.push(afterFn);
|
|
55
|
-
}
|
|
56
|
-
try {
|
|
57
|
-
let result = await resolverFn(root, args, context, info);
|
|
58
|
-
for (const afterFn of afterCalls) {
|
|
59
|
-
afterFn({
|
|
60
|
-
result,
|
|
61
|
-
setResult: newResult => {
|
|
62
|
-
result = newResult;
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
return result;
|
|
67
|
-
}
|
|
68
|
-
catch (e) {
|
|
69
|
-
let resultErr = e;
|
|
70
|
-
for (const afterFn of afterCalls) {
|
|
71
|
-
afterFn({
|
|
72
|
-
result: resultErr,
|
|
73
|
-
setResult: newResult => {
|
|
74
|
-
resultErr = newResult;
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
throw resultErr;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
return resolverFn(root, args, context, info);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
28
|
|
|
90
29
|
const envelopIsIntrospectionSymbol = Symbol('ENVELOP_IS_INTROSPECTION');
|
|
91
30
|
function isOperationDefinition(def) {
|
|
@@ -303,7 +242,6 @@ function createEnvelopOrchestrator(plugins) {
|
|
|
303
242
|
// to allow setting the schema from the onPluginInit callback. We also need to make sure
|
|
304
243
|
// here not to call the same plugin that initiated the schema switch.
|
|
305
244
|
const replaceSchema = (newSchema, ignorePluginIndex = -1) => {
|
|
306
|
-
prepareTracedSchema(newSchema);
|
|
307
245
|
schema = newSchema;
|
|
308
246
|
if (initDone) {
|
|
309
247
|
for (const [i, plugin] of plugins.entries()) {
|