@webiny/handler-graphql 0.0.0-mt-2 → 0.0.0-unstable.085ff6572f
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/builtInTypes/AnyScalar.d.ts +1 -1
- package/builtInTypes/AnyScalar.js +3 -6
- package/builtInTypes/AnyScalar.js.map +1 -0
- package/builtInTypes/DateScalar.js +5 -16
- package/builtInTypes/DateScalar.js.map +1 -0
- package/builtInTypes/DateTimeScalar.js +3 -14
- package/builtInTypes/DateTimeScalar.js.map +1 -0
- package/builtInTypes/DateTimeZScalar.js +1 -14
- package/builtInTypes/DateTimeZScalar.js.map +1 -0
- package/builtInTypes/JsonScalar.js +0 -2
- package/builtInTypes/JsonScalar.js.map +1 -0
- package/builtInTypes/LongScalar.d.ts +2 -1
- package/builtInTypes/LongScalar.js +49 -4
- package/builtInTypes/LongScalar.js.map +1 -0
- package/builtInTypes/NumberScalar.d.ts +1 -1
- package/builtInTypes/NumberScalar.js +10 -15
- package/builtInTypes/NumberScalar.js.map +1 -0
- package/builtInTypes/RefInputScalar.d.ts +1 -1
- package/builtInTypes/RefInputScalar.js +3 -14
- package/builtInTypes/RefInputScalar.js.map +1 -0
- package/builtInTypes/TimeScalar.js +1 -13
- package/builtInTypes/TimeScalar.js.map +1 -0
- package/builtInTypes/index.js +0 -18
- package/builtInTypes/index.js.map +1 -0
- package/createGraphQLHandler.d.ts +1 -1
- package/createGraphQLHandler.js +74 -58
- package/createGraphQLHandler.js.map +1 -0
- package/createGraphQLSchema.d.ts +4 -3
- package/createGraphQLSchema.js +27 -23
- package/createGraphQLSchema.js.map +1 -0
- package/debugPlugins.d.ts +10 -8
- package/debugPlugins.js +16 -28
- package/debugPlugins.js.map +1 -0
- package/errors.d.ts +2 -2
- package/errors.js +1 -6
- package/errors.js.map +1 -0
- package/index.d.ts +2 -4
- package/index.js +23 -21
- package/index.js.map +1 -0
- package/interceptConsole.d.ts +5 -1
- package/interceptConsole.js +5 -7
- package/interceptConsole.js.map +1 -0
- package/package.json +21 -20
- package/plugins/GraphQLSchemaPlugin.d.ts +2 -2
- package/plugins/GraphQLSchemaPlugin.js +1 -8
- package/plugins/GraphQLSchemaPlugin.js.map +1 -0
- package/plugins/index.js +0 -2
- package/plugins/index.js.map +1 -0
- package/processRequestBody.d.ts +4 -1
- package/processRequestBody.js +6 -14
- package/processRequestBody.js.map +1 -0
- package/responses.d.ts +20 -18
- package/responses.js +22 -23
- package/responses.js.map +1 -0
- package/types.d.ts +7 -5
- package/types.js.map +1 -0
package/createGraphQLHandler.js
CHANGED
|
@@ -1,77 +1,93 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
8
|
var _boolean = require("boolean");
|
|
13
|
-
|
|
9
|
+
var _handler = require("@webiny/handler");
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
14
11
|
var _createGraphQLSchema = require("./createGraphQLSchema");
|
|
15
|
-
|
|
16
12
|
var _debugPlugins = _interopRequireDefault(require("./debugPlugins"));
|
|
17
|
-
|
|
18
13
|
var _processRequestBody = _interopRequireDefault(require("./processRequestBody"));
|
|
19
|
-
|
|
20
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
21
|
-
|
|
22
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
23
|
-
|
|
24
|
-
const DEFAULT_HEADERS = {
|
|
25
|
-
"Content-Type": "application/json",
|
|
26
|
-
"Access-Control-Allow-Origin": "*",
|
|
27
|
-
"Access-Control-Allow-Headers": "*",
|
|
28
|
-
"Access-Control-Allow-Methods": "OPTIONS,POST"
|
|
29
|
-
};
|
|
30
14
|
const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
31
15
|
|
|
16
|
+
const createCacheKey = context => {
|
|
17
|
+
const plugins = (0, _createGraphQLSchema.getSchemaPlugins)(context);
|
|
18
|
+
// TODO: in the near future, we have to assign a fixed name to every GraphQLSchema plugin,
|
|
19
|
+
// to be able to create a reliable cache key.
|
|
20
|
+
return plugins.length.toString();
|
|
21
|
+
};
|
|
22
|
+
const createRequestBody = body => {
|
|
23
|
+
/**
|
|
24
|
+
* We are trusting that the body payload is correct.
|
|
25
|
+
* The `processRequestBody` will fail if it is not.
|
|
26
|
+
*/
|
|
27
|
+
return typeof body === "string" ? JSON.parse(body) : body;
|
|
28
|
+
};
|
|
29
|
+
const formatErrorPayload = error => {
|
|
30
|
+
if (error instanceof _error.default) {
|
|
31
|
+
return JSON.stringify({
|
|
32
|
+
type: "CoreGraphQLWebinyError",
|
|
33
|
+
message: error.message,
|
|
34
|
+
code: error.code,
|
|
35
|
+
data: error.data
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return JSON.stringify({
|
|
39
|
+
type: "Error",
|
|
40
|
+
name: error.name,
|
|
41
|
+
message: error.message,
|
|
42
|
+
stack: error.stack
|
|
43
|
+
});
|
|
44
|
+
};
|
|
32
45
|
var _default = (options = {}) => {
|
|
33
|
-
let schema;
|
|
46
|
+
let schema = undefined;
|
|
47
|
+
let cacheKey = undefined;
|
|
34
48
|
const debug = (0, _boolean.boolean)(options.debug);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
49
|
+
const path = (options === null || options === void 0 ? void 0 : options.path) || "/graphql";
|
|
50
|
+
const route = new _handler.RoutePlugin(async ({
|
|
51
|
+
onPost,
|
|
52
|
+
onOptions,
|
|
53
|
+
context
|
|
54
|
+
}) => {
|
|
55
|
+
onOptions(path, async (_, reply) => {
|
|
56
|
+
return reply.status(204).headers({
|
|
57
|
+
"Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`
|
|
58
|
+
}).send({}).hijack();
|
|
59
|
+
});
|
|
60
|
+
onPost(path, async (request, reply) => {
|
|
61
|
+
const contextCacheKey = createCacheKey(context);
|
|
62
|
+
if (!schema || cacheKey !== contextCacheKey) {
|
|
63
|
+
try {
|
|
64
|
+
schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
|
|
65
|
+
cacheKey = contextCacheKey;
|
|
66
|
+
} catch (ex) {
|
|
67
|
+
return reply.code(500).send(formatErrorPayload(ex));
|
|
68
|
+
}
|
|
55
69
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
70
|
+
let body;
|
|
71
|
+
try {
|
|
72
|
+
body = createRequestBody(request.body);
|
|
73
|
+
} catch (ex) {
|
|
74
|
+
console.error(`Error while creating the body request.`);
|
|
75
|
+
console.error(formatErrorPayload(ex));
|
|
76
|
+
throw ex;
|
|
59
77
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
78
|
+
try {
|
|
79
|
+
const result = await (0, _processRequestBody.default)(body, schema, context);
|
|
80
|
+
return reply.status(200).send(result);
|
|
81
|
+
} catch (ex) {
|
|
82
|
+
console.error(`Error while processing the body request.`);
|
|
83
|
+
console.error(formatErrorPayload(ex));
|
|
84
|
+
throw ex;
|
|
63
85
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
headers: DEFAULT_HEADERS
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
}];
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
route.name = "handler.graphql.route.default";
|
|
89
|
+
return [...(debug ? (0, _debugPlugins.default)() : []), {
|
|
90
|
+
type: "wcp-telemetry-tracker"
|
|
91
|
+
}, route];
|
|
75
92
|
};
|
|
76
|
-
|
|
77
93
|
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DEFAULT_CACHE_MAX_AGE","createCacheKey","context","plugins","getSchemaPlugins","length","toString","createRequestBody","body","JSON","parse","formatErrorPayload","error","WebinyError","stringify","type","message","code","data","name","stack","options","schema","undefined","cacheKey","debug","boolean","path","route","RoutePlugin","onPost","onOptions","_","reply","status","headers","send","hijack","request","contextCacheKey","createGraphQLSchema","ex","console","result","processRequestBody","debugPlugins"],"sources":["createGraphQLHandler.ts"],"sourcesContent":["import { boolean } from \"boolean\";\nimport { GraphQLSchema } from \"graphql\";\nimport { RoutePlugin } from \"@webiny/handler\";\nimport WebinyError from \"@webiny/error\";\nimport { PluginCollection } from \"@webiny/plugins/types\";\nimport { GraphQLRequestBody, HandlerGraphQLOptions } from \"./types\";\nimport { createGraphQLSchema, getSchemaPlugins } from \"./createGraphQLSchema\";\nimport debugPlugins from \"./debugPlugins\";\nimport processRequestBody from \"./processRequestBody\";\nimport { Context } from \"@webiny/handler\";\n\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\n\nconst createCacheKey = (context: Context) => {\n const plugins = getSchemaPlugins(context);\n // TODO: in the near future, we have to assign a fixed name to every GraphQLSchema plugin,\n // to be able to create a reliable cache key.\n return plugins.length.toString();\n};\n\nconst createRequestBody = (body: unknown): GraphQLRequestBody | GraphQLRequestBody[] => {\n /**\n * We are trusting that the body payload is correct.\n * The `processRequestBody` will fail if it is not.\n */\n return typeof body === \"string\" ? JSON.parse(body) : body;\n};\n\nconst formatErrorPayload = (error: Error): string => {\n if (error instanceof WebinyError) {\n return JSON.stringify({\n type: \"CoreGraphQLWebinyError\",\n message: error.message,\n code: error.code,\n data: error.data\n });\n }\n\n return JSON.stringify({\n type: \"Error\",\n name: error.name,\n message: error.message,\n stack: error.stack\n });\n};\n\nexport default (options: HandlerGraphQLOptions = {}): PluginCollection => {\n let schema: GraphQLSchema | undefined = undefined;\n let cacheKey: string | undefined = undefined;\n\n const debug = boolean(options.debug);\n\n const path = options?.path || \"/graphql\";\n\n const route = new RoutePlugin(async ({ onPost, onOptions, context }) => {\n onOptions(path, async (_, reply) => {\n return reply\n .status(204)\n .headers({\n \"Cache-Control\": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`\n })\n .send({})\n .hijack();\n });\n onPost(path, async (request, reply) => {\n const contextCacheKey = createCacheKey(context as Context);\n if (!schema || cacheKey !== contextCacheKey) {\n try {\n schema = createGraphQLSchema(context);\n cacheKey = contextCacheKey;\n } catch (ex) {\n return reply.code(500).send(formatErrorPayload(ex));\n }\n }\n let body: GraphQLRequestBody | GraphQLRequestBody[];\n try {\n body = createRequestBody(request.body);\n } catch (ex) {\n console.error(`Error while creating the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n try {\n const result = await processRequestBody(body, schema, context);\n return reply.status(200).send(result);\n } catch (ex) {\n console.error(`Error while processing the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n });\n });\n\n route.name = \"handler.graphql.route.default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,KAAK,CAACC,MAAM,CAAC,GAAG,CAAC,CAACE,IAAI,CAACO,MAAM,CAAC;MACzC,CAAC,CAAC,OAAOF,EAAE,EAAE;QACTC,OAAO,CAAC9B,KAAK,CAAE,0CAAyC,CAAC;QACzD8B,OAAO,CAAC9B,KAAK,CAACD,kBAAkB,CAAC8B,EAAE,CAAC,CAAC;QACrC,MAAMA,EAAE;MACZ;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEFb,KAAK,CAACT,IAAI,GAAG,+BAA+B;EAE5C,OAAO,CACH,IAAIM,KAAK,GAAG,IAAAoB,qBAAY,GAAE,GAAG,EAAE,CAAC,EAChC;IACI9B,IAAI,EAAE;EACV,CAAC,EACDa,KAAK,CACR;AACL,CAAC;AAAA"}
|
package/createGraphQLSchema.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare const
|
|
1
|
+
import { GraphQLSchemaPlugin } from "./types";
|
|
2
|
+
import { Context } from "@webiny/api/types";
|
|
3
|
+
export declare const getSchemaPlugins: (context: Context) => GraphQLSchemaPlugin<Context>[];
|
|
4
|
+
export declare const createGraphQLSchema: (context: Context) => import("graphql").GraphQLSchema;
|
package/createGraphQLSchema.js
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.createGraphQLSchema = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
7
|
+
exports.getSchemaPlugins = exports.createGraphQLSchema = void 0;
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
12
9
|
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
13
|
-
|
|
14
10
|
var _schema = require("@graphql-tools/schema");
|
|
15
|
-
|
|
16
11
|
var _builtInTypes = require("./builtInTypes");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
const getSchemaPlugins = context => {
|
|
13
|
+
return context.plugins.byType("graphql-schema");
|
|
14
|
+
};
|
|
15
|
+
exports.getSchemaPlugins = getSchemaPlugins;
|
|
22
16
|
const createGraphQLSchema = context => {
|
|
23
17
|
const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar);
|
|
18
|
+
|
|
19
|
+
// TODO: once the API packages more closed, we'll have the opportunity
|
|
20
|
+
// TODO: to maybe import the @ps directive from `api-prerendering-service` package.
|
|
24
21
|
const typeDefs = [(0, _graphqlTag.default)`
|
|
25
22
|
type Query
|
|
26
23
|
type Mutation
|
|
@@ -33,33 +30,40 @@ const createGraphQLSchema = context => {
|
|
|
33
30
|
scalar Date
|
|
34
31
|
scalar DateTime
|
|
35
32
|
scalar Time
|
|
33
|
+
|
|
34
|
+
# This directive doesn't do anything on the GraphQL resolution level. It just serves
|
|
35
|
+
# as a way to tell the Prerendering Service whether the GraphQL query needs to be
|
|
36
|
+
# cached or not.
|
|
37
|
+
directive @ps(cache: Boolean) on QUERY
|
|
36
38
|
`];
|
|
37
|
-
const resolvers = [
|
|
39
|
+
const resolvers = [(0, _objectSpread2.default)((0, _objectSpread2.default)({}, scalars.reduce((acc, s) => {
|
|
38
40
|
acc[s.name] = s;
|
|
39
41
|
return acc;
|
|
40
42
|
}, {})), {}, {
|
|
41
43
|
JSON: _builtInTypes.JsonScalar,
|
|
42
44
|
Long: _builtInTypes.LongScalar,
|
|
43
|
-
RefInput: _builtInTypes.
|
|
44
|
-
Number: _builtInTypes.
|
|
45
|
-
Any: _builtInTypes.
|
|
45
|
+
RefInput: _builtInTypes.RefInputScalar,
|
|
46
|
+
Number: _builtInTypes.NumberScalar,
|
|
47
|
+
Any: _builtInTypes.AnyScalar,
|
|
46
48
|
DateTime: _builtInTypes.DateTimeScalar,
|
|
47
49
|
Date: _builtInTypes.DateScalar,
|
|
48
50
|
Time: _builtInTypes.TimeScalar
|
|
49
51
|
})];
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
const plugins = getSchemaPlugins(context);
|
|
53
|
+
for (const plugin of plugins) {
|
|
54
|
+
/**
|
|
55
|
+
* TODO @ts-refactor
|
|
56
|
+
* Figure out correct types on typeDefs and resolvers
|
|
57
|
+
*/
|
|
58
|
+
// @ts-ignore
|
|
54
59
|
typeDefs.push(plugin.schema.typeDefs);
|
|
60
|
+
// @ts-ignore
|
|
55
61
|
resolvers.push(plugin.schema.resolvers);
|
|
56
62
|
}
|
|
57
|
-
|
|
58
63
|
return (0, _schema.makeExecutableSchema)({
|
|
59
64
|
typeDefs,
|
|
60
65
|
resolvers,
|
|
61
66
|
inheritResolversFromInterfaces: true
|
|
62
67
|
});
|
|
63
68
|
};
|
|
64
|
-
|
|
65
69
|
exports.createGraphQLSchema = createGraphQLSchema;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getSchemaPlugins","context","plugins","byType","createGraphQLSchema","scalars","map","item","scalar","typeDefs","gql","name","join","resolvers","reduce","acc","s","JSON","JsonScalar","Long","LongScalar","RefInput","RefInputScalar","Number","NumberScalar","Any","AnyScalar","DateTime","DateTimeScalar","Date","DateScalar","Time","TimeScalar","plugin","push","schema","makeExecutableSchema","inheritResolversFromInterfaces"],"sources":["createGraphQLSchema.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport { makeExecutableSchema } from \"@graphql-tools/schema\";\nimport { GraphQLScalarPlugin, GraphQLSchemaPlugin } from \"./types\";\nimport { Context } from \"@webiny/api/types\";\nimport {\n RefInputScalar,\n NumberScalar,\n AnyScalar,\n DateScalar,\n DateTimeScalar,\n JsonScalar,\n TimeScalar,\n LongScalar\n} from \"./builtInTypes\";\nimport { GraphQLScalarType } from \"graphql/type/definition\";\n\nexport const getSchemaPlugins = (context: Context) => {\n return context.plugins.byType<GraphQLSchemaPlugin>(\"graphql-schema\");\n};\n\nexport const createGraphQLSchema = (context: Context) => {\n const scalars = context.plugins\n .byType<GraphQLScalarPlugin>(\"graphql-scalar\")\n .map(item => item.scalar);\n\n // TODO: once the API packages more closed, we'll have the opportunity\n // TODO: to maybe import the @ps directive from `api-prerendering-service` package.\n const typeDefs = [\n gql`\n type Query\n type Mutation\n ${scalars.map(scalar => `scalar ${scalar.name}`).join(\" \")}\n scalar JSON\n scalar Long\n scalar RefInput\n scalar Number\n scalar Any\n scalar Date\n scalar DateTime\n scalar Time\n\n # This directive doesn't do anything on the GraphQL resolution level. It just serves\n # as a way to tell the Prerendering Service whether the GraphQL query needs to be\n # cached or not.\n directive @ps(cache: Boolean) on QUERY\n `\n ];\n\n const resolvers = [\n {\n ...scalars.reduce<Record<string, GraphQLScalarType>>((acc, s) => {\n acc[s.name] = s;\n return acc;\n }, {}),\n JSON: JsonScalar,\n Long: LongScalar,\n RefInput: RefInputScalar,\n Number: NumberScalar,\n Any: AnyScalar,\n DateTime: DateTimeScalar,\n Date: DateScalar,\n Time: TimeScalar\n }\n ];\n\n const plugins = getSchemaPlugins(context);\n for (const plugin of plugins) {\n /**\n * TODO @ts-refactor\n * Figure out correct types on typeDefs and resolvers\n */\n // @ts-ignore\n typeDefs.push(plugin.schema.typeDefs);\n // @ts-ignore\n resolvers.push(plugin.schema.resolvers);\n }\n\n return makeExecutableSchema({\n typeDefs,\n resolvers,\n inheritResolversFromInterfaces: true\n });\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AAGA;AAYO,MAAMA,gBAAgB,GAAIC,OAAgB,IAAK;EAClD,OAAOA,OAAO,CAACC,OAAO,CAACC,MAAM,CAAsB,gBAAgB,CAAC;AACxE,CAAC;AAAC;AAE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B,EAAE;EACpC,CAAC,CAAC;AACN,CAAC;AAAC"}
|
package/debugPlugins.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { GraphQLAfterQueryPlugin
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { GraphQLAfterQueryPlugin } from "./types";
|
|
2
|
+
import { Context } from "@webiny/api/types";
|
|
3
|
+
import { ContextPlugin } from "@webiny/api";
|
|
4
|
+
interface Log {
|
|
5
|
+
method: string;
|
|
6
|
+
args: any;
|
|
7
|
+
}
|
|
8
|
+
interface DebugContext extends Context {
|
|
4
9
|
debug: {
|
|
5
|
-
logs?:
|
|
6
|
-
method: string;
|
|
7
|
-
args: any;
|
|
8
|
-
}[];
|
|
10
|
+
logs?: Log[];
|
|
9
11
|
};
|
|
10
12
|
}
|
|
11
|
-
declare const _default: () => (ContextPlugin<DebugContext
|
|
13
|
+
declare const _default: () => (ContextPlugin<DebugContext> | GraphQLAfterQueryPlugin<DebugContext>)[];
|
|
12
14
|
export default _default;
|
package/debugPlugins.js
CHANGED
|
@@ -4,45 +4,33 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _interceptConsole = require("./interceptConsole");
|
|
9
|
-
|
|
10
|
-
var _default = () => [{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
apply(context) {
|
|
14
|
-
context.debug = context.debug || {};
|
|
15
|
-
context.debug.logs = [];
|
|
16
|
-
(0, _interceptConsole.interceptConsole)((method, args) => {
|
|
17
|
-
context.debug.logs.push({
|
|
18
|
-
method,
|
|
19
|
-
args
|
|
20
|
-
});
|
|
21
|
-
});
|
|
8
|
+
var _api = require("@webiny/api");
|
|
9
|
+
var _default = () => [new _api.ContextPlugin(async context => {
|
|
10
|
+
if (!context.debug) {
|
|
11
|
+
context.debug = {};
|
|
22
12
|
}
|
|
23
|
-
|
|
24
|
-
}, {
|
|
25
|
-
type: "graphql-before-query",
|
|
26
|
-
|
|
27
|
-
apply({
|
|
28
|
-
context
|
|
29
|
-
}) {
|
|
30
|
-
// Empty logs
|
|
13
|
+
if (!context.debug.logs) {
|
|
31
14
|
context.debug.logs = [];
|
|
32
15
|
}
|
|
33
|
-
|
|
34
|
-
|
|
16
|
+
(0, _interceptConsole.interceptConsole)((method, args) => {
|
|
17
|
+
context.debug.logs.push({
|
|
18
|
+
method,
|
|
19
|
+
args
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}), {
|
|
35
23
|
type: "graphql-after-query",
|
|
36
|
-
|
|
37
24
|
apply({
|
|
38
25
|
result,
|
|
39
26
|
context
|
|
40
27
|
}) {
|
|
41
28
|
result["extensions"] = {
|
|
42
|
-
console: context.debug.logs || []
|
|
29
|
+
console: [...(context.debug.logs || [])]
|
|
43
30
|
};
|
|
31
|
+
if (context.debug.logs) {
|
|
32
|
+
context.debug.logs.length = 0;
|
|
33
|
+
}
|
|
44
34
|
}
|
|
45
|
-
|
|
46
35
|
}];
|
|
47
|
-
|
|
48
36
|
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ContextPlugin","context","debug","logs","interceptConsole","method","args","push","type","apply","result","console","length"],"sources":["debugPlugins.ts"],"sourcesContent":["import { interceptConsole } from \"./interceptConsole\";\nimport { GraphQLAfterQueryPlugin } from \"./types\";\nimport { Context } from \"@webiny/api/types\";\nimport { ContextPlugin } from \"@webiny/api\";\n\ninterface Log {\n method: string;\n args: any;\n}\ninterface DebugContext extends Context {\n debug: {\n logs?: Log[];\n };\n}\n\nexport default () => [\n new ContextPlugin<DebugContext>(async context => {\n if (!context.debug) {\n context.debug = {};\n }\n\n if (!context.debug.logs) {\n context.debug.logs = [];\n }\n\n interceptConsole((method, args) => {\n (context.debug.logs as Log[]).push({ method, args });\n });\n }),\n {\n type: \"graphql-after-query\",\n apply({ result, context }) {\n result[\"extensions\"] = { console: [...(context.debug.logs || [])] };\n if (context.debug.logs) {\n context.debug.logs.length = 0;\n }\n }\n } as GraphQLAfterQueryPlugin<DebugContext>\n];\n"],"mappings":";;;;;;AAAA;AAGA;AAA4C,eAY7B,MAAM,CACjB,IAAIA,kBAAa,CAAe,MAAMC,OAAO,IAAI;EAC7C,IAAI,CAACA,OAAO,CAACC,KAAK,EAAE;IAChBD,OAAO,CAACC,KAAK,GAAG,CAAC,CAAC;EACtB;EAEA,IAAI,CAACD,OAAO,CAACC,KAAK,CAACC,IAAI,EAAE;IACrBF,OAAO,CAACC,KAAK,CAACC,IAAI,GAAG,EAAE;EAC3B;EAEA,IAAAC,kCAAgB,EAAC,CAACC,MAAM,EAAEC,IAAI,KAAK;IAC9BL,OAAO,CAACC,KAAK,CAACC,IAAI,CAAWI,IAAI,CAAC;MAAEF,MAAM;MAAEC;IAAK,CAAC,CAAC;EACxD,CAAC,CAAC;AACN,CAAC,CAAC,EACF;EACIE,IAAI,EAAE,qBAAqB;EAC3BC,KAAK,CAAC;IAAEC,MAAM;IAAET;EAAQ,CAAC,EAAE;IACvBS,MAAM,CAAC,YAAY,CAAC,GAAG;MAAEC,OAAO,EAAE,CAAC,IAAIV,OAAO,CAACC,KAAK,CAACC,IAAI,IAAI,EAAE,CAAC;IAAE,CAAC;IACnE,IAAIF,OAAO,CAACC,KAAK,CAACC,IAAI,EAAE;MACpBF,OAAO,CAACC,KAAK,CAACC,IAAI,CAACS,MAAM,GAAG,CAAC;IACjC;EACJ;AACJ,CAAC,CACJ;AAAA"}
|
package/errors.d.ts
CHANGED
package/errors.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.NotFoundError = void 0;
|
|
9
|
-
|
|
10
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
-
|
|
12
9
|
class NotFoundError extends _error.default {
|
|
13
10
|
constructor(message = "Not found.") {
|
|
14
11
|
super(message, "NOT_FOUND");
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
}
|
|
18
|
-
|
|
19
14
|
exports.NotFoundError = NotFoundError;
|
package/errors.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NotFoundError","WebinyError","constructor","message"],"sources":["errors.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\n\nexport class NotFoundError extends WebinyError {\n constructor(message = \"Not found.\") {\n super(message, \"NOT_FOUND\");\n }\n}\n"],"mappings":";;;;;;;AAAA;AAEO,MAAMA,aAAa,SAASC,cAAW,CAAC;EAC3CC,WAAW,CAACC,OAAO,GAAG,YAAY,EAAE;IAChC,KAAK,CAACA,OAAO,EAAE,WAAW,CAAC;EAC/B;AACJ;AAAC"}
|
package/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { HandlerGraphQLOptions } from "./types";
|
|
2
|
-
import { Context } from "@webiny/handler/types";
|
|
3
|
-
import { GraphQLFieldResolver } from "./types";
|
|
4
2
|
export * from "./errors";
|
|
5
3
|
export * from "./responses";
|
|
4
|
+
export * from "./plugins";
|
|
5
|
+
export { default as processRequestBody } from "./processRequestBody";
|
|
6
6
|
declare const _default: (options?: HandlerGraphQLOptions) => import("@webiny/plugins/types").PluginCollection[];
|
|
7
7
|
export default _default;
|
|
8
|
-
export declare const pipe: <TSource = any, TArgs = Record<string, any>, TContext = Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>>(...fns: any[]) => (resolver: import("graphql").GraphQLFieldResolver<TSource, TContext, TArgs>) => any;
|
|
9
|
-
export declare const compose: <TSource = any, TArgs = Record<string, any>, TContext = Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>>(...fns: any[]) => (resolver: import("graphql").GraphQLFieldResolver<TSource, TContext, TArgs>) => any;
|
package/index.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
var _exportNames = {
|
|
9
|
-
|
|
10
|
-
compose: true
|
|
8
|
+
processRequestBody: true
|
|
11
9
|
};
|
|
12
|
-
exports.
|
|
13
|
-
|
|
10
|
+
exports.default = void 0;
|
|
11
|
+
Object.defineProperty(exports, "processRequestBody", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () {
|
|
14
|
+
return _processRequestBody.default;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
14
17
|
var _createGraphQLHandler = _interopRequireDefault(require("./createGraphQLHandler"));
|
|
15
|
-
|
|
16
18
|
var _errors = require("./errors");
|
|
17
|
-
|
|
18
19
|
Object.keys(_errors).forEach(function (key) {
|
|
19
20
|
if (key === "default" || key === "__esModule") return;
|
|
20
21
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -26,9 +27,7 @@ Object.keys(_errors).forEach(function (key) {
|
|
|
26
27
|
}
|
|
27
28
|
});
|
|
28
29
|
});
|
|
29
|
-
|
|
30
30
|
var _responses = require("./responses");
|
|
31
|
-
|
|
32
31
|
Object.keys(_responses).forEach(function (key) {
|
|
33
32
|
if (key === "default" || key === "__esModule") return;
|
|
34
33
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -40,15 +39,18 @@ Object.keys(_responses).forEach(function (key) {
|
|
|
40
39
|
}
|
|
41
40
|
});
|
|
42
41
|
});
|
|
43
|
-
|
|
42
|
+
var _plugins = require("./plugins");
|
|
43
|
+
Object.keys(_plugins).forEach(function (key) {
|
|
44
|
+
if (key === "default" || key === "__esModule") return;
|
|
45
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
46
|
+
if (key in exports && exports[key] === _plugins[key]) return;
|
|
47
|
+
Object.defineProperty(exports, key, {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
get: function () {
|
|
50
|
+
return _plugins[key];
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
var _processRequestBody = _interopRequireDefault(require("./processRequestBody"));
|
|
44
55
|
var _default = (options = {}) => [(0, _createGraphQLHandler.default)(options)];
|
|
45
|
-
|
|
46
|
-
exports.default = _default;
|
|
47
|
-
|
|
48
|
-
const pipe = (...fns) => resolver => fns.reduce((v, f) => f(v), resolver);
|
|
49
|
-
|
|
50
|
-
exports.pipe = pipe;
|
|
51
|
-
|
|
52
|
-
const compose = (...fns) => resolver => fns.reduceRight((v, f) => f(v), resolver);
|
|
53
|
-
|
|
54
|
-
exports.compose = compose;
|
|
56
|
+
exports.default = _default;
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["options","createGraphQLHandler"],"sources":["index.ts"],"sourcesContent":["import { HandlerGraphQLOptions } from \"./types\";\nimport createGraphQLHandler from \"./createGraphQLHandler\";\n\nexport * from \"./errors\";\nexport * from \"./responses\";\nexport * from \"./plugins\";\nexport { default as processRequestBody } from \"./processRequestBody\";\n\nexport default (options: HandlerGraphQLOptions = {}) => [createGraphQLHandler(options)];\n"],"mappings":";;;;;;;;;;;;;;;;AACA;AAEA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAqE,eAEtD,CAACA,OAA8B,GAAG,CAAC,CAAC,KAAK,CAAC,IAAAC,6BAAoB,EAACD,OAAO,CAAC,CAAC;AAAA"}
|
package/interceptConsole.d.ts
CHANGED
package/interceptConsole.js
CHANGED
|
@@ -7,33 +7,31 @@ exports.interceptConsole = void 0;
|
|
|
7
7
|
const consoleMethods = ["assert", "debug", "dir", "error", "group", "groupCollapsed", "groupEnd", "info", "log", "table", "warn"];
|
|
8
8
|
const originalMethods = {};
|
|
9
9
|
const skipOriginal = ["table"];
|
|
10
|
-
|
|
11
10
|
const restoreOriginalMethods = () => {
|
|
12
11
|
for (const method of consoleMethods) {
|
|
12
|
+
// @ts-ignore
|
|
13
13
|
console[method] = originalMethods[method];
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
|
|
17
16
|
const interceptConsole = callback => {
|
|
17
|
+
// @ts-ignore
|
|
18
18
|
if (console["__WEBINY__"] === true) {
|
|
19
19
|
restoreOriginalMethods();
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
// @ts-ignore
|
|
22
23
|
console["__WEBINY__"] = true;
|
|
23
|
-
|
|
24
24
|
for (const method of consoleMethods) {
|
|
25
|
+
// @ts-ignore
|
|
25
26
|
originalMethods[method] = console[method];
|
|
26
|
-
|
|
27
|
+
// @ts-ignore
|
|
27
28
|
console[method] = (...args) => {
|
|
28
29
|
callback(method, args);
|
|
29
|
-
|
|
30
30
|
if (skipOriginal.includes(method)) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
|
|
34
33
|
originalMethods[method](...args);
|
|
35
34
|
};
|
|
36
35
|
}
|
|
37
36
|
};
|
|
38
|
-
|
|
39
37
|
exports.interceptConsole = interceptConsole;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["consoleMethods","originalMethods","skipOriginal","restoreOriginalMethods","method","console","interceptConsole","callback","args","includes"],"sources":["interceptConsole.ts"],"sourcesContent":["const consoleMethods = [\n \"assert\",\n \"debug\",\n \"dir\",\n \"error\",\n \"group\",\n \"groupCollapsed\",\n \"groupEnd\",\n \"info\",\n \"log\",\n \"table\",\n \"warn\"\n];\n\nconst originalMethods: Record<string, any> = {};\nconst skipOriginal: string[] = [\"table\"];\n\nconst restoreOriginalMethods = () => {\n for (const method of consoleMethods) {\n // @ts-ignore\n console[method] = originalMethods[method];\n }\n};\n\ninterface InterceptConsoleCallable {\n (method: string, args: any[]): void;\n}\n\nexport const interceptConsole = (callback: InterceptConsoleCallable) => {\n // @ts-ignore\n if (console[\"__WEBINY__\"] === true) {\n restoreOriginalMethods();\n }\n\n // @ts-ignore\n console[\"__WEBINY__\"] = true;\n\n for (const method of consoleMethods) {\n // @ts-ignore\n originalMethods[method] = console[method];\n // @ts-ignore\n console[method] = (...args) => {\n callback(method, args);\n if (skipOriginal.includes(method)) {\n return;\n }\n originalMethods[method](...args);\n };\n }\n};\n"],"mappings":";;;;;;AAAA,MAAMA,cAAc,GAAG,CACnB,QAAQ,EACR,OAAO,EACP,KAAK,EACL,OAAO,EACP,OAAO,EACP,gBAAgB,EAChB,UAAU,EACV,MAAM,EACN,KAAK,EACL,OAAO,EACP,MAAM,CACT;AAED,MAAMC,eAAoC,GAAG,CAAC,CAAC;AAC/C,MAAMC,YAAsB,GAAG,CAAC,OAAO,CAAC;AAExC,MAAMC,sBAAsB,GAAG,MAAM;EACjC,KAAK,MAAMC,MAAM,IAAIJ,cAAc,EAAE;IACjC;IACAK,OAAO,CAACD,MAAM,CAAC,GAAGH,eAAe,CAACG,MAAM,CAAC;EAC7C;AACJ,CAAC;AAMM,MAAME,gBAAgB,GAAIC,QAAkC,IAAK;EACpE;EACA,IAAIF,OAAO,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE;IAChCF,sBAAsB,EAAE;EAC5B;;EAEA;EACAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;EAE5B,KAAK,MAAMD,MAAM,IAAIJ,cAAc,EAAE;IACjC;IACAC,eAAe,CAACG,MAAM,CAAC,GAAGC,OAAO,CAACD,MAAM,CAAC;IACzC;IACAC,OAAO,CAACD,MAAM,CAAC,GAAG,CAAC,GAAGI,IAAI,KAAK;MAC3BD,QAAQ,CAACH,MAAM,EAAEI,IAAI,CAAC;MACtB,IAAIN,YAAY,CAACO,QAAQ,CAACL,MAAM,CAAC,EAAE;QAC/B;MACJ;MACAH,eAAe,CAACG,MAAM,CAAC,CAAC,GAAGI,IAAI,CAAC;IACpC,CAAC;EACL;AACJ,CAAC;AAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler-graphql",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-unstable.085ff6572f",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -14,28 +14,29 @@
|
|
|
14
14
|
"Adrian Smijulj <adrian@webiny.com>"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@babel/runtime": "7.
|
|
17
|
+
"@babel/runtime": "7.20.13",
|
|
18
18
|
"@graphql-tools/schema": "7.1.5",
|
|
19
|
-
"@webiny/
|
|
20
|
-
"@webiny/
|
|
21
|
-
"@webiny/handler
|
|
22
|
-
"@webiny/plugins": "0.0.0-
|
|
23
|
-
"boolean": "3.
|
|
24
|
-
"graphql": "
|
|
19
|
+
"@webiny/api": "0.0.0-unstable.085ff6572f",
|
|
20
|
+
"@webiny/error": "0.0.0-unstable.085ff6572f",
|
|
21
|
+
"@webiny/handler": "0.0.0-unstable.085ff6572f",
|
|
22
|
+
"@webiny/plugins": "0.0.0-unstable.085ff6572f",
|
|
23
|
+
"boolean": "3.2.0",
|
|
24
|
+
"graphql": "15.8.0",
|
|
25
25
|
"graphql-scalars": "1.12.0",
|
|
26
|
-
"graphql-tag": "2.12.
|
|
26
|
+
"graphql-tag": "2.12.6"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@babel/cli": "
|
|
30
|
-
"@babel/core": "
|
|
31
|
-
"@babel/preset-env": "
|
|
32
|
-
"@webiny/cli": "
|
|
33
|
-
"@webiny/handler-
|
|
34
|
-
"@webiny/project-utils": "
|
|
35
|
-
"jest": "
|
|
36
|
-
"jest-mock-console": "
|
|
37
|
-
"rimraf": "
|
|
38
|
-
"
|
|
29
|
+
"@babel/cli": "7.20.7",
|
|
30
|
+
"@babel/core": "7.20.12",
|
|
31
|
+
"@babel/preset-env": "7.20.2",
|
|
32
|
+
"@webiny/cli": "0.0.0-unstable.085ff6572f",
|
|
33
|
+
"@webiny/handler-aws": "0.0.0-unstable.085ff6572f",
|
|
34
|
+
"@webiny/project-utils": "0.0.0-unstable.085ff6572f",
|
|
35
|
+
"jest": "29.5.0",
|
|
36
|
+
"jest-mock-console": "1.3.0",
|
|
37
|
+
"rimraf": "3.0.2",
|
|
38
|
+
"ttypescript": "1.5.15",
|
|
39
|
+
"typescript": "4.7.4"
|
|
39
40
|
},
|
|
40
41
|
"publishConfig": {
|
|
41
42
|
"access": "public",
|
|
@@ -45,5 +46,5 @@
|
|
|
45
46
|
"build": "yarn webiny run build",
|
|
46
47
|
"watch": "yarn webiny run watch"
|
|
47
48
|
},
|
|
48
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "085ff6572f6bb6a76d218088b06d9f4ef92bbea7"
|
|
49
50
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
2
|
import { GraphQLSchemaDefinition, Resolvers, Types } from "../types";
|
|
3
|
-
import { Context } from "@webiny/
|
|
3
|
+
import { Context } from "@webiny/api/types";
|
|
4
4
|
export interface GraphQLSchemaPluginConfig<TContext> {
|
|
5
5
|
typeDefs?: Types;
|
|
6
6
|
resolvers?: Resolvers<TContext>;
|
|
7
7
|
}
|
|
8
8
|
export declare class GraphQLSchemaPlugin<TContext = Context> extends Plugin {
|
|
9
|
-
static readonly type
|
|
9
|
+
static readonly type: string;
|
|
10
10
|
private config;
|
|
11
11
|
constructor(config: GraphQLSchemaPluginConfig<TContext>);
|
|
12
12
|
get schema(): GraphQLSchemaDefinition<TContext>;
|