graphql-yup-middleware icon indicating copy to clipboard operation
graphql-yup-middleware copied to clipboard

support query validation

Open meodemsao opened this issue 6 years ago • 5 comments

i try use this lib with validate query argument but seem not work

meodemsao avatar Oct 29 '19 04:10 meodemsao

Hey @meodemsao, I will need more details/sample code to understand the issue

JCMais avatar Oct 29 '19 12:10 JCMais

everything run but not return input is invalid, i using many lib but still can't valid input maybe be cause i use with sequelize graphql

meodemsao avatar Oct 31 '19 09:10 meodemsao

@JCMais i using with apollo 2.x

const middleware = [yupMiddleware()]

// schema
const schema = makeExecutableSchema({
  typeDefs,
  resolvers,
  schemaDirective: {
    rateLimitDirective
  }
})

const schemaWithMiddleware = applyMiddleware(schema, ...middleware)
import { resolver, createConnectionResolver } from 'graphql-sequelize'
import { validator, validate } from 'graphql-validation'
import * as yup from 'yup'

export default {
  category: resolver((parent, args, context, info) => context.models.Category),

  categories: {
    validationSchema: yup.object().shape({
      limit: yup.number().required().min(1).max(10)
    }),
    resolve: resolver((parent, args, context, info) => context.models.Category)
  },

  categoriesConnection: createConnectionResolver({
    target: (parent, args, context, info) => context.models.Category,
    where: (findOptions, args) => args
  }).resolveConnection
}

schema.graphql

type FieldValidationError {
  field: String!
  errors: [String!]!
}

type MutationValidationError {
  message: String!
  details: [FieldValidationError!]!
}

# Write your query or mutation here
query{
 	categories(limit: 40){
    id
    name
  }
}

but don't return error

meodemsao avatar Nov 16 '19 03:11 meodemsao

Hi @meodemsao, I'm not having time to look into that, however if you are able to share a full sample code, runnable, I may be able to run it locally and see If I can find what is wrong.

JCMais avatar Nov 18 '19 11:11 JCMais

@JCMais thank, i using graphql-shield for my project

meodemsao avatar Nov 18 '19 13:11 meodemsao