How to use the graphql-shield.not function in graphql-shield

To help you get started, we’ve selected a few graphql-shield examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github maticzav / graphql-shield / examples / basic / index.js View on Github external
async (parent, args, ctx, info) => {
    return ctx.user.role === 'admin'
  },
)

const isEditor = rule({ cache: 'contextual' })(
  async (parent, args, ctx, info) => {
    return ctx.user.role === 'editor'
  },
)

// Permissions

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

const server = GraphQLServer({
  typeDefs,
  resolvers,
  middlewares: [permissions],
  context: req => ({
    ...req,
github WhatTheFar / modularizing-graphql-boilerplate / src / common / ping / ping.permissions.ts View on Github external
import { isAuthenticated } from '@src/auth/auth.rules';
import { not } from 'graphql-shield';

const pingPermissions = {
	Query: {
		ping: not(isAuthenticated),
		pingAuthenticated: isAuthenticated
	}
};

export default pingPermissions;

graphql-shield

GraphQL Server permissions as another layer of abstraction!

MIT
Latest version published 2 years ago

Package Health Score

72 / 100
Full package analysis

Similar packages