@webiny/handler-graphql 0.0.0-mt-1

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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -0
  3. package/builtInTypes/AnyScalar.d.ts +2 -0
  4. package/builtInTypes/AnyScalar.js +20 -0
  5. package/builtInTypes/DateScalar.d.ts +2 -0
  6. package/builtInTypes/DateScalar.js +38 -0
  7. package/builtInTypes/DateTimeScalar.d.ts +2 -0
  8. package/builtInTypes/DateTimeScalar.js +38 -0
  9. package/builtInTypes/DateTimeZScalar.d.ts +6 -0
  10. package/builtInTypes/DateTimeZScalar.js +63 -0
  11. package/builtInTypes/JsonScalar.d.ts +1 -0
  12. package/builtInTypes/JsonScalar.js +11 -0
  13. package/builtInTypes/LongScalar.d.ts +1 -0
  14. package/builtInTypes/LongScalar.js +11 -0
  15. package/builtInTypes/NumberScalar.d.ts +2 -0
  16. package/builtInTypes/NumberScalar.js +60 -0
  17. package/builtInTypes/RefInputScalar.d.ts +2 -0
  18. package/builtInTypes/RefInputScalar.js +65 -0
  19. package/builtInTypes/TimeScalar.d.ts +2 -0
  20. package/builtInTypes/TimeScalar.js +71 -0
  21. package/builtInTypes/index.d.ts +9 -0
  22. package/builtInTypes/index.js +122 -0
  23. package/createGraphQLHandler.d.ts +4 -0
  24. package/createGraphQLHandler.js +77 -0
  25. package/createGraphQLSchema.d.ts +3 -0
  26. package/createGraphQLSchema.js +65 -0
  27. package/debugPlugins.d.ts +12 -0
  28. package/debugPlugins.js +48 -0
  29. package/errors.d.ts +4 -0
  30. package/errors.js +19 -0
  31. package/index.d.ts +9 -0
  32. package/index.js +54 -0
  33. package/interceptConsole.d.ts +1 -0
  34. package/interceptConsole.js +39 -0
  35. package/package.json +49 -0
  36. package/plugins/GraphQLSchemaPlugin.d.ts +13 -0
  37. package/plugins/GraphQLSchemaPlugin.js +31 -0
  38. package/plugins/index.d.ts +1 -0
  39. package/plugins/index.js +18 -0
  40. package/processRequestBody.d.ts +2 -0
  41. package/processRequestBody.js +49 -0
  42. package/responses.d.ts +39 -0
  43. package/responses.js +88 -0
  44. package/types.d.ts +50 -0
  45. package/types.js +5 -0
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createGraphQLSchema = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
13
+
14
+ var _schema = require("@graphql-tools/schema");
15
+
16
+ var _builtInTypes = require("./builtInTypes");
17
+
18
+ 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; }
19
+
20
+ 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; }
21
+
22
+ const createGraphQLSchema = context => {
23
+ const scalars = context.plugins.byType("graphql-scalar").map(item => item.scalar);
24
+ const typeDefs = [(0, _graphqlTag.default)`
25
+ type Query
26
+ type Mutation
27
+ ${scalars.map(scalar => `scalar ${scalar.name}`).join(" ")}
28
+ scalar JSON
29
+ scalar Long
30
+ scalar RefInput
31
+ scalar Number
32
+ scalar Any
33
+ scalar Date
34
+ scalar DateTime
35
+ scalar Time
36
+ `];
37
+ const resolvers = [_objectSpread(_objectSpread({}, scalars.reduce((acc, s) => {
38
+ acc[s.name] = s;
39
+ return acc;
40
+ }, {})), {}, {
41
+ JSON: _builtInTypes.JsonScalar,
42
+ Long: _builtInTypes.LongScalar,
43
+ RefInput: _builtInTypes.RefInput,
44
+ Number: _builtInTypes.Number,
45
+ Any: _builtInTypes.Any,
46
+ DateTime: _builtInTypes.DateTimeScalar,
47
+ Date: _builtInTypes.DateScalar,
48
+ Time: _builtInTypes.TimeScalar
49
+ })];
50
+ const gqlPlugins = context.plugins.byType("graphql-schema");
51
+
52
+ for (let i = 0; i < gqlPlugins.length; i++) {
53
+ const plugin = gqlPlugins[i];
54
+ typeDefs.push(plugin.schema.typeDefs);
55
+ resolvers.push(plugin.schema.resolvers);
56
+ }
57
+
58
+ return (0, _schema.makeExecutableSchema)({
59
+ typeDefs,
60
+ resolvers,
61
+ inheritResolversFromInterfaces: true
62
+ });
63
+ };
64
+
65
+ exports.createGraphQLSchema = createGraphQLSchema;
@@ -0,0 +1,12 @@
1
+ import { GraphQLAfterQueryPlugin, GraphQLBeforeQueryPlugin } from "./types";
2
+ import { ContextInterface, ContextPlugin } from "@webiny/handler/types";
3
+ interface DebugContext extends ContextInterface {
4
+ debug: {
5
+ logs?: {
6
+ method: string;
7
+ args: any;
8
+ }[];
9
+ };
10
+ }
11
+ declare const _default: () => (ContextPlugin<DebugContext, import("@webiny/handler/types").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>>, import("@webiny/handler/types").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>>, import("@webiny/handler/types").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>>, import("@webiny/handler/types").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>>, import("@webiny/handler/types").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>>, import("@webiny/handler/types").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>>, import("@webiny/handler/types").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>>, import("@webiny/handler/types").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>>, import("@webiny/handler/types").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>>> | GraphQLBeforeQueryPlugin<DebugContext> | GraphQLAfterQueryPlugin<DebugContext>)[];
12
+ export default _default;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _interceptConsole = require("./interceptConsole");
9
+
10
+ var _default = () => [{
11
+ type: "context",
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
+ });
22
+ }
23
+
24
+ }, {
25
+ type: "graphql-before-query",
26
+
27
+ apply({
28
+ context
29
+ }) {
30
+ // Empty logs
31
+ context.debug.logs = [];
32
+ }
33
+
34
+ }, {
35
+ type: "graphql-after-query",
36
+
37
+ apply({
38
+ result,
39
+ context
40
+ }) {
41
+ result["extensions"] = {
42
+ console: context.debug.logs || []
43
+ };
44
+ }
45
+
46
+ }];
47
+
48
+ exports.default = _default;
package/errors.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import Error from "@webiny/error";
2
+ export declare class NotFoundError extends Error {
3
+ constructor(message?: string);
4
+ }
package/errors.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.NotFoundError = void 0;
9
+
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+
12
+ class NotFoundError extends _error.default {
13
+ constructor(message = "Not found.") {
14
+ super(message, "NOT_FOUND");
15
+ }
16
+
17
+ }
18
+
19
+ exports.NotFoundError = NotFoundError;
package/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { HandlerGraphQLOptions } from "./types";
2
+ import { Context } from "@webiny/handler/types";
3
+ import { GraphQLFieldResolver } from "./types";
4
+ export * from "./errors";
5
+ export * from "./responses";
6
+ declare const _default: (options?: HandlerGraphQLOptions) => import("@webiny/plugins/types").PluginCollection[];
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 ADDED
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ var _exportNames = {
9
+ pipe: true,
10
+ compose: true
11
+ };
12
+ exports.pipe = exports.default = exports.compose = void 0;
13
+
14
+ var _createGraphQLHandler = _interopRequireDefault(require("./createGraphQLHandler"));
15
+
16
+ var _errors = require("./errors");
17
+
18
+ Object.keys(_errors).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
21
+ if (key in exports && exports[key] === _errors[key]) return;
22
+ Object.defineProperty(exports, key, {
23
+ enumerable: true,
24
+ get: function () {
25
+ return _errors[key];
26
+ }
27
+ });
28
+ });
29
+
30
+ var _responses = require("./responses");
31
+
32
+ Object.keys(_responses).forEach(function (key) {
33
+ if (key === "default" || key === "__esModule") return;
34
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
35
+ if (key in exports && exports[key] === _responses[key]) return;
36
+ Object.defineProperty(exports, key, {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _responses[key];
40
+ }
41
+ });
42
+ });
43
+
44
+ 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;
@@ -0,0 +1 @@
1
+ export declare const interceptConsole: (callback: any) => void;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.interceptConsole = void 0;
7
+ const consoleMethods = ["assert", "debug", "dir", "error", "group", "groupCollapsed", "groupEnd", "info", "log", "table", "warn"];
8
+ const originalMethods = {};
9
+ const skipOriginal = ["table"];
10
+
11
+ const restoreOriginalMethods = () => {
12
+ for (const method of consoleMethods) {
13
+ console[method] = originalMethods[method];
14
+ }
15
+ };
16
+
17
+ const interceptConsole = callback => {
18
+ if (console["__WEBINY__"] === true) {
19
+ restoreOriginalMethods();
20
+ }
21
+
22
+ console["__WEBINY__"] = true;
23
+
24
+ for (const method of consoleMethods) {
25
+ originalMethods[method] = console[method];
26
+
27
+ console[method] = (...args) => {
28
+ callback(method, args);
29
+
30
+ if (skipOriginal.includes(method)) {
31
+ return;
32
+ }
33
+
34
+ originalMethods[method](...args);
35
+ };
36
+ }
37
+ };
38
+
39
+ exports.interceptConsole = interceptConsole;
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@webiny/handler-graphql",
3
+ "version": "0.0.0-mt-1",
4
+ "main": "index.js",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/webiny/webiny-js.git"
9
+ },
10
+ "description": "The Apollo Server as a function.",
11
+ "contributors": [
12
+ "Pavel Denisjuk <pavel@webiny.com>",
13
+ "Sven Al Hamad <sven@webiny.com>",
14
+ "Adrian Smijulj <adrian@webiny.com>"
15
+ ],
16
+ "dependencies": {
17
+ "@babel/runtime": "7.15.4",
18
+ "@graphql-tools/schema": "7.1.5",
19
+ "@webiny/error": "0.0.0-mt-1",
20
+ "@webiny/handler": "0.0.0-mt-1",
21
+ "@webiny/handler-http": "0.0.0-mt-1",
22
+ "@webiny/plugins": "0.0.0-mt-1",
23
+ "boolean": "3.1.4",
24
+ "graphql": "14.7.0",
25
+ "graphql-scalars": "1.12.0",
26
+ "graphql-tag": "2.12.5"
27
+ },
28
+ "devDependencies": {
29
+ "@babel/cli": "^7.5.5",
30
+ "@babel/core": "^7.5.5",
31
+ "@babel/preset-env": "^7.5.5",
32
+ "@webiny/cli": "^0.0.0-mt-1",
33
+ "@webiny/handler-args": "^0.0.0-mt-1",
34
+ "@webiny/project-utils": "^0.0.0-mt-1",
35
+ "jest": "^26.6.3",
36
+ "jest-mock-console": "^1.0.0",
37
+ "rimraf": "^3.0.2",
38
+ "typescript": "^4.1.3"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public",
42
+ "directory": "dist"
43
+ },
44
+ "scripts": {
45
+ "build": "yarn webiny run build",
46
+ "watch": "yarn webiny run watch"
47
+ },
48
+ "gitHead": "37736d8456a6ecb342a6c3645060bd9a3f2d4bb0"
49
+ }
@@ -0,0 +1,13 @@
1
+ import { Plugin } from "@webiny/plugins";
2
+ import { GraphQLSchemaDefinition, Resolvers, Types } from "../types";
3
+ import { Context } from "@webiny/handler/types";
4
+ export interface GraphQLSchemaPluginConfig<TContext> {
5
+ typeDefs?: Types;
6
+ resolvers?: Resolvers<TContext>;
7
+ }
8
+ export declare class GraphQLSchemaPlugin<TContext = Context> extends Plugin {
9
+ static readonly type = "graphql-schema";
10
+ private config;
11
+ constructor(config: GraphQLSchemaPluginConfig<TContext>);
12
+ get schema(): GraphQLSchemaDefinition<TContext>;
13
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.GraphQLSchemaPlugin = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _plugins = require("@webiny/plugins");
13
+
14
+ class GraphQLSchemaPlugin extends _plugins.Plugin {
15
+ constructor(config) {
16
+ super();
17
+ (0, _defineProperty2.default)(this, "config", void 0);
18
+ this.config = config;
19
+ }
20
+
21
+ get schema() {
22
+ return {
23
+ typeDefs: this.config.typeDefs || "",
24
+ resolvers: this.config.resolvers
25
+ };
26
+ }
27
+
28
+ }
29
+
30
+ exports.GraphQLSchemaPlugin = GraphQLSchemaPlugin;
31
+ (0, _defineProperty2.default)(GraphQLSchemaPlugin, "type", "graphql-schema");
@@ -0,0 +1 @@
1
+ export * from "./GraphQLSchemaPlugin";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _GraphQLSchemaPlugin = require("./GraphQLSchemaPlugin");
8
+
9
+ Object.keys(_GraphQLSchemaPlugin).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _GraphQLSchemaPlugin[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _GraphQLSchemaPlugin[key];
16
+ }
17
+ });
18
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: (requestBody: any, schema: any, context: any) => Promise<any>;
2
+ export default _default;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _graphql = require("graphql");
9
+
10
+ const processRequestBody = async (body, schema, context) => {
11
+ const {
12
+ query,
13
+ variables,
14
+ operationName
15
+ } = body;
16
+ context.plugins.byType("graphql-before-query").forEach(pl => pl.apply({
17
+ body,
18
+ schema,
19
+ context
20
+ }));
21
+ const result = await (0, _graphql.graphql)(schema, query, {}, context, variables, operationName);
22
+ context.plugins.byType("graphql-after-query").forEach(pl => {
23
+ pl.apply({
24
+ result,
25
+ body,
26
+ schema,
27
+ context
28
+ });
29
+ });
30
+ return result;
31
+ };
32
+
33
+ var _default = async (requestBody, schema, context) => {
34
+ let result;
35
+
36
+ if (Array.isArray(requestBody)) {
37
+ result = [];
38
+
39
+ for (let i = 0; i < requestBody.length; i++) {
40
+ result.push(await processRequestBody(requestBody[i], schema, context));
41
+ }
42
+ } else {
43
+ result = await processRequestBody(requestBody, schema, context);
44
+ }
45
+
46
+ return result;
47
+ };
48
+
49
+ exports.default = _default;
package/responses.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ declare type ErrorResponseParams = {
2
+ code?: string;
3
+ message?: string;
4
+ data?: any;
5
+ };
6
+ export declare class ErrorResponse {
7
+ data: any;
8
+ error: {
9
+ code: string;
10
+ message: string;
11
+ data?: any;
12
+ };
13
+ constructor(params: ErrorResponseParams);
14
+ }
15
+ export declare class NotFoundResponse extends ErrorResponse {
16
+ constructor(message: string);
17
+ }
18
+ export declare class ListErrorResponse {
19
+ data: null;
20
+ meta: null;
21
+ error: {
22
+ code: string;
23
+ message: string;
24
+ data?: any;
25
+ };
26
+ constructor(params: ErrorResponseParams);
27
+ }
28
+ export declare class Response<T extends any = any> {
29
+ data: T;
30
+ error: null;
31
+ constructor(data: T);
32
+ }
33
+ export declare class ListResponse<T extends any, M extends any> {
34
+ data: Array<T>;
35
+ meta: M;
36
+ error: null;
37
+ constructor(data: Array<T>, meta?: M);
38
+ }
39
+ export {};
package/responses.js ADDED
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.Response = exports.NotFoundResponse = exports.ListResponse = exports.ListErrorResponse = exports.ErrorResponse = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ const defaultParams = {
13
+ code: "",
14
+ message: "",
15
+ data: null
16
+ };
17
+
18
+ class ErrorResponse {
19
+ constructor(params) {
20
+ (0, _defineProperty2.default)(this, "data", void 0);
21
+ (0, _defineProperty2.default)(this, "error", void 0);
22
+ this.data = null;
23
+ this.error = {
24
+ code: params.code || defaultParams.code,
25
+ message: params.message || defaultParams.message,
26
+ data: params.data || defaultParams.data
27
+ };
28
+ }
29
+
30
+ }
31
+
32
+ exports.ErrorResponse = ErrorResponse;
33
+
34
+ class NotFoundResponse extends ErrorResponse {
35
+ constructor(message) {
36
+ super({
37
+ code: "NOT_FOUND",
38
+ message
39
+ });
40
+ }
41
+
42
+ }
43
+
44
+ exports.NotFoundResponse = NotFoundResponse;
45
+
46
+ class ListErrorResponse {
47
+ constructor(params) {
48
+ (0, _defineProperty2.default)(this, "data", void 0);
49
+ (0, _defineProperty2.default)(this, "meta", void 0);
50
+ (0, _defineProperty2.default)(this, "error", void 0);
51
+ this.data = null;
52
+ this.meta = null;
53
+ this.error = {
54
+ code: params.code || defaultParams.code,
55
+ message: params.message || defaultParams.message,
56
+ data: params.data || defaultParams.data
57
+ };
58
+ }
59
+
60
+ }
61
+
62
+ exports.ListErrorResponse = ListErrorResponse;
63
+
64
+ class Response {
65
+ constructor(data) {
66
+ (0, _defineProperty2.default)(this, "data", void 0);
67
+ (0, _defineProperty2.default)(this, "error", void 0);
68
+ this.data = data;
69
+ this.error = null;
70
+ }
71
+
72
+ }
73
+
74
+ exports.Response = Response;
75
+
76
+ class ListResponse {
77
+ constructor(data, meta) {
78
+ (0, _defineProperty2.default)(this, "data", void 0);
79
+ (0, _defineProperty2.default)(this, "meta", void 0);
80
+ (0, _defineProperty2.default)(this, "error", void 0);
81
+ this.data = Array.isArray(data) ? data : [];
82
+ this.meta = meta || {};
83
+ this.error = null;
84
+ }
85
+
86
+ }
87
+
88
+ exports.ListResponse = ListResponse;
package/types.d.ts ADDED
@@ -0,0 +1,50 @@
1
+ import { GraphQLScalarType, GraphQLFieldResolver as BaseGraphQLFieldResolver, GraphQLSchema } from "graphql";
2
+ import { Plugin } from "@webiny/plugins/types";
3
+ import { ContextInterface } from "@webiny/handler/types";
4
+ export interface GraphQLScalarPlugin extends Plugin {
5
+ type: "graphql-scalar";
6
+ scalar: GraphQLScalarType;
7
+ }
8
+ export interface HandlerGraphQLOptions {
9
+ debug?: boolean | string;
10
+ }
11
+ export declare type GraphQLFieldResolver<TSource = any, TArgs = any, TContext = ContextInterface> = BaseGraphQLFieldResolver<TSource, TContext, TArgs>;
12
+ export declare type Types = string | (() => string | Promise<string>);
13
+ export interface GraphQLSchemaPluginTypeArgs {
14
+ context?: any;
15
+ args?: any;
16
+ source?: any;
17
+ }
18
+ export declare type Resolvers<TContext> = GraphQLScalarType | GraphQLFieldResolver<any, Record<string, any>, TContext> | {
19
+ [property: string]: Resolvers<TContext>;
20
+ };
21
+ export interface GraphQLSchemaDefinition<TContext> {
22
+ typeDefs: Types;
23
+ resolvers?: Resolvers<TContext>;
24
+ }
25
+ export interface GraphQLSchemaPlugin<TContext extends ContextInterface = ContextInterface> extends Plugin {
26
+ type: "graphql-schema";
27
+ schema: GraphQLSchemaDefinition<TContext>;
28
+ }
29
+ export interface GraphQLRequestBody {
30
+ query: string;
31
+ variables: Record<string, any>;
32
+ operationName: string;
33
+ }
34
+ export interface GraphQLBeforeQueryPlugin<TContext extends ContextInterface = ContextInterface> extends Plugin {
35
+ type: "graphql-before-query";
36
+ apply(params: {
37
+ body: GraphQLRequestBody;
38
+ schema: GraphQLSchema;
39
+ context: TContext;
40
+ }): void;
41
+ }
42
+ export interface GraphQLAfterQueryPlugin<TContext extends ContextInterface = ContextInterface> extends Plugin {
43
+ type: "graphql-after-query";
44
+ apply(params: {
45
+ result: any;
46
+ body: GraphQLRequestBody;
47
+ schema: GraphQLSchema;
48
+ context: TContext;
49
+ }): void;
50
+ }
package/types.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });