mickhansen / graphql-sequelize

GraphQL & Relay for MySQL & Postgres via Sequelize
MIT License
1.9k stars 172 forks source link

Support Graphql-Shield #641

Closed ianberdin closed 5 years ago

ianberdin commented 5 years ago

Hello. Is it support?

I tried like this:

const Sequelize = require('sequelize')
const { applyMiddleware } = require('graphql-middleware')
const { resolver, attributeFields } = require('graphql-sequelize')
const { rule, shield, and, or, not, allow } = require('graphql-shield')
const {
  GraphQLObjectType,
  GraphQLSchema,
  GraphQLNonNull,
  GraphQLInt,
  GraphQLString,
  GraphQLList,
} = require('graphql')

const User = db.define('user', {
  firstName: {
    type: Sequelize.STRING
  },
  lastName: {
    type: Sequelize.STRING
  },
})

let userType = new GraphQLObjectType({
  name: 'User',
  description: 'A user',
  fields: attributeFields(User)
})

let schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'RootQueryType',
    fields: {
      user: {
        type: userType,
        args: {
          id: {
            description: 'id of the user',
            type: new GraphQLNonNull(GraphQLInt)
          }
        },
        resolve: resolver(User)
      },
    }
  }),
})

const isAuthenticated = rule()(async ( parent, args, ctx, info ) => {
  return true
})

const permissions = shield({
  query: {
    user: isAuthenticated,
  }
})

schema = applyMiddleware(schema, permissions)

But it's have error: It seems like you have applied rules to ${typeErrors} types but Shield cannot find them in your schema.

mickhansen commented 5 years ago

graphql-sequelize has no graphql-shield specific code