How to use the @graphql-codegen/visitor-plugin-common.parseMapper function in @graphql-codegen/visitor-plugin-common

To help you get started, we’ve selected a few @graphql-codegen/visitor-plugin-common 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 dotansimha / graphql-code-generator / packages / plugins / typescript / resolvers / src / index.ts View on Github external
if (hasScalars()) {
    imports.push('GraphQLScalarType', 'GraphQLScalarTypeConfig');
  }

  if (showUnusedMappers && unusedMappers.length) {
    console['warn'](`Unused mappers: ${unusedMappers.join(',')}`);
  }

  const prepend: string[] = [];

  if (imports.length) {
    prepend.push(`import { ${imports.join(', ')} } from 'graphql';`);
  }

  if (config.customResolveInfo) {
    const parsedMapper = parseMapper(config.customResolveInfo);
    if (parsedMapper.isExternal) {
      if (parsedMapper.default) {
        prepend.push(`import GraphQLResolveInfo from '${parsedMapper.source}'`);
      }
      prepend.push(`import { ${parsedMapper.import} ${parsedMapper.import !== 'GraphQLResolveInfo' ? 'as GraphQLResolveInfo' : ''} } from '${parsedMapper.source}';`);
    } else {
      prepend.push(`type GraphQLResolveInfo = ${parsedMapper.type}`);
    }
  }

  prepend.push(...mappersImports, ...visitor.globalDeclarations);

  return {
    prepend,
    content: [header, resolversTypeMapping, resolversParentTypeMapping, ...visitorResult.definitions.filter(d => typeof d === 'string'), getRootResolver(), getAllDirectiveResolvers()].join('\n'),
  };
github dotansimha / graphql-code-generator / packages / plugins / java / resolvers / src / visitor.ts View on Github external
constructor(rawConfig: JavaResolversPluginRawConfig, private _schema: GraphQLSchema, defaultPackageName: string) {
    super(rawConfig, {
      mappers: transformMappers(rawConfig.mappers || {}),
      package: rawConfig.package || defaultPackageName,
      defaultMapper: parseMapper(rawConfig.defaultMapper || 'Object'),
      className: rawConfig.className || 'Resolvers',
      listType: rawConfig.listType || 'Iterable',
      scalars: buildScalars(_schema, rawConfig.scalars, JAVA_SCALARS),
    });
  }