Using directives #1258
-
I am trying to imlement directives with type-graphql: import {getDirective, MapperKind, mapSchema} from "@graphql-tools/utils";
import {GraphQLSchema} from "graphql";
// ... other imports
function directiveTransformer(schema: GraphQLSchema, directiveName: string) {
return mapSchema(schema, {
// Executes once for each object field definition in the schema
[MapperKind.OBJECT_FIELD]: (fieldConfig) => {
const directive = getDirective(schema, fieldConfig, directiveName);
if (directive) {
console.log({directive})
return fieldConfig;
}
}
});
};
@Resolver()
export class CustomResolver {
@Directive("@auth(requires: ADMIN)")
@Query((_returns) => String, { nullable: true })
async testQuery() {
return 'It is query';
}
}
const schema = buildSchemaSync({
resolvers: [CustomResolver],
});
directiveTransformer(schema, "auth") The problem: it does not detect directive at all...
Will be very thankful for the answers how to use it properly. Update: I tried: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
You need to create |
Beta Was this translation helpful? Give feedback.
You need to create
new GraphQLDirective
with the definition side, not only the graphql tools implementation part.