Hey guys, I'm using graphql-yoga and for validatio...
# orm-help
m
Hey guys, I'm using graphql-yoga and for validation i'm using joi but when throw back error i'm not able to get error object in response.My code for throwing error is like this: const { GraphQLYogaError } = require("graphql-yoga"); const schema = Joi.object({ name: Joi.string().empty().messages({ "string.empty":
Please provide user name
, }), email: Joi.string().empty().email().messages({ "string.empty":
Please provide email
, "string.email":
Please provide valid email
, }), password: Joi.string().empty().min(8).messages({ "string.empty":
Please provide password
, "string.min":
Password must be atleast 8 character long
, }), }); const { error, value } = schema.validate(args.data, { abortEarly: false, }); const { haveErrors, errors } = createObject(value, error); if (haveErrors) { throw new GraphQLYogaError(JSON.stringify(errors)); } But i'm not getting error object. Plz help if anyone have idea. Thanks in advance
n
Hey Moin 👋 So do you mean that you are throwing the error but not receiving the error in the
catch
block?
m
No i mean i'm not getting errors in response.
n
So you don’t get any errors when joi validates your schema, right?
m
Joi giving me error but when i'm throwing object of error in response that error object i'm not getting in response.
n
How are you sending your response?