Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support functions in schema security key. #544

Merged
merged 1 commit into from
Jun 9, 2019

Conversation

Pavel910
Copy link
Collaborator

@Pavel910 Pavel910 commented Jun 9, 2019

Related Issue

CMS schema supports addition of typeDefs and resolvers via plugins. However, we must also be able to add security rules via plugins. At this point security only supported an object as its value, and as such it was interpreted too early for other plugins to be registered.

Your solution

This PR adds the ability to assign a function to schema plugin security key, and it will be executed at runtime, when all plugins have already been registered, and so we'll be able to use our plugin system to add graphql-shield rules.

{
  // ... other schema keys
  security: () =>
    merge(
      {
        shield: {
          CmsQuery: {
            getMenu: hasScope("cms:menu:crud")
          },
          CmsMutation: {
            createMenu: hasScope("cms:menu:crud")
          }
        }
      },
      // Fetch plugins and merge with current security value
      ...getPlugins("cms-schema").map(pl => pl.security)
    );
}

How Has This Been Tested?

Manual testing.

@Pavel910 Pavel910 self-assigned this Jun 9, 2019
@Pavel910 Pavel910 merged commit a27fa88 into development Jun 9, 2019
@Pavel910 Pavel910 deleted the feat/security-as-function branch October 27, 2019 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant