@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.
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/builtInTypes/AnyScalar.d.ts +2 -0
- package/builtInTypes/AnyScalar.js +20 -0
- package/builtInTypes/DateScalar.d.ts +2 -0
- package/builtInTypes/DateScalar.js +38 -0
- package/builtInTypes/DateTimeScalar.d.ts +2 -0
- package/builtInTypes/DateTimeScalar.js +38 -0
- package/builtInTypes/DateTimeZScalar.d.ts +6 -0
- package/builtInTypes/DateTimeZScalar.js +63 -0
- package/builtInTypes/JsonScalar.d.ts +1 -0
- package/builtInTypes/JsonScalar.js +11 -0
- package/builtInTypes/LongScalar.d.ts +1 -0
- package/builtInTypes/LongScalar.js +11 -0
- package/builtInTypes/NumberScalar.d.ts +2 -0
- package/builtInTypes/NumberScalar.js +60 -0
- package/builtInTypes/RefInputScalar.d.ts +2 -0
- package/builtInTypes/RefInputScalar.js +65 -0
- package/builtInTypes/TimeScalar.d.ts +2 -0
- package/builtInTypes/TimeScalar.js +71 -0
- package/builtInTypes/index.d.ts +9 -0
- package/builtInTypes/index.js +122 -0
- package/createGraphQLHandler.d.ts +4 -0
- package/createGraphQLHandler.js +77 -0
- package/createGraphQLSchema.d.ts +3 -0
- package/createGraphQLSchema.js +65 -0
- package/debugPlugins.d.ts +12 -0
- package/debugPlugins.js +48 -0
- package/errors.d.ts +4 -0
- package/errors.js +19 -0
- package/index.d.ts +9 -0
- package/index.js +54 -0
- package/interceptConsole.d.ts +1 -0
- package/interceptConsole.js +39 -0
- package/package.json +49 -0
- package/plugins/GraphQLSchemaPlugin.d.ts +13 -0
- package/plugins/GraphQLSchemaPlugin.js +31 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +18 -0
- package/processRequestBody.d.ts +2 -0
- package/processRequestBody.js +49 -0
- package/responses.d.ts +39 -0
- package/responses.js +88 -0
- package/types.d.ts +50 -0
- package/types.js +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @webiny/handler-graphql
|
|
2
|
+
[](https://www.npmjs.com/package/@webiny/handler-graphql)
|
|
3
|
+
[](https://www.npmjs.com/package/@webiny/handler-graphql)
|
|
4
|
+
[](https://github.com/prettier/prettier)
|
|
5
|
+
[](http://makeapullrequest.com)
|
|
6
|
+
|
|
7
|
+
A simple Apollo Server as a `handler`
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Any = void 0;
|
|
7
|
+
|
|
8
|
+
var _graphql = require("graphql");
|
|
9
|
+
|
|
10
|
+
const returnValue = value => {
|
|
11
|
+
return value;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const Any = new _graphql.GraphQLScalarType({
|
|
15
|
+
name: "Any",
|
|
16
|
+
description: `A scalar type that represents an ambiguous value.`,
|
|
17
|
+
serialize: returnValue,
|
|
18
|
+
parseValue: returnValue
|
|
19
|
+
});
|
|
20
|
+
exports.Any = Any;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.DateScalar = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _graphqlScalars = require("graphql-scalars");
|
|
13
|
+
|
|
14
|
+
var _graphql = require("graphql");
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
const DateScalar = new _graphql.GraphQLScalarType(_objectSpread(_objectSpread({}, _graphqlScalars.DateResolver), {}, {
|
|
21
|
+
serialize: value => {
|
|
22
|
+
if (!value) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const date = new Date(value);
|
|
28
|
+
return date.toISOString().substr(0, 10);
|
|
29
|
+
} catch (ex) {
|
|
30
|
+
if (value.toISOString) {
|
|
31
|
+
return value.toISOString().substr(0, 10);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
throw ex;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
exports.DateScalar = DateScalar;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.DateTimeScalar = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _graphqlScalars = require("graphql-scalars");
|
|
13
|
+
|
|
14
|
+
var _graphql = require("graphql");
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
const DateTimeScalar = new _graphql.GraphQLScalarType(_objectSpread(_objectSpread({}, _graphqlScalars.DateTimeResolver), {}, {
|
|
21
|
+
serialize: value => {
|
|
22
|
+
if (!value) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const date = new Date(value);
|
|
28
|
+
return date.toISOString();
|
|
29
|
+
} catch (ex) {
|
|
30
|
+
if (value.toISOString) {
|
|
31
|
+
return value.toISOString();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
throw ex;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
exports.DateTimeScalar = DateTimeScalar;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.DateTimeZScalar = void 0;
|
|
9
|
+
|
|
10
|
+
var _graphqlScalars = require("graphql-scalars");
|
|
11
|
+
|
|
12
|
+
var _graphql = require("graphql");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
const validateTimeZone = value => {
|
|
17
|
+
const timeWithTimezone = value.split("T")[1];
|
|
18
|
+
|
|
19
|
+
if (!timeWithTimezone) {
|
|
20
|
+
throw new _error.default("Could not extract time with timezone from value.", "DATE_TIME_TIMEZONE_ERROR", {
|
|
21
|
+
value
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const separator = timeWithTimezone.includes("-") ? "-" : "+";
|
|
26
|
+
const zone = timeWithTimezone.split(separator)[1];
|
|
27
|
+
|
|
28
|
+
if (!zone) {
|
|
29
|
+
throw new _error.default("Could not extract timezone from value.", "DATE_TIME_TIMEZONE_ERROR", {
|
|
30
|
+
value: timeWithTimezone
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const hoursMinutes = zone.split(":");
|
|
35
|
+
const [hours, minutes] = hoursMinutes;
|
|
36
|
+
|
|
37
|
+
if (hours === undefined || minutes === undefined || hoursMinutes.length !== 2) {
|
|
38
|
+
throw new _error.default("Could not extract hours or minutes from value.", "DATE_TIME_TIMEZONE_ERROR", {
|
|
39
|
+
value: zone
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* A custom type for dateTime with the timezone.
|
|
45
|
+
* Must be in format "YYYY-MM-ddTHH:mm:ss+HH:mm".
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
const DateTimeZScalar = new _graphql.GraphQLScalarType({
|
|
50
|
+
name: "DateTimeZ",
|
|
51
|
+
description: "A custom type for dateTime with the timezone.",
|
|
52
|
+
parseValue: value => {
|
|
53
|
+
// this serves as validator
|
|
54
|
+
_graphqlScalars.DateTimeResolver.parseValue(value);
|
|
55
|
+
|
|
56
|
+
validateTimeZone(value);
|
|
57
|
+
return value;
|
|
58
|
+
},
|
|
59
|
+
serialize: value => {
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
exports.DateTimeZScalar = DateTimeZScalar;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const JsonScalar: import("graphql").GraphQLScalarType;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.JsonScalar = void 0;
|
|
7
|
+
|
|
8
|
+
var _graphqlScalars = require("graphql-scalars");
|
|
9
|
+
|
|
10
|
+
const JsonScalar = _graphqlScalars.JSONResolver;
|
|
11
|
+
exports.JsonScalar = JsonScalar;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const LongScalar: import("graphql").GraphQLScalarType;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.LongScalar = void 0;
|
|
7
|
+
|
|
8
|
+
var _graphqlScalars = require("graphql-scalars");
|
|
9
|
+
|
|
10
|
+
const LongScalar = _graphqlScalars.LongResolver;
|
|
11
|
+
exports.LongScalar = LongScalar;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.Number = void 0;
|
|
9
|
+
|
|
10
|
+
var _graphql = require("graphql");
|
|
11
|
+
|
|
12
|
+
var _language = require("graphql/language");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
const parseValue = value => {
|
|
17
|
+
if (String(value).match(/^0x/) !== null) {
|
|
18
|
+
throw new _error.default("Value sent must be a non-hex number.", "INVALID_VALUE", {
|
|
19
|
+
value
|
|
20
|
+
});
|
|
21
|
+
} else if (typeof value === "number") {
|
|
22
|
+
return value;
|
|
23
|
+
} else if (value === null || value === undefined) {
|
|
24
|
+
return null;
|
|
25
|
+
} else if (isNaN(value) === true) {
|
|
26
|
+
throw new _error.default("Value sent must be a number.", "INVALID_VALUE", {
|
|
27
|
+
value
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return parseFloat(value);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const Number = new _graphql.GraphQLScalarType({
|
|
35
|
+
name: "Number",
|
|
36
|
+
description: "A custom input type to be used with numbers. Supports Int and Float.",
|
|
37
|
+
serialize: value => {
|
|
38
|
+
try {
|
|
39
|
+
return parseValue(value);
|
|
40
|
+
} catch (ex) {
|
|
41
|
+
console.log({
|
|
42
|
+
message: "Value sent must be a number.",
|
|
43
|
+
code: "INVALID_VALUE",
|
|
44
|
+
data: {
|
|
45
|
+
value
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
parseValue,
|
|
52
|
+
parseLiteral: ast => {
|
|
53
|
+
if (ast.kind === _language.Kind.INT || ast.kind === _language.Kind.FLOAT) {
|
|
54
|
+
return ast.value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
throw new Error(`Expected type Number, found {${ast.value}}`);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
exports.Number = Number;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.RefInput = void 0;
|
|
7
|
+
|
|
8
|
+
var _graphql = require("graphql");
|
|
9
|
+
|
|
10
|
+
const isMongoId = value => {
|
|
11
|
+
if (/^[0-9a-fA-F]{24}$/.test(value)) {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
throw new Error("Must be a valid Mongo ID!");
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const RefInput = new _graphql.GraphQLScalarType({
|
|
19
|
+
name: "RefInput",
|
|
20
|
+
description: "A custom input type to be used with references. Supports plain ID and `{ id: ID }` Object literal.",
|
|
21
|
+
serialize: value => {
|
|
22
|
+
if (!value || value.id === null) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return typeof value === "string" ? value : value.id;
|
|
27
|
+
},
|
|
28
|
+
parseValue: value => {
|
|
29
|
+
if (!value || value.id === null) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (typeof value === "string") {
|
|
34
|
+
return isMongoId(value);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if ("id" in value) {
|
|
38
|
+
return isMongoId(value.id);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
throw new Error("Invalid RefInput value!");
|
|
42
|
+
},
|
|
43
|
+
parseLiteral: ast => {
|
|
44
|
+
if (ast.kind === "StringValue") {
|
|
45
|
+
return isMongoId(ast.value);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (ast.kind === "ObjectValue") {
|
|
49
|
+
for (let i = 0; i < ast.fields.length; i++) {
|
|
50
|
+
const {
|
|
51
|
+
name,
|
|
52
|
+
value
|
|
53
|
+
} = ast.fields[i];
|
|
54
|
+
|
|
55
|
+
if (name.value === "id") {
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
return isMongoId(value.value);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
throw new Error("Invalid RefInput value!");
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
exports.RefInput = RefInput;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.TimeScalar = void 0;
|
|
9
|
+
|
|
10
|
+
var _graphql = require("graphql");
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
const re = /^([0-9]{2}):([0-9]{2})(:([0-9]{2}))?$/;
|
|
15
|
+
|
|
16
|
+
const parseTime = value => {
|
|
17
|
+
if (!value || value.match(re) === null) {
|
|
18
|
+
throw new _error.default("Value does not look like time.", "TIME_VALIDATION_ERROR", {
|
|
19
|
+
value
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const parsed = value.split(":").map(Number);
|
|
24
|
+
|
|
25
|
+
if (parsed.length < 2) {
|
|
26
|
+
throw new _error.default(`Could not parse the value.`, "TIME_VALIDATION_ERROR", {
|
|
27
|
+
value
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const [hours, minutes, seconds = 0] = parsed;
|
|
32
|
+
|
|
33
|
+
if (hours >= 24) {
|
|
34
|
+
throw new _error.default(`There cannot be more than 24 hours.`, "TIME_VALIDATION_ERROR", {
|
|
35
|
+
value
|
|
36
|
+
});
|
|
37
|
+
} else if (minutes >= 60) {
|
|
38
|
+
throw new _error.default(`There cannot be more than 59 minutes.`, "TIME_VALIDATION_ERROR", {
|
|
39
|
+
value
|
|
40
|
+
});
|
|
41
|
+
} else if (seconds >= 60) {
|
|
42
|
+
throw new _error.default(`There cannot be more than 59 seconds.`, "TIME_VALIDATION_ERROR", {
|
|
43
|
+
value
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
hours,
|
|
49
|
+
minutes,
|
|
50
|
+
seconds
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const convertToTime = value => {
|
|
55
|
+
const {
|
|
56
|
+
hours,
|
|
57
|
+
minutes,
|
|
58
|
+
seconds
|
|
59
|
+
} = parseTime(value);
|
|
60
|
+
return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const TimeScalar = new _graphql.GraphQLScalarType({
|
|
64
|
+
name: "Time",
|
|
65
|
+
description: "A custom type to support time-only input.",
|
|
66
|
+
// sending to client
|
|
67
|
+
serialize: convertToTime,
|
|
68
|
+
// received from client
|
|
69
|
+
parseValue: convertToTime
|
|
70
|
+
});
|
|
71
|
+
exports.TimeScalar = TimeScalar;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./AnyScalar";
|
|
2
|
+
export * from "./DateScalar";
|
|
3
|
+
export * from "./DateTimeScalar";
|
|
4
|
+
export * from "./DateTimeZScalar";
|
|
5
|
+
export * from "./JsonScalar";
|
|
6
|
+
export * from "./LongScalar";
|
|
7
|
+
export * from "./NumberScalar";
|
|
8
|
+
export * from "./RefInputScalar";
|
|
9
|
+
export * from "./TimeScalar";
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _AnyScalar = require("./AnyScalar");
|
|
8
|
+
|
|
9
|
+
Object.keys(_AnyScalar).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _AnyScalar[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _AnyScalar[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
var _DateScalar = require("./DateScalar");
|
|
21
|
+
|
|
22
|
+
Object.keys(_DateScalar).forEach(function (key) {
|
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
|
24
|
+
if (key in exports && exports[key] === _DateScalar[key]) return;
|
|
25
|
+
Object.defineProperty(exports, key, {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _DateScalar[key];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
var _DateTimeScalar = require("./DateTimeScalar");
|
|
34
|
+
|
|
35
|
+
Object.keys(_DateTimeScalar).forEach(function (key) {
|
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
|
37
|
+
if (key in exports && exports[key] === _DateTimeScalar[key]) return;
|
|
38
|
+
Object.defineProperty(exports, key, {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return _DateTimeScalar[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
var _DateTimeZScalar = require("./DateTimeZScalar");
|
|
47
|
+
|
|
48
|
+
Object.keys(_DateTimeZScalar).forEach(function (key) {
|
|
49
|
+
if (key === "default" || key === "__esModule") return;
|
|
50
|
+
if (key in exports && exports[key] === _DateTimeZScalar[key]) return;
|
|
51
|
+
Object.defineProperty(exports, key, {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return _DateTimeZScalar[key];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
var _JsonScalar = require("./JsonScalar");
|
|
60
|
+
|
|
61
|
+
Object.keys(_JsonScalar).forEach(function (key) {
|
|
62
|
+
if (key === "default" || key === "__esModule") return;
|
|
63
|
+
if (key in exports && exports[key] === _JsonScalar[key]) return;
|
|
64
|
+
Object.defineProperty(exports, key, {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () {
|
|
67
|
+
return _JsonScalar[key];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
var _LongScalar = require("./LongScalar");
|
|
73
|
+
|
|
74
|
+
Object.keys(_LongScalar).forEach(function (key) {
|
|
75
|
+
if (key === "default" || key === "__esModule") return;
|
|
76
|
+
if (key in exports && exports[key] === _LongScalar[key]) return;
|
|
77
|
+
Object.defineProperty(exports, key, {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function () {
|
|
80
|
+
return _LongScalar[key];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
var _NumberScalar = require("./NumberScalar");
|
|
86
|
+
|
|
87
|
+
Object.keys(_NumberScalar).forEach(function (key) {
|
|
88
|
+
if (key === "default" || key === "__esModule") return;
|
|
89
|
+
if (key in exports && exports[key] === _NumberScalar[key]) return;
|
|
90
|
+
Object.defineProperty(exports, key, {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get: function () {
|
|
93
|
+
return _NumberScalar[key];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
var _RefInputScalar = require("./RefInputScalar");
|
|
99
|
+
|
|
100
|
+
Object.keys(_RefInputScalar).forEach(function (key) {
|
|
101
|
+
if (key === "default" || key === "__esModule") return;
|
|
102
|
+
if (key in exports && exports[key] === _RefInputScalar[key]) return;
|
|
103
|
+
Object.defineProperty(exports, key, {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
get: function () {
|
|
106
|
+
return _RefInputScalar[key];
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
var _TimeScalar = require("./TimeScalar");
|
|
112
|
+
|
|
113
|
+
Object.keys(_TimeScalar).forEach(function (key) {
|
|
114
|
+
if (key === "default" || key === "__esModule") return;
|
|
115
|
+
if (key in exports && exports[key] === _TimeScalar[key]) return;
|
|
116
|
+
Object.defineProperty(exports, key, {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
get: function () {
|
|
119
|
+
return _TimeScalar[key];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _boolean = require("boolean");
|
|
13
|
+
|
|
14
|
+
var _createGraphQLSchema = require("./createGraphQLSchema");
|
|
15
|
+
|
|
16
|
+
var _debugPlugins = _interopRequireDefault(require("./debugPlugins"));
|
|
17
|
+
|
|
18
|
+
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
|
+
const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
31
|
+
|
|
32
|
+
var _default = (options = {}) => {
|
|
33
|
+
let schema;
|
|
34
|
+
const debug = (0, _boolean.boolean)(options.debug);
|
|
35
|
+
return [...(debug ? (0, _debugPlugins.default)() : []), {
|
|
36
|
+
type: "handler",
|
|
37
|
+
name: "handler-graphql",
|
|
38
|
+
|
|
39
|
+
async handle(context, next) {
|
|
40
|
+
const {
|
|
41
|
+
http
|
|
42
|
+
} = context;
|
|
43
|
+
|
|
44
|
+
if (!http) {
|
|
45
|
+
return next();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (http.request.method === "OPTIONS") {
|
|
49
|
+
return http.response({
|
|
50
|
+
statusCode: 204,
|
|
51
|
+
headers: _objectSpread(_objectSpread({}, DEFAULT_HEADERS), {}, {
|
|
52
|
+
"Cache-Control": "public, max-age=" + DEFAULT_CACHE_MAX_AGE
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (http.request.method !== "POST") {
|
|
58
|
+
return next();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!schema) {
|
|
62
|
+
schema = (0, _createGraphQLSchema.createGraphQLSchema)(context);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const body = JSON.parse(http.request.body);
|
|
66
|
+
const result = await (0, _processRequestBody.default)(body, schema, context);
|
|
67
|
+
return http.response({
|
|
68
|
+
body: JSON.stringify(result),
|
|
69
|
+
statusCode: 200,
|
|
70
|
+
headers: DEFAULT_HEADERS
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
}];
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
exports.default = _default;
|