Graphqlbundle: Graphql dump schema command works only once in v0.12

Created on 9 Jul 2019  路  3Comments  路  Source: overblog/GraphQLBundle

| Q | A
| ---------------- | -----
| Bug report? | yes
| Feature request? | no
| BC Break report? | yes
| RFC? | yes
| Version/Branch | 0.12

Hello,
When I tried upgrading to the version 0.12 from the version 0.11, I found that the Symfony command to dump the schema doesn't work anymore when the cache is already loaded.

Here are the reproducing steps:

rm -rf var/cache/*'
php bin/console graphql:dump-schema # this works
php bin/console graphql:dump-schema # this doesn't work

Here's the error message:

PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "QueryType" from namespace "Overblog\GraphQLBundle\__DEFINITIONS__".
Did you forget a "use" statement for another namespace? in /var/www/-/vendor/overblog/graphql-bundle/src/Definition/Builder/TypeFactory.php:26
Stack trace:
#0 /var/www/-/var/cache/dev/Container1CfP0yW/getQueryTypeService.php(11): Overblog\GraphQLBundle\Definition\Builder\TypeFactory->create('Overblog\\GraphQ...')
#1 /var/www/-/var/cache/dev/Container1CfP0yW/srcApp_KernelDevDebugContainer.php(809): require('/var/www/theesc...')
#2 /var/www/-/vendor/symfony/dependency-injection/Container.php(243): Container1CfP0yW\srcApp_KernelDevDebugContainer->load('getQueryTypeSer...')
#3 /var/www/-/vendor/symfony/dependency-injection/Container.php(225): Symfony\Component\DependencyInjection\Container->make('Overblog\\GraphQ...', 1)
#4 [internal function]: Symfony\Component\DependencyInjection\Container->get('Overblog\ in /var/www/-/vendor/overblog/graphql-bundle/src/Definition/Builder/TypeFactory.php on line 26

And here's my config/packages/graphql.yaml file:

overblog_graphql:
    definitions:
        schema:
            query: Query
            mutation: Mutation
        mappings:
            auto_discover: false
            types:
                -
                    type: yaml
                    dir: "%kernel.project_dir%/config/graphql/types"
                    suffix: ~
                -
                    type: yaml
                    dir: "%kernel.project_dir%/src"
                    suffix: ".type"

services:
    _defaults:
        autowire: true
        public: true

    App\GraphQL\:
        resource: '../../src/GraphQL'

And my Kernel.php:

    protected function build(ContainerBuilder $container)
    {
        $container->registerForAutoconfiguration(ResolverInterface::class)->addTag('overblog_graphql.resolver');
        $container->registerForAutoconfiguration(MutationInterface::class)->addTag('overblog_graphql.mutation');
    }

My Query.yaml file is in config/graphql/types and this command worked normally in 0.11.

By digging a bit, I think it's possible that it comes from https://github.com/overblog/GraphQLBundle/pull/505 but I'm not sure.

bug

Most helpful comment

Thanks @mcg-web it works normally now!

All 3 comments

hi @SebastienTainon I try adding a test to cover you case but didn't have the same issue, here is my test:

    public function testManyDump()
    {
        $file = $this->cacheDir.'/schema.json';

        $input = [
            '--file' => $file,
        ];
        $this->assertCommandExecution(
            $input,
            __DIR__.'/fixtures/schema.json',
            $file,
            'json'
        );
        $this->assertCommandExecution(
            $input,
            __DIR__.'/fixtures/schema.json',
            $file,
            'json'
        );
    }

Can you try this with bin/console graphql:debug please ?

I'm not sure what you expect me to do here?

I've tried adding this test to tests/Functional/Command/GraphDumpSchemaCommandTest.php (after cloning the GraphQLBundle) and I confirm that it runs without exception, so I guess the issue comes from the bundle configuration or usage, though I haven't been excentric in this.

I've also run bin/console graphql:debug in my project, and I can confirm that this command works normally even multiple times, here's an excerpt:

GraphQL Types Services
======================
 --------------------------------------------------------------------------------- -------------------------------------- 
  solution id                                                                       aliases                               
 --------------------------------------------------------------------------------- -------------------------------------- 
Overblog\GraphQLBundle\__DEFINITIONS__\QueryType                                  Query                                 
Overblog\GraphQLBundle\__DEFINITIONS__\RateSessionInputType                       RateSessionInput                      
Overblog\GraphQLBundle\__DEFINITIONS__\RatingInputType                            RatingInput

The problem in bin/console graphql:dump-schema seems to be that the cached classes in var/cache/dev/overblog/graphql-bundle/__definitions__ are not auto-loaded correctly and thus not found when the schema is dumped. However, the GraphQL executor works perfectly when I run queries or mutations.

If you want me to test something in particular, feel free to ask.

Thanks @mcg-web it works normally now!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

apoberez picture apoberez  路  3Comments

akomm picture akomm  路  6Comments

JuanWilde picture JuanWilde  路  4Comments

Alsciende picture Alsciende  路  5Comments

VincentClair picture VincentClair  路  4Comments