我正在尝试将指令添加到从远程模式扩展一个指令的类型。
const extensionSchema = `
directive @upper on FIELD_DEFINITION
extend type User {
firstname: String @upper
}
`;
// resolvedSchemas is an array of makeRemoteExecutableSchema coming from introspection queries.
resolvedSchemas.push(extensionSchema);
return mergeSchemas({
schemas: resolvedSchemas,
schemaDirectives: {
upper: UpperCaseDirective
}
})
然后我得到:Error: Unknown directive "upper".
。
我想念什么?
我的指令:
const { SchemaDirectiveVisitor } = require("graphql-tools");
const { defaultFieldResolver } = require("graphql");
module.exports = class UpperCaseDirective extends SchemaDirectiveVisitor {
visitFieldDefinition(field) {
const { resolve = defaultFieldResolver } = field;
field.resolve = async function (...args) {
const result = await resolve.apply(this, args);
console.log("RESULTADOOOO", result);
if (typeof result === "string") {
return result.toUpperCase();
}
return result;
};
}
}