Skip to content

Using custom validators #3941

Answered by rmosolgo
BrandonMathis asked this question in Q&A
Discussion options

You must be logged in to vote

I guess what counts is, that validator has to be registered before any definitions actually use it.

A couple options:

  • Put it in an initializer, so you can be sure that's run before any application code is loaded
  • Put it in iso_8601_duration_validator.rb, and add require "graphql/(your path)/iso_8601_duration_validator.rb" to any files that use that validator. That would make sure that validator was loaded and installed before those types are configured.
  • Probably, you could put that line before you schema class definition (eg app/graphql/my_app_schema.rb, before the class definition). That will work, assuming that none of the types that use the validator are referenced outside the schema. …

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by BrandonMathis
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants