youshido-php/GraphQLBundle

Symfony 4 support

enumag opened this issue ยท 11 comments

Symfony 4 supports bundle-less applications (and it's considered best-practice).

The configure command from this bundle doesn't work with this at the moment so I don't know how to initialize graphql in my project.

Also the explorer doesn't work. It throws this error:

Unable to find template "GraphQLBundle:Feature:explorer.html.twig" (looked into: <projectPath>/templates, <projectPath>/vendor/symfony/twig-bridge/Resources/views/Form).

Running into this as well after following the instructions in the readme

Next step would be to link assets for GraphiQL Explorer by executing:

php bin/console assets:install --symlink
Now you can access it at http://localhost:8000/graphql/explorer

screen shot 2017-12-31 at 3 27 38 pm

Having exactly the same issue, followed the instructions on the readme.

explorer-error

I got it working by adding the following to my config.yml:

framework:
    templating:
        engines: ['twig']
symm commented

r.e. the configure command not working, it looks like the bundle is using functionality which was deprecated in Symfony 3.4 and removed in 4.0:

[2018-02-14 10:01:47] php.INFO: User Deprecated: Auto-registration of the command "Youshido\GraphQLBundle\Command\GraphQLConfigureCommand" is deprecated since Symfony 3.4 and won't be supported in 4.0. Use PSR-4 based service discovery instead. {"exception":"[object] (ErrorException(code: 0): User Deprecated: Auto-registration of the command "Youshido\GraphQLBundle\Command\GraphQLConfigureCommand" is deprecated since Symfony 3.4 and won't be supported in 4.0. Use PSR-4 based service discovery instead. at /Users/gareth.jones/Github/driveplan/driveplan-api/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Bundle/Bundle.php:190)"} []

symm commented

I'm also seeing the following deprecation warnings on Symfony 3.4 related to the GraphQLController when using service config:

graphql:
    schema_class: "AppBundle\\GraphQL\\Schema"
    logger: "@logger"

and parameters

graphql.execution_context.class: AppBundle\GraphQL\ExecutionContext

1x: Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should alias the "AppBundle\GraphQL\Schema" service to "Youshido\GraphQL\Schema\AbstractSchema" instead.

1x: Checking for the initialization of the "graphql.schema" private service is deprecated since Symfony 3.4 and won't be supported anymore in Symfony 4.0.

1x: The "graphql.schema" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0.

1x: The "graphql.processor" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.

In order to make this work in sf4 you need to:

  1. Install the templating component

     composer require templating
    
  2. Configure the templating in your framework.yml as mentioned in #68 (comment)

  3. Manually create a schema file in src/GraphQL/Schema.php with the following content:

<?php

declare (strict_types=1);

namespace App\GraphQL;

use Youshido\GraphQL\Schema\AbstractSchema;
use Youshido\GraphQL\Config\Schema\SchemaConfig;
use Youshido\GraphQL\Type\Scalar\StringType;

final class Schema extends AbstractSchema
{
    public function build(SchemaConfig $config)
    {
        $config->getQuery()->addFields([
            'hello' => [
                'type'    => new StringType(),
                'args'    => [
                    'name' => [
                        'type' => new StringType(),
                        'defaultValue' => 'Stranger'
                    ]
                ],
                'resolve' => function ($context, $args) {
                    return 'Hello ' . $args['name'];
                }
            ]
        ]);
    }
}
  1. create a file graphql.yaml in your config folder with the following contents:
graphql:
  schema_class: 'App\GraphQL\Schema'
  1. fix the service related issues by re-declaring the services in my services.yml as following:
    graphql.schema:
      public: true
      synthetic: true

    graphql.processor:
      public: true
      class: Youshido\GraphQLBundle\Execution\Processor
      arguments:
        $executionContext: '@graphql.execution_context'
      calls:
        - [setSecurityManager, ['@graphql.security_manager']]

Perhaps I'll run into some other issues further on, but I'll try to document them here

In case someone else encounters the same:
After following the steps layed out by mvriel i got a "Schema class does not exist" error message.
The fix is to create the file at point 4 in the config/packages folder instead of the config folder.

Also it would be great if you create recipe for automatic installation

After installation I've got following error:
The service "graphql.security_manager" has a dependency on a non-existent service "security.authorization_checker".

I resolved it by running:
composer require symfony/security-bundle

BTW for normal loading of explorer you must execute:
bin/console assets:install --symlink --relative public

I put the pieces of the puzzle together at GraphQL Demo for Symfony 4

Symfony 4
the solution is to add this two lines on ### framework.yaml :
framework:
secret: '%env(APP_SECRET)%'
templating:
engines: ['twig']