siler icon indicating copy to clipboard operation
siler copied to clipboard

Deannotate interdependent types

Open gskierk opened this issue 4 years ago • 3 comments

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

gskierk avatar Nov 04 '20 20:11 gskierk

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

leocavalcante avatar Nov 06 '20 22:11 leocavalcante

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? 

gskierk avatar Nov 07 '20 11:11 gskierk

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?

borodean avatar Jan 23 '22 01:01 borodean