@webiny/handler-graphql 0.0.0-ee-vpcs.549378cf03
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/LICENSE +21 -0
- package/README.md +7 -0
- package/builtInTypes/AnyScalar.d.ts +2 -0
- package/builtInTypes/AnyScalar.js +20 -0
- package/builtInTypes/AnyScalar.js.map +1 -0
- package/builtInTypes/DateScalar.d.ts +2 -0
- package/builtInTypes/DateScalar.js +34 -0
- package/builtInTypes/DateScalar.js.map +1 -0
- package/builtInTypes/DateTimeScalar.d.ts +2 -0
- package/builtInTypes/DateTimeScalar.js +34 -0
- package/builtInTypes/DateTimeScalar.js.map +1 -0
- package/builtInTypes/DateTimeZScalar.d.ts +6 -0
- package/builtInTypes/DateTimeZScalar.js +63 -0
- package/builtInTypes/DateTimeZScalar.js.map +1 -0
- package/builtInTypes/JsonScalar.d.ts +1 -0
- package/builtInTypes/JsonScalar.js +11 -0
- package/builtInTypes/JsonScalar.js.map +1 -0
- package/builtInTypes/LongScalar.d.ts +1 -0
- package/builtInTypes/LongScalar.js +11 -0
- package/builtInTypes/LongScalar.js.map +1 -0
- package/builtInTypes/NumberScalar.d.ts +2 -0
- package/builtInTypes/NumberScalar.js +64 -0
- package/builtInTypes/NumberScalar.js.map +1 -0
- package/builtInTypes/RefInputScalar.d.ts +2 -0
- package/builtInTypes/RefInputScalar.js +65 -0
- package/builtInTypes/RefInputScalar.js.map +1 -0
- package/builtInTypes/TimeScalar.d.ts +2 -0
- package/builtInTypes/TimeScalar.js +71 -0
- package/builtInTypes/TimeScalar.js.map +1 -0
- package/builtInTypes/index.d.ts +9 -0
- package/builtInTypes/index.js +122 -0
- package/builtInTypes/index.js.map +1 -0
- package/createGraphQLHandler.d.ts +4 -0
- package/createGraphQLHandler.js +82 -0
- package/createGraphQLHandler.js.map +1 -0
- package/createGraphQLSchema.d.ts +2 -0
- package/createGraphQLSchema.js +73 -0
- package/createGraphQLSchema.js.map +1 -0
- package/debugPlugins.d.ts +14 -0
- package/debugPlugins.js +45 -0
- package/debugPlugins.js.map +1 -0
- package/errors.d.ts +4 -0
- package/errors.js +19 -0
- package/errors.js.map +1 -0
- package/index.d.ts +6 -0
- package/index.js +57 -0
- package/index.js.map +1 -0
- package/interceptConsole.d.ts +5 -0
- package/interceptConsole.js +43 -0
- package/interceptConsole.js.map +1 -0
- package/package.json +50 -0
- package/plugins/GraphQLSchemaPlugin.d.ts +13 -0
- package/plugins/GraphQLSchemaPlugin.js +31 -0
- package/plugins/GraphQLSchemaPlugin.js.map +1 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +18 -0
- package/plugins/index.js.map +1 -0
- package/processRequestBody.d.ts +5 -0
- package/processRequestBody.js +47 -0
- package/processRequestBody.js.map +1 -0
- package/responses.d.ts +41 -0
- package/responses.js +107 -0
- package/responses.js.map +1 -0
- package/types.d.ts +52 -0
- package/types.js +5 -0
- package/types.js.map +1 -0
package/responses.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
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
|
+
stack: null
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
class ErrorResponse {
|
|
20
|
+
constructor(params) {
|
|
21
|
+
(0, _defineProperty2.default)(this, "data", void 0);
|
|
22
|
+
(0, _defineProperty2.default)(this, "error", void 0);
|
|
23
|
+
this.data = null;
|
|
24
|
+
const debug = process.env.DEBUG === "true"; // Ensure `stack` is either `string` or `null`.
|
|
25
|
+
|
|
26
|
+
let stack = defaultParams.stack;
|
|
27
|
+
|
|
28
|
+
if (debug && params.stack) {
|
|
29
|
+
stack = params.stack;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this.error = {
|
|
33
|
+
code: params.code || defaultParams.code,
|
|
34
|
+
message: params.message || defaultParams.message,
|
|
35
|
+
data: params.data || defaultParams.data,
|
|
36
|
+
stack: stack
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.ErrorResponse = ErrorResponse;
|
|
43
|
+
|
|
44
|
+
class NotFoundResponse extends ErrorResponse {
|
|
45
|
+
constructor(message) {
|
|
46
|
+
super({
|
|
47
|
+
code: "NOT_FOUND",
|
|
48
|
+
message
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.NotFoundResponse = NotFoundResponse;
|
|
55
|
+
|
|
56
|
+
class ListErrorResponse {
|
|
57
|
+
constructor(params) {
|
|
58
|
+
(0, _defineProperty2.default)(this, "data", void 0);
|
|
59
|
+
(0, _defineProperty2.default)(this, "meta", void 0);
|
|
60
|
+
(0, _defineProperty2.default)(this, "error", void 0);
|
|
61
|
+
this.meta = null;
|
|
62
|
+
this.data = null;
|
|
63
|
+
const debug = process.env.DEBUG === "true"; // Ensure `stack` is either `string` or `null`.
|
|
64
|
+
|
|
65
|
+
let stack = defaultParams.stack;
|
|
66
|
+
|
|
67
|
+
if (debug && params.stack) {
|
|
68
|
+
stack = params.stack;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
this.error = {
|
|
72
|
+
code: params.code || defaultParams.code,
|
|
73
|
+
message: params.message || defaultParams.message,
|
|
74
|
+
data: params.data || defaultParams.data,
|
|
75
|
+
stack: stack
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
exports.ListErrorResponse = ListErrorResponse;
|
|
82
|
+
|
|
83
|
+
class Response {
|
|
84
|
+
constructor(data) {
|
|
85
|
+
(0, _defineProperty2.default)(this, "data", void 0);
|
|
86
|
+
(0, _defineProperty2.default)(this, "error", void 0);
|
|
87
|
+
this.data = data;
|
|
88
|
+
this.error = null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
exports.Response = Response;
|
|
94
|
+
|
|
95
|
+
class ListResponse {
|
|
96
|
+
constructor(data, meta) {
|
|
97
|
+
(0, _defineProperty2.default)(this, "data", void 0);
|
|
98
|
+
(0, _defineProperty2.default)(this, "meta", void 0);
|
|
99
|
+
(0, _defineProperty2.default)(this, "error", void 0);
|
|
100
|
+
this.data = Array.isArray(data) ? data : [];
|
|
101
|
+
this.meta = meta || {};
|
|
102
|
+
this.error = null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
exports.ListResponse = ListResponse;
|
package/responses.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["defaultParams","code","message","data","stack","ErrorResponse","constructor","params","debug","process","env","DEBUG","error","NotFoundResponse","ListErrorResponse","meta","Response","ListResponse","Array","isArray"],"sources":["responses.ts"],"sourcesContent":["export interface ErrorResponseParams {\n message: string;\n code?: string;\n data?: any;\n stack?: string | null;\n}\n\nconst defaultParams: Required<ErrorResponseParams> = {\n code: \"\",\n message: \"\",\n data: null,\n stack: null\n};\n\nexport class ErrorResponse {\n public readonly data: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\nexport class NotFoundResponse extends ErrorResponse {\n constructor(message: string) {\n super({\n code: \"NOT_FOUND\",\n message\n });\n }\n}\n\nexport class ListErrorResponse {\n public readonly data: null;\n public readonly meta: null;\n public readonly error: {\n code: string;\n message: string;\n data: any;\n stack: string | null;\n };\n\n constructor(params: ErrorResponseParams) {\n this.meta = null;\n this.data = null;\n\n const debug = process.env.DEBUG === \"true\";\n\n // Ensure `stack` is either `string` or `null`.\n let stack = defaultParams.stack;\n if (debug && params.stack) {\n stack = params.stack;\n }\n\n this.error = {\n code: params.code || defaultParams.code,\n message: params.message || defaultParams.message,\n data: params.data || defaultParams.data,\n stack: stack\n };\n }\n}\n\nexport class Response<T = any> {\n public readonly data: T;\n public readonly error: null;\n\n constructor(data: T) {\n this.data = data;\n this.error = null;\n }\n}\n\nexport class ListResponse<T, M> {\n public readonly data: Array<T>;\n public readonly meta: M;\n public readonly error: null;\n\n constructor(data: Array<T>, meta?: M) {\n this.data = Array.isArray(data) ? data : [];\n this.meta = meta || ({} as M);\n this.error = null;\n }\n}\n"],"mappings":";;;;;;;;;;;AAOA,MAAMA,aAA4C,GAAG;EACjDC,IAAI,EAAE,EAD2C;EAEjDC,OAAO,EAAE,EAFwC;EAGjDC,IAAI,EAAE,IAH2C;EAIjDC,KAAK,EAAE;AAJ0C,CAArD;;AAOO,MAAMC,aAAN,CAAoB;EASvBC,WAAW,CAACC,MAAD,EAA8B;IAAA;IAAA;IACrC,KAAKJ,IAAL,GAAY,IAAZ;IAEA,MAAMK,KAAK,GAAGC,OAAO,CAACC,GAAR,CAAYC,KAAZ,KAAsB,MAApC,CAHqC,CAKrC;;IACA,IAAIP,KAAK,GAAGJ,aAAa,CAACI,KAA1B;;IACA,IAAII,KAAK,IAAID,MAAM,CAACH,KAApB,EAA2B;MACvBA,KAAK,GAAGG,MAAM,CAACH,KAAf;IACH;;IAED,KAAKQ,KAAL,GAAa;MACTX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W,CAACH,IAAD,EAAiBY,IAAjB,EAA2B;IAAA;IAAA;IAAA;IAClC,KAAKZ,IAAL,GAAYe,KAAK,CAACC,OAAN,CAAchB,IAAd,IAAsBA,IAAtB,GAA6B,EAAzC;IACA,KAAKY,IAAL,GAAYA,IAAI,IAAK,EAArB;IACA,KAAKH,KAAL,GAAa,IAAb;EACH;;AAT2B"}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { GraphQLScalarType, GraphQLFieldResolver as BaseGraphQLFieldResolver, GraphQLSchema } from "graphql";
|
|
2
|
+
import { Plugin } from "@webiny/plugins/types";
|
|
3
|
+
import { Context } from "@webiny/api/types";
|
|
4
|
+
import { RouteMethodPath } from "@webiny/handler/types";
|
|
5
|
+
export interface GraphQLScalarPlugin extends Plugin {
|
|
6
|
+
type: "graphql-scalar";
|
|
7
|
+
scalar: GraphQLScalarType;
|
|
8
|
+
}
|
|
9
|
+
export interface HandlerGraphQLOptions {
|
|
10
|
+
path?: RouteMethodPath;
|
|
11
|
+
debug?: boolean | string;
|
|
12
|
+
}
|
|
13
|
+
export declare type GraphQLFieldResolver<TSource = any, TArgs = any, TContext = Context> = BaseGraphQLFieldResolver<TSource, TContext, TArgs>;
|
|
14
|
+
export declare type Types = string | (() => string | Promise<string>);
|
|
15
|
+
export interface GraphQLSchemaPluginTypeArgs {
|
|
16
|
+
context?: any;
|
|
17
|
+
args?: any;
|
|
18
|
+
source?: any;
|
|
19
|
+
}
|
|
20
|
+
export declare type Resolvers<TContext> = GraphQLScalarType | GraphQLFieldResolver<any, Record<string, any>, TContext> | {
|
|
21
|
+
[property: string]: Resolvers<TContext>;
|
|
22
|
+
};
|
|
23
|
+
export interface GraphQLSchemaDefinition<TContext> {
|
|
24
|
+
typeDefs: Types;
|
|
25
|
+
resolvers?: Resolvers<TContext>;
|
|
26
|
+
}
|
|
27
|
+
export interface GraphQLSchemaPlugin<TContext extends Context = Context> extends Plugin {
|
|
28
|
+
type: "graphql-schema";
|
|
29
|
+
schema: GraphQLSchemaDefinition<TContext>;
|
|
30
|
+
}
|
|
31
|
+
export interface GraphQLRequestBody {
|
|
32
|
+
query: string;
|
|
33
|
+
variables: Record<string, any>;
|
|
34
|
+
operationName: string;
|
|
35
|
+
}
|
|
36
|
+
export interface GraphQLBeforeQueryPlugin<TContext extends Context = Context> extends Plugin {
|
|
37
|
+
type: "graphql-before-query";
|
|
38
|
+
apply(params: {
|
|
39
|
+
body: GraphQLRequestBody;
|
|
40
|
+
schema: GraphQLSchema;
|
|
41
|
+
context: TContext;
|
|
42
|
+
}): void;
|
|
43
|
+
}
|
|
44
|
+
export interface GraphQLAfterQueryPlugin<TContext extends Context = Context> extends Plugin {
|
|
45
|
+
type: "graphql-after-query";
|
|
46
|
+
apply(params: {
|
|
47
|
+
result: any;
|
|
48
|
+
body: GraphQLRequestBody;
|
|
49
|
+
schema: GraphQLSchema;
|
|
50
|
+
context: TContext;
|
|
51
|
+
}): void;
|
|
52
|
+
}
|
package/types.js
ADDED
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import {\n GraphQLScalarType,\n GraphQLFieldResolver as BaseGraphQLFieldResolver,\n GraphQLSchema\n} from \"graphql\";\nimport { Plugin } from \"@webiny/plugins/types\";\nimport { Context } from \"@webiny/api/types\";\nimport { RouteMethodPath } from \"@webiny/handler/types\";\n\nexport interface GraphQLScalarPlugin extends Plugin {\n type: \"graphql-scalar\";\n scalar: GraphQLScalarType;\n}\n\nexport interface HandlerGraphQLOptions {\n path?: RouteMethodPath;\n debug?: boolean | string;\n}\n\nexport type GraphQLFieldResolver<\n TSource = any,\n TArgs = any,\n TContext = Context\n> = BaseGraphQLFieldResolver<TSource, TContext, TArgs>;\n\n// `GraphQLSchemaPlugin` types.\nexport type Types = string | (() => string | Promise<string>);\n\nexport interface GraphQLSchemaPluginTypeArgs {\n context?: any;\n args?: any;\n source?: any;\n}\n\nexport type Resolvers<TContext> =\n | GraphQLScalarType\n | GraphQLFieldResolver<any, Record<string, any>, TContext>\n | { [property: string]: Resolvers<TContext> };\n\nexport interface GraphQLSchemaDefinition<TContext> {\n typeDefs: Types;\n resolvers?: Resolvers<TContext>;\n}\n\nexport interface GraphQLSchemaPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-schema\";\n schema: GraphQLSchemaDefinition<TContext>;\n}\n\nexport interface GraphQLRequestBody {\n query: string;\n variables: Record<string, any>;\n operationName: string;\n}\n\nexport interface GraphQLBeforeQueryPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-before-query\";\n apply(params: { body: GraphQLRequestBody; schema: GraphQLSchema; context: TContext }): void;\n}\n\nexport interface GraphQLAfterQueryPlugin<TContext extends Context = Context> extends Plugin {\n type: \"graphql-after-query\";\n apply(params: {\n result: any;\n body: GraphQLRequestBody;\n schema: GraphQLSchema;\n context: TContext;\n }): void;\n}\n"],"mappings":""}
|