Skip to content
This repository has been archived by the owner on Feb 13, 2022. It is now read-only.

Deannotate interdependent types #495

Open
gskierk opened this issue Nov 4, 2020 · 3 comments
Open

Deannotate interdependent types #495

gskierk opened this issue Nov 4, 2020 · 3 comments
Assignees

Comments

@gskierk
Copy link
Contributor

gskierk commented Nov 4, 2020

Types put in GraphQL annotations are not being deannotated in the fly, so implementing many-to-many association is impossible, because always TypeA will require TypeB that still wasn't deannotated.

Edit: It's working correctly with one-to-many relation, so probably there is something with listOf annotation...

@leocavalcante
Copy link
Owner

Hm, the lazy evaluation should handle this already, can you send a small snippet that reproduces the error, please?

@gskierk
Copy link
Contributor Author

gskierk commented Nov 7, 2020

This is a main part:

// Discussion.php

    /**
     * @ORM\ManyToMany(targetEntity="Tag", inversedBy="discussions")
     * @ORM\JoinTable(name="tags_discussions")
     */
    public Collection $tags;

    /**
     * @GraphQL\Field(name="tags", listOf=Tag::class)
     * @GraphQL\Args(
     *     {
     *          @GraphQL\Field(name="first", type="Int", nullable=true),
     *          @GraphQL\Field(name="offset", type="Int", nullable=true),
     *          @GraphQL\Field(name="sort", listOf=SortInput::class, nullableList=true)
     *     }
     * )
     */
    public function getTags($root, array $args, $context, ResolveInfo $resolveInfo): array
    {
        // $criteria = ...

        return $this->tags->matching($criteria)->toArray();
    }
// Tag.php

    /**
     * @ORM\ManyToMany(targetEntity="Discussion", mappedBy="tags")
     */
    public Collection $discussions;

    /**
     * @GraphQL\Field(name="discussions", listOf=Discussion::class)
     * @GraphQL\Args(
     *     {
     *          @GraphQL\Field(name="first", type="Int", nullable=true),
     *          @GraphQL\Field(name="offset", type="Int", nullable=true),
     *          @GraphQL\Field(name="sort", listOf=SortInput::class, nullableList=true)
     *     }
     * )
     */
    public function getDiscussions($root, array $args, $context, ResolveInfo $resolveInfo): array
    {
        // $criteria = ...

        return $this->discussions->matching($criteria)->toArray();
    }

It produces:

Fatal error: Uncaught TypeError: Class App\Entity\Tag does exists, but is not a Type. Does it have Annotations and it's added to annotated function array? 

@borodean
Copy link

I'm also running into the same issue. I have a more straightforward example:

/* Node.php */

use Siler\GraphQL\Annotation\Field;
use Siler\GraphQL\Annotation\ObjectType;

/** @ObjectType */
class Node
{
  /** @Field */
  public function child(): Node
  {
    return new Node();
  }
}
/* schema.php */

use function Siler\GraphQL\annotated;

return annotated([
  Node::class,
]);

Presents me with the same error:

Fatal error: Uncaught TypeError: Class Node does exists, but is not a Type. Does it have Annotations and it's added to annotated function array?

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

No branches or pull requests

3 participants