Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfony 4 support #68

Open
enumag opened this issue Nov 20, 2017 · 11 comments
Open

Symfony 4 support #68

enumag opened this issue Nov 20, 2017 · 11 comments

Comments

@enumag
Copy link

enumag commented Nov 20, 2017

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
Copy link
Author

enumag commented Nov 20, 2017

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

@justinlevi
Copy link
Contributor

justinlevi commented Dec 31, 2017

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

@Imagica
Copy link

Imagica commented Feb 1, 2018

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

explorer-error

@Imagica
Copy link

Imagica commented Feb 1, 2018

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

framework:
    templating:
        engines: ['twig']

@symm
Copy link
Contributor

symm commented Feb 14, 2018

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
Copy link
Contributor

symm commented Feb 14, 2018

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.

@mvriel
Copy link

mvriel commented Feb 23, 2018

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 Symfony 4 support #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

@Pirokiko
Copy link

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.

@HEKET313
Copy link

HEKET313 commented Jun 28, 2018

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

@programarivm
Copy link

programarivm commented Jul 8, 2018

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

@KerkniMohamed
Copy link

KerkniMohamed commented Jan 24, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants