leocavalcante / siler

⚡ Flat-files and plain-old PHP functions rockin'on as a set of general purpose high-level abstractions.
https://siler.leocavalcante.dev
MIT License
1.12k stars 90 forks source link

GraphQL type is declared but its not Identified as valid type #888

Closed razorback21 closed 2 years ago

razorback21 commented 2 years ago

Hi, I have this error. Class ProductType does exist but is not a Type. Does it have Annotations and it's added to annotated function array. What did I miss?

<?php declare(strict_types=1);

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

/**
 * @ObjectType()
 */
class ProductType
{
    /**
     * @Field(type="Int", nullable=true)
     */
    public $ID;
}

In my CollectionType I have this resolver

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

/**
 * @ObjectType()
 */
class CollectionType
{

  /**
   * @Field(listOf=ProductType::class)  // **this line throws an error**
   * @Args({
   *     @Field(name="ID", type="Int", nullable=true),
   *     @Field(name="OnSaleOnly", type="Boolean", nullable=true)
   * })
   * @return array
   */
  public function Products($root, $args) : array
  {
       return [ProductType] // returns an array of ProductType
  }

}

then in my controller action

$schema = annotated([
      CollectionType::class,
      ProductType::class,
      Query::class
]);

GraphQL\init($schema);
leocavalcante commented 2 years ago

Move ProductType to be before CollectionType:

$schema = annotated([
      ProductType::class,
      CollectionType::class,
      Query::class
]);