@axinom/mosaic-graphql-common 0.8.0-rc.1 → 0.8.0-rc.3
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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/middleware/forward-to-graphiql.d.ts +8 -0
- package/dist/middleware/forward-to-graphiql.d.ts.map +1 -0
- package/dist/middleware/forward-to-graphiql.js +21 -0
- package/dist/middleware/forward-to-graphiql.js.map +1 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +18 -0
- package/dist/middleware/index.js.map +1 -0
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/middleware/forward-to-graphiql.ts +22 -0
- package/src/middleware/index.ts +1 -0
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./common"), exports);
|
|
18
|
+
__exportStar(require("./middleware"), exports);
|
|
18
19
|
__exportStar(require("./plugins"), exports);
|
|
19
20
|
__exportStar(require("./postgraphile"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,4CAA0B;AAC1B,iDAA+B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,+CAA6B;AAC7B,4CAA0B;AAC1B,iDAA+B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NextFunction, Request, Response } from 'express';
|
|
2
|
+
/**
|
|
3
|
+
* Middleware that forwards requests that accept html to graphiql.
|
|
4
|
+
* @param graphQLUrl The url to forward from. (default: '/graphql')
|
|
5
|
+
* @param graphiQLUrl The url to forward to. (default: '/graphiql')
|
|
6
|
+
*/
|
|
7
|
+
export declare const forwardToGraphiQl: (graphQLUrl?: string, graphiQLUrl?: string) => (req: Request, res: Response, next: NextFunction) => void;
|
|
8
|
+
//# sourceMappingURL=forward-to-graphiql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forward-to-graphiql.d.ts","sourceRoot":"","sources":["../../src/middleware/forward-to-graphiql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE1D;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,uDAEtB,OAAO,OAAO,QAAQ,QAAQ,YAAY,KAAG,IAYlD,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.forwardToGraphiQl = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Middleware that forwards requests that accept html to graphiql.
|
|
6
|
+
* @param graphQLUrl The url to forward from. (default: '/graphql')
|
|
7
|
+
* @param graphiQLUrl The url to forward to. (default: '/graphiql')
|
|
8
|
+
*/
|
|
9
|
+
const forwardToGraphiQl = (graphQLUrl = '/graphql', graphiQLUrl = '/graphiql') => (req, res, next) => {
|
|
10
|
+
if (req.accepts('html') &&
|
|
11
|
+
// Get requests to / that accept html
|
|
12
|
+
((req.path === '/' && req.method === 'GET' && req.accepts('html')) ||
|
|
13
|
+
// Get requests to /graphql that accept html and do not have a query
|
|
14
|
+
(req.path === graphQLUrl && req.method === 'GET' && !req.query.query))) {
|
|
15
|
+
// forward to graphiql
|
|
16
|
+
return res.redirect(graphiQLUrl);
|
|
17
|
+
}
|
|
18
|
+
return next();
|
|
19
|
+
};
|
|
20
|
+
exports.forwardToGraphiQl = forwardToGraphiQl;
|
|
21
|
+
//# sourceMappingURL=forward-to-graphiql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forward-to-graphiql.js","sourceRoot":"","sources":["../../src/middleware/forward-to-graphiql.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACI,MAAM,iBAAiB,GAC5B,CAAC,UAAU,GAAG,UAAU,EAAE,WAAW,GAAG,WAAW,EAAE,EAAE,CACvD,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAQ,EAAE;IACxD,IACE,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC;QACnB,qCAAqC;QACrC,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAChE,oEAAoE;YACpE,CAAC,GAAG,CAAC,IAAI,KAAK,UAAU,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EACxE;QACA,sBAAsB;QACtB,OAAO,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;KAClC;IACD,OAAO,IAAI,EAAE,CAAC;AAChB,CAAC,CAAC;AAdS,QAAA,iBAAiB,qBAc1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./forward-to-graphiql"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axinom/mosaic-graphql-common",
|
|
3
|
-
"version": "0.8.0-rc.
|
|
3
|
+
"version": "0.8.0-rc.3",
|
|
4
4
|
"description": "Common GraphQL and PostGraphile related functionality.",
|
|
5
5
|
"author": "Axinom",
|
|
6
6
|
"license": "PROPRIETARY",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "cb9bba0b7ae9543a415ea8eefbcb3444e76ac6f2"
|
|
61
61
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NextFunction, Request, Response } from 'express';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Middleware that forwards requests that accept html to graphiql.
|
|
5
|
+
* @param graphQLUrl The url to forward from. (default: '/graphql')
|
|
6
|
+
* @param graphiQLUrl The url to forward to. (default: '/graphiql')
|
|
7
|
+
*/
|
|
8
|
+
export const forwardToGraphiQl =
|
|
9
|
+
(graphQLUrl = '/graphql', graphiQLUrl = '/graphiql') =>
|
|
10
|
+
(req: Request, res: Response, next: NextFunction): void => {
|
|
11
|
+
if (
|
|
12
|
+
req.accepts('html') &&
|
|
13
|
+
// Get requests to / that accept html
|
|
14
|
+
((req.path === '/' && req.method === 'GET' && req.accepts('html')) ||
|
|
15
|
+
// Get requests to /graphql that accept html and do not have a query
|
|
16
|
+
(req.path === graphQLUrl && req.method === 'GET' && !req.query.query))
|
|
17
|
+
) {
|
|
18
|
+
// forward to graphiql
|
|
19
|
+
return res.redirect(graphiQLUrl);
|
|
20
|
+
}
|
|
21
|
+
return next();
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './forward-to-graphiql';
|