Skip to content

GraphQLite attempts to load non-class files, resulting in weird errors  #659

Closed
@oprypkhantc

Description

@oprypkhantc

Hey.

We have a modules/ folder that maps to Modules\ PSR-4 namespace. This namespace was also added to be globbed by graphqlite using ->addTypeNamespace('Modules\\') and -> addControllerNamespace('Modules\\'). That namespace also contains non-class files (such as lang files and others), as well as pre-8.0 enums that require autoloading before they can be used.

If you try to blindly require these files, you'll get errors as those non-class files are meant to be loaded from a specific context, and those enums require a special autoloader to call ::initialize() static method on them.

The problem is that GraphQLite does exactly that - blindly load all files using require_once that appear as classes to it. Obviously, this is not desired, as it forces you to list every class separately in calls to ->addTypeNamespace() and ->addControllerNamespace() to avoid loading what it can't load.

This is happening because of this fix: https://github.com/thecodingmachine/graphqlite/blob/master/src/Utils/Namespaces/NS.php#L55. It was done specifically to avoid issues with autoloading, and to allow autoloading incorrectly namespaced classes.

Instead of doing that, GraphQLite can instead attempt to load a class through autoloading and simply skip it if it fails. This will break loading of classes that have incorrect namespaces.

What do you think @oojacoboo? I'll draft a PR if it's an acceptable BC.

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