0.2.12 • Published 5 years ago
graphql-to-restapi v0.2.12
Cài module:
$ npm install --save graphql-to-restapi
Sử dụng
Chỉ cần sử dụng graphql-to-restapi
như một route handle
import GraphqlRest from 'graphql-to-restapi';
import express from 'express';
const app = express();
app.use('/api', GraphqlRest({
schema: GraphQLSchema,
routeConfigs: routeConfigs
}));
app.listen(4000);
Options
graphql-to-restapi
chấp nhận các options dưới đây:
schema(*)
: LàGraphQLSchema
instance từGraphQL.js
.routeConfigs(*)
: Là config rest api và graphql resolve tương ứng
let routeConfigs = [
// Viewer
{
method: 'post',
path: '/login',
handle: {
type: 'mutation',
name: 'login'
},
tags: ['Viewer']
},{
method: 'get',
path: '/profile',
handle: {
type: 'query',
name: 'profile'
},
// áp dụng security chỉ ở phạm vi api get profile
security: [{
BearerAuth: []
}],
tags: ['Viewer']
}
/*************************************/
// ACCOUNT
{
method: 'post',
path: '/account',
handle: {
type: 'mutation',
name: 'createAccount'
},
tags: ['Account']
},{
method: 'get',
path: '/account',
handle: {
type: 'query',
name: 'accounts'
},
tags: ['Account']
}
];
swagger
: Nếu có sẽ gen ra link doc swagger. info, servers, components, security theo như config của swagger
swagger = {
info: {
title: 'Sample API',
version: '0.1.9'
},
servers: [
{
url: '/api'
}
],
components: {
securitySchemes: {
// Định nghĩa các kiểu authen https://swagger.io/docs/specification/authentication/
BearerAuth: {
type: 'http',
scheme: 'bearer'
}
}
},
//Áp dụng security global cho tất cả api
security: [
{
BearerAuth: []
}
]
}
graphql
: Nếu có giá trịtrue
thì sẽ gen ra link doc graphql như graphqli củaexpress-graphql
.formatContext
: Là function để formatcontext
chographql()
. NếuformatContext
không có thìrequest
sẽ được gán vào context.
0.2.12
5 years ago
0.2.11
5 years ago
0.2.10
5 years ago
0.2.9
5 years ago
0.2.8
5 years ago
0.2.7
5 years ago
0.2.6
5 years ago
0.2.4
5 years ago
0.2.3
6 years ago
0.2.2
6 years ago
0.2.1
6 years ago
0.2.0
6 years ago
0.1.8
6 years ago
0.1.7
6 years ago
0.1.6
6 years ago
0.1.5
6 years ago
0.1.4
6 years ago
0.1.3
6 years ago
0.1.2
6 years ago
0.1.1
6 years ago
0.1.0
6 years ago
0.0.31
6 years ago
0.0.30
6 years ago
0.0.29
6 years ago
0.0.28
6 years ago
0.0.27
6 years ago
0.0.26
6 years ago
0.0.25
6 years ago
0.0.24
6 years ago
0.0.23
6 years ago
0.0.22
6 years ago
0.0.21
6 years ago
0.0.20
6 years ago
0.0.19
6 years ago
0.0.18
6 years ago