Currently, I am using Apollo Server to construct a graphql based server that communicates with a MongoDB instance. My goal is to ensure that if the client provides a value for a field that has a graphql type of ID, the value must be a valid mongo ObjectId. Even though mongoose has a utility function to check this, my main concern is to receive a validation error at the graphql level (i.e., a 400) if the value is not a valid ObjectId. I want to avoid encountering a 500 error later in the process when attempting to use that value as an ObjectId and I do not wish to validate the value multiple times within the server.
In essence, I aim to implement validation logic at the graphql level specifically for the ID scalar type, if that clarifies things.