@eddeee888/gcg-typescript-resolver-files
Version:
This [GraphQL Code Generator](https://www.the-guild.dev/graphql/codegen) plugin creates resolvers given GraphQL schema.
59 lines • 2.39 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleGraphQLScalarType = void 0;
const utils_1 = require("../utils");
const graphQLScalarType = 'GraphQLScalarType';
const handleGraphQLScalarType = ({ fieldFilePath, isFileAlreadyOnFilesystem, resolverName, normalizedResolverName, moduleName, relativePathFromBaseToModule, }, { result, config: { resolverGeneration, emitLegacyCommonJSImports } }) => {
if (!(0, utils_1.isMatchResolverNamePattern)({
pattern: resolverGeneration.scalar,
value: normalizedResolverName.withModule,
}) &&
!isFileAlreadyOnFilesystem) {
utils_1.logger.debug(`Skipped Scalar resolver generation: "${normalizedResolverName.withModule}". Pattern: "${resolverGeneration.scalar}".`);
return;
}
const resolverTypeImportDeclaration = (0, utils_1.printImportLine)({
isTypeImport: false,
module: 'graphql',
moduleType: 'module',
namedImports: [graphQLScalarType],
emitLegacyCommonJSImports,
});
const variableStatement = `export const ${resolverName} = new ${graphQLScalarType}({
name: '${resolverName}',
description: '${resolverName} description',
serialize: (value) => {
/* Implement logic to turn the returned value from resolvers to a value that can be sent to clients */
},
parseValue: (value) => {
/* Implement logic to parse input that was sent to the server as variables */
},
parseLiteral: (ast) => {
/* Implement logic to parse input that was sent to the server as literal values (string, number, or boolean) */
},
});`;
result.files[fieldFilePath] = {
__filetype: 'scalarResolver',
filesystem: {
type: 'virtual',
contentUpdated: false,
},
content: `
${resolverTypeImportDeclaration}
${variableStatement}`,
mainImportIdentifier: resolverName,
meta: {
moduleName,
relativePathFromBaseToModule,
normalizedResolverName,
resolverTypeImportDeclaration,
variableStatement,
resolverType: {
baseImport: graphQLScalarType,
final: graphQLScalarType,
},
},
};
};
exports.handleGraphQLScalarType = handleGraphQLScalarType;
//# sourceMappingURL=handleGraphQLScalarType.js.map
;