field.resolve in Directive is just broken
See original GitHub issueHave a schema like this:
extend type Query {
paymentList(filter: String skip: Int pageSize: Int): PaymentList @auth
}
directive @auth on FIELD_DEFINITION
And have directive resolver:
import { defaultFieldResolver } from 'graphql';
import { SchemaDirectiveVisitor } from 'apollo-server';
class AuthDirective extends SchemaDirectiveVisitor {
visitFieldDefinition(field) {
const { resolve = defaultFieldResolver } = field;
const { role } = this.args;
console.log('visit field def');
field.resolve = async function(...args) {
console.log('field.resolve');
};
}
}
export default AuthDirective;
Used in makeExecutableSchema:
import AuthDirective from './directives/Auth';
export const schema = makeExecutableSchema({
typeDefs,
resolvers,
schemaDirectives: {
auth: AuthDirective
}
});
When I run the server, I can see text from console.log(‘visit field def’);, however when I query from client, inside of field.resolve never invoking.
Using Apollo-Server @2.0.7 with Koa@2.6 and Apollo-Server-Koa@2.0.6.
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (2 by maintainers)
Top Results From Across the Web
GraphQL: field.resolve() result is undefined inside directive
One particular thing I found is that field.resolve, comes with 4 args, the first of them is always undefined, not sure if that...
Read more >Field arguments vs. directives in GraphQL
What's the difference between GraphQL field arguments and directives? Brush up on their unique capabilities and uses in this tutorial.
Read more >Entities in Apollo Federation
In a federated graph, an entity is an object type that can resolve its fields across multiple subgraphs. Each subgraph can contribute different...
Read more >Troubleshoot broken references - Visual Studio (Windows)
The inability to find the referenced component is the primary trigger for the error, but there are several situations in which a reference...
Read more >Top 18 Most Common AngularJS Developer Mistakes
There are two main reasons: you can't apply two isolated scope directives to an element, and you may encounter issues with nesting /...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello?
SchemaDirectiveVisitor
is part ofgraphql-tools
, so you may want to open an issue there. Note that we’re investigating a new approach for schema directives however, and will likely deprecate this API in the future.