overblog / GraphQLBundle

This bundle provides tools to build a complete GraphQL API server in your Symfony App.
MIT License
780 stars 223 forks source link

MetadataParser will throw exception if you have Symfony PHP Configurations in your bundle #1152

Closed flaviu-chelaru closed 5 months ago

flaviu-chelaru commented 6 months ago
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Version/Branch dev-master,1.0

I created the following boilerplate https://github.com/cfv1000/symfony-graphql/pull/1

Given a bundle with a PHP Configuration, the command php bin/console graphql:validate will throw a MetadataParser exception at line 261

image

Under the following conditions

The library will break a feature supported by Symfony

GrozescuRares commented 6 months ago

I am also interested into this topic.

Vincz commented 6 months ago

Hi @cfv1000, I downloaded your projet and run it without error.
Then I changed the graphql.yaml file into a graphql.php file like this:

<?php

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use function Symfony\Component\DependencyInjection\Loader\Configurator\param;

return static function (ContainerConfigurator $container): void {
    $container->extension('overblog_graphql', [
        // when using the param() function, you only have to pass the parameter name...
        'definitions' => [
            'schema' => [
                'query' => 'RootQuery'
            ],
            'mappings' => [
                'types' => [
                    ['type' => 'attribute', 'dir' => '%kernel.project_dir%/src/ApplicationBundle', 'suffix' => null]
                ]
            ]
        ]
    ]);
};

and run it again, and didn't get any error.
Do you mind to update your project with the configuration that leads to the error?

flaviu-chelaru commented 6 months ago

@Vincz - there is an open pull request - if you change the branch from main to that pull request branch, and run the command again you should get the same error as i had

Vincz commented 6 months ago

Ok, I understand. When we use a mapping with attributes, we expect the configured directories to contain only PHP files containing classes.
That's why you get this error.
One solution is to exclude this directories from the mapping parsing or be more specific on the directories containing your mapping.
We could also check if the class does exist before trying to parse it in the MetadataParser. Feel free to submit a PR if you want, otherwise, I'll add this later.