graphql-auth icon indicating copy to clipboard operation
graphql-auth copied to clipboard

no resolver when adding directive to scalar field

Open fc-io opened this issue 7 years ago • 1 comments

Tried adding a directive to a field

  type Article {
    id: ID!
    authorId: ID!
    authorName: String!
    articleName: String!
    link: String! @hasScope(scope: ["write:articles"])
    review: Review
  }

...but it throws on oldResolve.call as it does not have a field.resolve. https://github.com/chenkie/graphql-auth/blob/8d474576a13247b03d2862e9307ed4a8b4ea958d/directives/index.js#L68-L72

I'm not sure what would be appropriate here (have never built a graphql server before).

Made it work by making the following additions:

const {defaultFieldResolver} = require('graphql');
// ...
let promise = oldResolve ? oldResolve.call(field, ...arguments) : defaultFieldResolver.call(field, ...arguments)

fc-io avatar Nov 18 '17 19:11 fc-io

        const oldResolve = field.resolve || defaultFieldResolver;

@fc-io : shorten. :D

giautm avatar Nov 22 '17 03:11 giautm