GraphQLBundle icon indicating copy to clipboard operation
GraphQLBundle copied to clipboard

Symfony 4 support

Open enumag opened this issue 7 years ago • 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.

enumag avatar Nov 20 '17 10:11 enumag

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).

enumag avatar Nov 20 '17 11:11 enumag

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

justinlevi avatar Dec 31 '17 20:12 justinlevi

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

explorer-error

Imagica avatar Feb 01 '18 10:02 Imagica

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

framework:
    templating:
        engines: ['twig']

Imagica avatar Feb 01 '18 11:02 Imagica

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 avatar Feb 14 '18 10:02 symm

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.

symm avatar Feb 14 '18 10:02 symm

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 https://github.com/Youshido/GraphQLBundle/issues/68#issuecomment-362233618

  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

mvriel avatar Feb 23 '18 10:02 mvriel

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.

Pirokiko avatar Apr 12 '18 08:04 Pirokiko

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

HEKET313 avatar Jun 28 '18 07:06 HEKET313

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

programarivm avatar Jul 08 '18 20:07 programarivm

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

KerkniMohamed avatar Jan 24 '19 08:01 KerkniMohamed