avored / laravel-ecommerce

AvoRed an Open Source Laravel Shopping Cart
https://avored.com
1.51k stars 549 forks source link

about graphql API issue #626

Closed marol1210 closed 2 years ago

marol1210 commented 2 years ago

Describe the bug avored's graphql api can't find graphql offset of TYPES which config in config/avored.php.

To Reproduce Steps to reproduce the behavior:

  1. install avored from docker-dev
  2. visiter fontend
  3. show exception

Screenshots

{
  "errors": [
    {
      "debugMessage": "Type Category not found.\nCheck that the config array key for the type matches the name attribute in the type's class.\nIt is required when 'lazyload_types' is enabled",
      "message": "Internal server error",
      "extensions": {
        "category": "internal"
      },
      "locations": [
        {
          "line": 2,
          "column": 1
        }
      ],
      "path": [
        "allCategory",
        0
      ],
      "trace": [
        {
          "file": "/var/www/backend/vendor/rebing/graphql-laravel/src/GraphQL.php",
          "line": 224,
          "call": "Rebing\\GraphQL\\GraphQL::getType('Category', false)"
        },
        {
          "file": "/var/www/backend/vendor/rebing/graphql-laravel/src/GraphQL.php",
          "line": 394,
          "call": "Rebing\\GraphQL\\GraphQL::type('Category')"
        },
        omit....

Additional context

  1. config/avored.php content:
        'types' => [
            'category' => CategoryType::class,
            'product' => ProductType::class,
            'customer' => CustomerType::class,
            'order' => OrderType::class,
            'address' => AddressType::class,
            'notification' => NotificationType::class,
            'cartProduct' => CartProductType::class,
            'payment' => PaymentType::class,
            'shipping' => ShippingType::class,
            'subscriber' => SubscriberType::class,
            'option' => OptionType::class,
        ]
  2. property attributes of class CategoryType is

    $attributes = [
        'name' => 'Category',
        'description' => 'A type'
    ]

    and there is space in property attributes of class ShippingType $attributes = [ 'name' => 'Shipping Type', 'description' => 'A type' ]

    so under my local environment , avored's config about grahpql's TYPES which key is lowercase , but capitalize in property attributes

indpurvesh commented 2 years ago

@marol1210 Have you manage to fixed it?

marol1210 commented 2 years ago

@marol1210 Have you manage to fixed it?

Yes , despite of fixed , it's not smart. I just modify name value of $attributes in which every AvoRed\\Framework\\Graphql\\Types classes to same as key of config/avored.php TYPES field.

marol1210 commented 2 years ago

@marol1210 Have you manage to fixed it?

alternative , just use type name of TYPE from graphql self whatever others. because , under hood, the name is defined by graphql Rebing\GraphQL\GraphQL::addTypes. so just use.

graphql introspection for exmaple:

{
__schema{
  types{
    name
    description
  }
}
}

after

{
  "data": {
    "__schema": {
      "types": [
        {
          "name": "Product",
          "description": "A type"
        },
        {
          "name": "Category",
          "description": "A type"
        }
        ....
 }
indpurvesh commented 2 years ago

Can you please do a pull request with your fixed. @marol1210