nuwave / nuwave/lighthouse

Where Has Morph Conditions Directive

Open
#1,243 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Where Has Morph Conditions Directive

Would it be possible to create whereHasMorphConditions directive? Such directive would behave as whereHasConditions directive but on morph columns. Laravel has added function on query builder whereHasMorph in version 5.8. Only difference i can now see form classic whereHas is that whereHasMorph takes additional second parameter determining which polymorphic types should be queried with addition of current type in callback function.

Proposed example:

union Userable = EmployeeUser | ParentUser

type EmployeeUser {
    accountNumber: String!
    user: User! @morphOne
}

type ParentUser {
    phone: String!
    user: User! @morphOne
}

type User {
    name: String!
    userable: Userable! @morphTo
}

type Query {
    users(
        userable: _ @whereHasMorphConditions(
        validMorphs: [
           {"EMPLOYEE_USER": "App\\EmployeeUser"}, 
           {"PARENT_USER": "App\\ParentUser"}, 
        ]
        columns: {   
           "accountNumber": ["EMPLOYEE_USER"], 
           "phone": ["PARENT_USER"]
        })
    ): [User]! @all
}

ValidMorphs could restrict and define possible morphed models.
Columns would define column name with array of possible morphed models.

One could then call something like:

query Users {
    users(
        userable: {column: {name: PHONE, model: PARENT_USER}, operator: LIKE, value: "xxx"}
    ) {
    ...
   }
}

PS - this is my first ever proposal of anything in IT world. Love your work.

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 locating the existing whereHasConditions directive and compare its behavior with Laravel's whereHasMorph query-builder API. Define how validMorphs, columns, and the current morph type should work in the proposed GraphQL arguments; done means the new directive supports the demonstrated polymorphic filtering behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, laravel, php
Domain
api, backend-api-design
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.