RisingStack / graffiti-mongoose

⚠️ DEVELOPMENT DISCONTINUED - Mongoose (MongoDB) adapter for graffiti (Node.js GraphQL ORM)
https://risingstack-graffiti.signup.team/
MIT License
382 stars 52 forks source link

Get specific field validation error? #194

Open danielmahon opened 7 years ago

danielmahon commented 7 years ago

Overview of the Issue

@tothandras Sorry to raise the dead (#66) but do you have a working example of how to get the individual field validation errors for a mutation? The only error graphql seems to give back is "modelName validation failed". I see where mongoose is calling that error but I can't find why it's calling THAT error and not the specific one for the field. Thanks for any help.

Reproduce the Error

GraphQL POST:

// my variables
{
  "input": {
    "name": ""
  }
}
// my mutation
mutation addModel($input: addModelInput!) {
  addModel(input: $input) {
    changedDepositionEdge {
      node {
        _id
        name
      }
    }
  }
}

Returns:

{
  "data": {
    "addModel": null
  },
  "errors": [
    {
      "message": "Model validation failed",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ]
    }
  ]
}

Input schema(s):

...
  name: {
    type: Types.Text,
    initial: true,
    required: [true, 'Name is required!'],
    label: 'Display Name',
  },
...

Node version: 6.3.1 Graffiti-Mongoose version: 5.3.0

Related Issues

66

Suggest a Fix

Does mongoose call multiple errors upon bad validation? Are we only checking for one?