Skip to content

Commit 4ef2b39

Browse files
Include fixes to swagger documentation
1 parent 0c01bf5 commit 4ef2b39

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

README.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ GraphQL Rest Router allows you to expose an internal GraphQL API as a REST API.
1212
_Example Usage_
1313
```js
1414
import GraphQLRestRouter from 'graphql-rest-router';
15+
import * as OpenApi from 'graphql-rest-router';
16+
1517
const Schema = `
1618
query UserById($id: Int!) {
1719
getUserById(id: $id) {
@@ -31,6 +33,22 @@ const Schema = `
3133
}
3234
`;
3335

36+
const swaggerDoc = new OpenApi.V2({
37+
title: 'Example API',
38+
version: '1.0.0',
39+
40+
host: 'http://127.0.0.1',
41+
basePath: '/api',
42+
});
43+
44+
const openApiDoc = new OpenApi.V3({
45+
title: 'Example API',
46+
version: '1.0.0',
47+
48+
host: 'http://127.0.0.1',
49+
basePath: '/api',
50+
});
51+
3452
const api = new GraphQLRestRouter(url, Schema, {
3553
cacheEngine: GraphQLRestRouter.InMemoryCache,
3654

@@ -43,8 +61,7 @@ const api = new GraphQLRestRouter(url, Schema, {
4361
},
4462
});
4563

46-
api.mount({
47-
operationName: 'UserByEmail'
64+
api.mount('UserByEmail', {
4865
path: '/user/:email',
4966

5067
method: 'POST',
@@ -63,16 +80,12 @@ api.mount({
6380
api.mount('UserById'); // creates GET /UserById?id=:id
6481

6582
api.mount('UserById').at('/:id') // creates GET /:id
66-
.setCacheTimeInMs(200);
6783

6884
api.mount('UserById').at('/:id').as('POST')
6985
.disableCache()
70-
.modifyRequest(request => {
71-
request.addHeader('x-jwt', 'test');
86+
.transformRequest(headers => {
87+
headers['x-context-jwt'] = '1234';
7288
})
73-
.modifyResponse(response => {
74-
response.setStatus(200);
75-
});
7689

7790
api.mount('UserById').withOptions({
7891
path: '/user/0',
@@ -83,8 +96,9 @@ api.mount('UserById').withOptions({
8396
}
8497
});
8598

99+
api.mount(swaggerDoc).at('/docs/swagger');
100+
api.mount(openApiDoc).at('/docs/openapi');
101+
86102
// Export Options
87-
api.asExpressRouter();
88-
api.asKoaRouter();
89-
api.listen(3000, () => console.log('Callback'));
103+
module.exports = api.asExpressRouter();
90104
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-rest-router",
3-
"version": "1.0.0-alpha.8",
3+
"version": "1.0.0-alpha.10",
44
"description": "",
55
"main": "index.js",
66
"files": ["*.js"],

0 commit comments

Comments
 (0)