How to use the @graphql-modules/core.ModuleConfig function in @graphql-modules/core

To help you get started, we’ve selected a few @graphql-modules/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github accounts-js / accounts / packages / graphql-api / src / utils / context-builder.ts View on Github external
export const context = (moduleName: string) => async (
  { req }: AccountsRequest,
  _: any,
  { injector }: ModuleSessionInfo
) => {
  if (!req) {
    return {
      ip: '',
      userAgent: '',
    };
  }

  const config: AccountsModuleConfig = injector.get(ModuleConfig(moduleName));
  const headerName = config.headerName || 'Authorization';
  let authToken = (req.headers[headerName] || req.headers[headerName.toLowerCase()]) as string;
  authToken = authToken && authToken.replace('Bearer ', '');
  let user;

  if (authToken && !config.excludeAddUserInContext) {
    try {
      user = await config.accountsServer.resumeSession(authToken);
    } catch (error) {
      // Empty catch
    }
  }

  let userAgent: string = (req.headers['user-agent'] as string) || '';
  if (req.headers['x-ucbrowser-ua']) {
    // special case of UC Browser
github Urigo / graphql-modules / examples / di / src / modules / info / providers / info.ts View on Github external
constructor(
    @inject(ModuleConfig('info')) private config: any,
    @inject(CommunicationBridge)
    private communicationBridge: CommunicationBridge,
    @inject(AppInfo) private app: AppInfo,
  ) {}