nuwave / nuwave/lighthouse

Allow wildcard(*) in config namespace

Open
#2,181 2 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

What problem does this feature proposal attempt to solve?

We can add a namespace to the config file and allow the lighthouse to search there for the classes. The namespaces can only be a folder and the class must be inside the folder. If the folder is nested then we have to add all of them. By adding wildcard functionality we can let the client just add the parent namespace, then we test the class name against all the files inside the main folder or nested folders.

|-- app
    |-- Models
        |-- Posts
            |--foo.php
        |-- Users
            |--bar.php
        |--baz.php

With the current solution:

'namespaces' => [
        'models' => ['App', 'App\\Models',  'App\\Models\\Posts',  'App\\Models\\Users'],
    ],

With the proposed feature:

'namespaces' => [
        'models' => ['App', 'App\\Models\\*'],
    ],

Which possible solutions should be considered?

If the wildcard exists in the namespace, then get all the directories inside the path with $fileSystem->directories($path). Try this again for the nested folders. Forming and testing the existence of the class will be the same as before.

Open questions

  1. Is there any predefined way to convert a namespace to the path?
  2. If the answer is no for 1, based on the PSR-4, are these correct?
Namespace Path
App\Models\* app/Models
App\Models\Posts\* app/Models/Posts

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 tracing the configuration namespace handling and the filesystem directories($path) call mentioned in the proposal. Check how PSR-4 namespaces are currently converted to paths and how class existence is tested. Done means a wildcard namespace searches its directory and nested directories while preserving existing non-wildcard behavior, with tests covering both examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
laravel, php
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.