nuwave / nuwave/lighthouse

Unify argument validation

Open
#1,751 9 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion enhancement
Dominant language
PHP
Stars
3.5k
Forks
468
Avg merge
3h 9m
Merged PRs (30d)
2

Description

What problem does this feature proposal attempt to solve?

The native spec-compliant validation performed by webonyx/graphql-php (!, scalars) and Lighthouse/Laravel (@rules, @validator) run in different phases and return different error shapes.

This has lead to number of issues:

Which possible solutions should be considered?

type Query {
  foo(
    nonNull: ID!
    customScalar: CustomScalar
    required: String @rules(apply: ["required"]
    email: String @rules(apply: ["email"]
  ): ID
}

query EverythingWrong {
  # Missing nonNull and required
  foo(customScalar: "wrong-format", email: "not-an-email")
}

An optimal solution would combine all kinds of validation in a single, unified step and return a consistent format for which inputs failed validation.

{
  "errors": [
    {
      "message": "Validation failed for the field [foo]",
      "extensions": {
        "validation": {
          "nonNull": ["The nonNull field is required."],
          "customScalar": ["The customScalar field must be a valid CustomScalar."],
          "required": ["The required field is required."],
          "email": ["The email field must be a valid email."]
        }
      }
    }
  ]
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing how webonyx/graphql-php handles native validation and how Lighthouse/Laravel process @rules and @validator, then compare the related issues #345 and #262. Use the sample schema and query to trace the separate phases. Done should be defined as a consistent validation step and error shape covering all listed input failures.

Written by the indexing model from the issue text.

Assessment

Tech stack
laravel, php
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.