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

ScalarType is not processed correctly when defined with Annotations #1132

Open
ageurts opened this issue Sep 5, 2023 · 1 comment
Open

Comments

@ageurts
Copy link

ageurts commented Sep 5, 2023

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Version/Branch 1.0

I'm using annotations in Symfony 6 on PHP 8.1 and I'm trying to define a custom scalar type for using the file upload feature.
Somehow the scalarType class name is not processed correctly and I end up with a faulty Type class.

This is my definition:

<?php

namespace App\GraphQL\CustomTypes;

use Overblog\GraphQLBundle\Annotation\Scalar;

#[Scalar(name: 'UploadImage', scalarType: '@=newObject("Overblog\\GraphQLBundle\\Upload\\Type\\GraphQLUploadType")')]
class UploadImageType
{
}

and this is the (faulty) generated Type class (see the scalarType line):

<?php

namespace Overblog\GraphQLBundle\__DEFINITIONS__;

use Overblog\GraphQLBundle\Definition\ConfigProcessor;
use Overblog\GraphQLBundle\Definition\GraphQLServices;
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
use Overblog\GraphQLBundle\Definition\Type\CustomScalarType;
use Overblog\GraphQLBundle\Definition\Type\GeneratedTypeInterface;

/**
 * THIS FILE WAS GENERATED AND SHOULD NOT BE EDITED MANUALLY.
 */
final class UploadImageType extends CustomScalarType implements GeneratedTypeInterface, AliasedInterface
{
    public const NAME = 'UploadImage';
    
    public function __construct(ConfigProcessor $configProcessor, GraphQLServices $services)
    {
        $config = [
            'name' => self::NAME,
            'scalarType' => (new \ReflectionClass("OverblogGraphQLBundleUploadTypeGraphQLUploadType"))->newInstanceArgs([]),
        ];
        
        parent::__construct($configProcessor->process($config));
    }
    
    /**
     * {@inheritdoc}
     */
    public static function getAliases(): array
    {
        return [self::NAME];
    }
}

The scalar class 'OverblogGraphQLBundleUploadTypeGraphQLUploadType' does not exist of course.

The Type class is generated correctly if I use the YAML variant.

UploadImage:
    type: custom-scalar
    config:
        scalarType: '@=newObject("Overblog\\GraphQLBundle\\Upload\\Type\\GraphQLUploadType")'

UploadImageType.php:

    public function __construct(ConfigProcessor $configProcessor, GraphQLServices $services)
    {
        $config = [
            'name' => self::NAME,
            'scalarType' => (new \ReflectionClass("Overblog\\GraphQLBundle\\Upload\\Type\\GraphQLUploadType"))->newInstanceArgs([]),
        ];
        
        parent::__construct($configProcessor->process($config));
    }

Is this a bug in the type class generation or am I using Annotations wrong?

@ageurts
Copy link
Author

ageurts commented Sep 5, 2023

So I found that escaping the class in the Annotation with 4 slashes fixes the generated class.

<?php

namespace App\GraphQL\CustomTypes;

use Overblog\GraphQLBundle\Annotation\Scalar;

#[Scalar(name: 'UploadImage', scalarType: '@=newObject("Overblog\\\\GraphQLBundle\\\\Upload\\\\Type\\\\GraphQLUploadType")')]
class UploadImageType
{
}

But I'm guessing this is not supposed to work like this.

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

1 participant