Graphiti icon indicating copy to clipboard operation
Graphiti copied to clipboard

Can't validate request

Open itayAmza opened this issue 4 years ago • 1 comments

Following Vapor's Validation API, I'm not really sure what is the right way to validate arguments in Graffiti. I've made the arguments struct conform to Validatable but since I cannot call validate before it's being decode, I'm always getting 'field is required' error.

itayAmza avatar Sep 21 '21 17:09 itayAmza

Hey @itayAmza, I don't think there's a good way to call validate(_ decoder: Decoder) before decode, since fields automatically define the decode block here: https://github.com/GraphQLSwift/Graphiti/blob/af903a243862c6427935677b91f67df0c21f2a71/Sources/Graphiti/Field/Field/Field.swift#L55

I think you have a few options:

  1. Code your own after-the-fact validation and place the logic in your resolver function, throwing errors when it fails
  2. Drop down into https://github.com/GraphQLSwift/GraphQL, where you have full control over argument decoding in the resolvers

Hope that helps!

NeedleInAJayStack avatar Oct 08 '21 20:10 NeedleInAJayStack