question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

field.resolve in Directive is just broken

See original GitHub issue

Have 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:closed
  • Created 4 years ago
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
rico345100commented, Apr 22, 2019

Hello?

1reaction
martijnwalravencommented, Jul 8, 2019

SchemaDirectiveVisitor is part of graphql-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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found