Graphql-shield: Query return field permission

Created on 23 Oct 2019  路  2Comments  路  Source: maticzav/graphql-shield

Question about GraphQL Shield

I'm trying to add permissions to certain fields that are returned from a Query.
For example, lets say I have the following structure:

type Query {
  stores: [Store],
  managers: [Manager]
}
type Store {
  id: ID
  name: String
  logo: String
}



md5-ad68507686580ca837d145c0884ec212



type Manager {
  id: ID
  name: String
  store: Store
}



md5-b0a31d2bd6d8c69699c187f98bf3b9a8



shield({
  Query: {
    '*': deny,
    stores: allow,
    managers: {
        logo: deny
    } 
  }
});



md5-02217831918d56364b5c2714a4af1ba5



const isAllowed = rule({ cache: 'no_cache' })(
  async (parent, args, ctx, info) => {
    if(info.operation.selectionSet.selections[0].name.value === 'managers' && info.fieldName === 'logo'){
      return false;
    }
   return true;
  },
);

But I don't think going into the operation.selectionSet.selections is the best approach.

Is there a better approach for what I'm trying to accomplish?

Thanks a lot for your time!

kinfeature

Most helpful comment

I face exactly the same problem

All 2 comments

Hey @xrofa :wave:,

Thank you for opening an issue. We will get back to you as soon as we can. Also, check out our Open Collective and consider contributing financially.

https://opencollective.com/graphql-shield

PS.: We offer priority support for all financial contributors. Don't forget to add priority label once you start contributing :smile:

I face exactly the same problem

Was this page helpful?
0 / 5 - 0 ratings

Related issues

viztor picture viztor  路  6Comments

BjoernRave picture BjoernRave  路  5Comments

tnolan8 picture tnolan8  路  5Comments

devautor picture devautor  路  7Comments

mhaagens picture mhaagens  路  7Comments