Skip to content

Get specific field validation error? #194

Description

@danielmahon

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions