Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'),
};
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),
});
}