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.

how to merge multi permission into one?

See original GitHub issue

follow the README, we have to defined the big permission object like this:

const permissions = shield({
  Query: {
    frontPage: not(isAuthenticated),
    fruits: and(isAuthenticated, or(isAdmin, isEditor)),
    customers: and(isAuthenticated, isAdmin)
  },
  Mutation: {
    addFruitToBasket: isAuthenticated,
  },
  Fruit: isAuthenticated,
  Cusomer: isAdmin
})

could you give something like merge

const permissions = mergeShield({
    1Resolve,
    2Resolve,
    ...
});

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
meebixcommented, Apr 16, 2019

@leonelpena and others who come across this issue… To accomplish what the OP and myself are looking to do, you can use a library called “assign-deep”. https://www.npmjs.com/package/assign-deep.

It merges the permissions together correctly allowing the following:

// file1.js
export default {
  Query: {
    getSecurityQuestions: allow,
  },
  SecurityQuestion: {
    shortName: allow,
  },
};
// file2.js
export default {
  Query: {
    getUser: allow,
  },
};
// permissionsArray is an array of the permissions above like...
// [{Query: {getSecurityQuestions: allow}}, {Query: {getUser: allow}}]

import assign from 'assign-deep';

const permissions = shield(assign(...permissionsArray), {
  debug: config.get('graphql.debug'),
  fallbackRule: deny,
  fallbackError: ApiError('UNAUTHORIZED'),
});

This produces the correct output that graphql-shield needs to operate.

1reaction
maticzavcommented, May 30, 2018

I have given a bit more thought to your problem. I am not sure this is your case, but here are two things that you can do.

1.

Because shield accepts a JSON object as an argument defining your schema, you could use Object.assign or ES6 merge syntax to merge your permissions into one.

// Query.allAuthStuffPermissions.ts
export const permissions = {
  login: noAuth,
  somethingElse: auth
}

// Query.somethingElseEquallyImportant.ts
export const permissions = {
  fruits: complexRule,
  vegies: simpleRule
}

// index.ts
import { permissions as permissions1 } from 'Query.allAuthStuffPermissions.ts'
import { permissions as permissions2 } from 'Query.somethingElseEquallyImportant.ts'

export default shield({
  Query: {
    ...permissions1,
    ...permissions2,
  }
})

2.

You can logically combine your permissions using logic operators. Available operators are and, or and not. You can read more about them here https://github.com/maticzav/graphql-shield#and-or-not

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to merge multi permission into one? · Issue #50 - GitHub
It merges the permissions together correctly allowing the following: // file1.js export default { Query: { getSecurityQuestions: allow, } ...
Read more >
Merge 3 Permission Sets into 1 - Salesforce Stack Exchange
This answer assumes you are managing the permission sets in a version control system and pushing/deploying changes to your org from your ...
Read more >
Is there a way to merge the files/permissions from one user on a
Is there a way to merge the files/permissions from one user on a computer to another user on the same computer WITHOUT overwriting...
Read more >
linux - changing multiple permissions with one single command
I was wondering if there is a way to combine these three commands into one without using octal numbers. linux · command-line ·...
Read more >
Merge Permission Sets - IdeaExchange - Salesforce
merge permission sets into Profiles: permanently alter the Profile by incorporating all the permissions in the permission set; merge permission sets into other ......
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