yunfly apollo plugin.
- install
yarn add @yunflyjs/yunfly-plugin-apollo- declare plugins in config/config.plugin.ts
/**
* yunfly plugin
*/
const plugins: {[key:string]: string}[] = [
{
name: 'apollo',
package: '@yunflyjs/yunfly-plugin-apollo',
lifeHook: 'beforeStart'
}
];
//
export default plugins;- enable plugins in config/config.default.ts
config.apollo = {
enable: true,
// serviceName: 'example-apollo-service',
// serviceUrl: 'http://xxx.com',
// secret: 'xxxxxx',
// namespace: 'application'
}export interface ApolloConfig {
enable?: boolean;
secret?: string;
serviceUrl?: string;
namespace?: string;
serviceName?: string;
}| field | type | required | default | notes |
|---|---|---|---|---|
| enable | boolean |
yes | false |
enable the plugin |
| secret | string |
no | process.env.APOLLO_ACCESSKEY_SECRET |
apollo secret |
| serviceUrl | string |
no | process.env.APOLLO_META_SERVER_URL |
apollo host url |
| namespace | string |
no | application |
apollo config namespace |
| serviceName | string |
no | packageJson.name |
- getApolloConfig
api usage
import { getApolloConfig } from '@yunflyjs/yunfly-plugin-apollo';
console.log('getApolloConfig',getApolloConfig);- get apollo config in controller
import { Controller, Get } from '@yunflyjs/yunfly';
import { getApolloConfig } from '@yunflyjs/yunfly-plugin-apollo';
@Controller()
export class ExampleController {
@Get('/users')
getApolloConfig() {
return getApolloConfig();
}
}apollo url host address, need to start with http:// or https://.
- priority
config.apollo.serviceUrl > process.env.APOLLO_META_SERVER_URL
if the apollo management side has enabled the secret key, this parameter needs to be passed.
- priority
config.apollo.secret > process.env.APOLLO_ACCESSKEY_SECRET
- apollo hot update
- failed to retry 5 times