@acastellon/graphql 中文文档教程

发布于 5年前 浏览 22 项目主页 更新于 3年前

Graphql

用于封装基于 GraphQL (HTTPS/Express) 的基本 WS 的通用配置的


模块 使用此模块的示例代码:

const SERVER = require('./config.server.js');
const AUTH = require('./config.auth.js');

const graphql = require('@acastellon/graphql')(SERVER, AUTH);
graphql.run(); 

您可以传递一个在服务器初始化后要执行的函数

rest.run(callback())

rest.run(() => { .. })

所需配置文件示例: 所需

- config.server.js

module.exports = {
    /* where are stored the certificate files */
    CERTIFICATION_PATH : '/opt/<project>/Certificate'

    /* listener port */ 
    ,PORT : 7000

    /* file used by CORS to allows requst to the server */
    ,WHITELIST : './whitelist'

    /* location of the static files if is needed */
    ,STATIC_PATH : '/html'         //null = no static files where associated

    /* location of the Schema & resolvers required by graphql */
    ,SCHEMA_PATH : './graphql/schema/'
}

- config.auth.js

module.exports = {
    url: 'ldap://<address>:389'
    ,DOMAIN: '<domain>'
    ,baseDN: 'DC=<>,DC=<>>'
    ,username: '<username>'
    ,password: '<password>'

    ,hostNames: {
        'DEV' : '<dev-server.ip.dns.name>'
        ,'QA' : '<QA-server.ip.dns.name>'
        ,'PROD' : '<production-server.ip.dns.name>'
    }
    ,passToken: '<passphrase-optional>'  /* if doesn't exists the module generates ones automatically */
    ,EXPIRES: 86400                     /* expires in 24 hours */

    , AUTH_TYPE : 'NTLM'  /* NTLM, JWT or NONE */

    ,MOCKUP_USERS : ['acastellon']
    ,MOCKUP_ROLES : ['User','Admin']
    ,ROLES : {                          /* LDAP Roles to match */
        'User': '<LDAP> USER '          
        , 'Admin': '<LDAP> ADMINISTRATOR '
        , 'Viewer': '<LDAP> VIEWER '
    }
}
- api.js
- See the api.template.js as a reference to implement the logic.

安全文件:

- privateKey.pem
- publicCert.pem
- passphrase

其他所需文件:

- whitelist : used by CORS

Graphql

Module to encapsulate the common configuration of a base WS based in GraphQL (HTTPS/Express)


Example Code to use this module:

const SERVER = require('./config.server.js');
const AUTH = require('./config.auth.js');

const graphql = require('@acastellon/graphql')(SERVER, AUTH);
graphql.run(); 

you can pass a function to be executed after the initialization of the server

rest.run(callback())

rest.run(() => { .. })

Example of configuration files required:

- config.server.js

module.exports = {
    /* where are stored the certificate files */
    CERTIFICATION_PATH : '/opt/<project>/Certificate'

    /* listener port */ 
    ,PORT : 7000

    /* file used by CORS to allows requst to the server */
    ,WHITELIST : './whitelist'

    /* location of the static files if is needed */
    ,STATIC_PATH : '/html'         //null = no static files where associated

    /* location of the Schema & resolvers required by graphql */
    ,SCHEMA_PATH : './graphql/schema/'
}

- config.auth.js

module.exports = {
    url: 'ldap://<address>:389'
    ,DOMAIN: '<domain>'
    ,baseDN: 'DC=<>,DC=<>>'
    ,username: '<username>'
    ,password: '<password>'

    ,hostNames: {
        'DEV' : '<dev-server.ip.dns.name>'
        ,'QA' : '<QA-server.ip.dns.name>'
        ,'PROD' : '<production-server.ip.dns.name>'
    }
    ,passToken: '<passphrase-optional>'  /* if doesn't exists the module generates ones automatically */
    ,EXPIRES: 86400                     /* expires in 24 hours */

    , AUTH_TYPE : 'NTLM'  /* NTLM, JWT or NONE */

    ,MOCKUP_USERS : ['acastellon']
    ,MOCKUP_ROLES : ['User','Admin']
    ,ROLES : {                          /* LDAP Roles to match */
        'User': '<LDAP> USER '          
        , 'Admin': '<LDAP> ADMINISTRATOR '
        , 'Viewer': '<LDAP> VIEWER '
    }
}
- api.js
- See the api.template.js as a reference to implement the logic.

Security files required:

- privateKey.pem
- publicCert.pem
- passphrase

Other files required:

- whitelist : used by CORS
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文