Я пытаюсь реализовать пользовательскую директиву с сервером apollo. Я взял пример с официального сайта.
Мой запрос похож на ниже:
directive @upper on FIELD_DEFINITION
type Query {
hello: String @upper
}
Мой распознаватель похож на ниже:
Query:{
async hello(){
return "hello world";
}
}
Вот мой сервер apollo config для пользовательской директивы:
const { ApolloServer, SchemaDirectiveVisitor } = require('apollo-server-express');
const { defaultFieldResolver } = require("graphql");
class UpperCaseDirective extends SchemaDirectiveVisitor {
visitFieldDefinition(field) {
const { resolve = defaultFieldResolver } = field;
field.resolve = async function (...args) {
const result = await resolve.apply(this, args);
if (typeof result === "string") {
return result.toUpperCase();
}
return result;
};
}
}
const server = new ApolloServer({
schema,
schemaDirectives: {
upper: UpperCaseDirective
},
introspection: true,
playground: true,
cors: cors()
});
Вывод, который я всегда получаю:
{
"data": {
"hello": "hello world"
}
}
Почему пользовательская директива не активирована? Почему вывод не в верхнем регистре?