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

@Security with External type declaration - error #546

Open
ameoba32 opened this issue Jan 20, 2023 · 4 comments
Open

@Security with External type declaration - error #546

ameoba32 opened this issue Jan 20, 2023 · 4 comments

Comments

@ameoba32
Copy link

ameoba32 commented Jan 20, 2023

I am getting next error when using @Security with External type declaration.

Version: 5.0.3

"array_combine(): Argument #1 ($keys) and argument #2 ($values) must have the same number of elements"
vendor/thecodingmachine/graphqlite/src/Middlewares/SecurityFieldMiddleware.php:132

I've tried to debug the issue myself, it has something related with first parameter, which is always there. But no luck. If I comment out array_combine in SecurityFieldMiddleware.php:132 it seems to work.

Consider next php code example:

namespace App\Types;

use TheCodingMachine\GraphQLite\Annotations\Type;
use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Security;
use App\Entities\Product;

/**
 * @Type(class=Product::class)
 */
class ProductType
{
    /**
     * @Field
     * @Security("this.canAccess()")
     */
    public function getId(Product $product): string
    {
        return $product->getId();
    }
    
    public function canAccess(): bool
    {
        return true;
    }
}

thanks.

@oojacoboo
Copy link
Collaborator

oojacoboo commented Jan 21, 2023

@ameoba32 Can you create a testcase for this, demonstrating the error, so we can work through it? Also, any reason you're not using the latest version?

@ameoba32
Copy link
Author

ameoba32 commented Feb 5, 2023

Ok, I was able to make a test, plz see this pull request #554

@Lappihuan
Copy link
Contributor

@ameoba32 this seems to be caused by the fact that all parameters are expected to map 1:1 to what the GQL schema exposes.
i think you could get this working by just adding a Ignore annotation/attribute for the $product parameter.

@ameoba32
Copy link
Author

@Lappihuan Can you show the code sample?

I think I will just drop the idea of using separate classes for type declaration and convert Types to Entities that I already have. External types does not work with security.

It made sense when I started to use graphqlite lib, wasn't sure about how it would go. After approx 1 year I am quite happy with results and will incorporate types directly into existing classes.

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

3 participants