folkloreinc / laravel-graphql

Facebook GraphQL for Laravel 5. It supports Relay, eloquent models, validation and GraphiQL.
1.76k stars 234 forks source link

Cannot query field - Works on Laptop, not on desktop #279

Open mithradantor opened 6 years ago

mithradantor commented 6 years ago

Hi guys, I cannot seem to get GraphQL working on my desktop. Pushed it to GIT, downloaden with my laptop and there it works flawless. Been trying to find a fix for days now but unfortunately have not found one. My problem described below:

Hi guys,

today I installed GraphQL and when I go to mysite.com/admin/public/graphiql I do see the real-time editor but it is simply not working. Whenever I do a query I get this error in return:

Cannot query field \"products\" on type \"Query\".

I copy and pasted the example code from the website (to retrieve a user) but this gave me the exact same error.

I ran composer dumpautoload, composer install, composer update, php artisan clear cache/view/config et cetera but nothing solved my problem.

Hope someone can help me out on this matter :)

I am using Laravel 5.5!

My Type code:

<?php
namespace App\GraphQL\Type;

use GraphQL;
use GraphQL\Type\Definition\Type;
use Folklore\GraphQL\Support\Type as GraphQLType;

class ProductType extends GraphQLType
{

    protected $attributes = [
        'name' => 'Product',
        'description' => 'A product'
    ];

    public function fields()
    {
        return [
            'id' => [
                'type' => Type::nonNull(Type::int()),
                'description' => 'The id of the product'
            ]
        ];
    }

}

My Query code:

<?php
namespace App\GraphQL\Query;

use GraphQL;
use GraphQL\Type\Definition\Type;
use Folklore\GraphQL\Support\Query;

use App\Product;

class ProductsQuery extends Query
{

    protected $attributes = [
        'name' => 'products'
    ];

    public function type()
    {
        return Type::listOf(GraphQL::type('Product'));
    }

    public function args()
    {
        return [
            'id' => ['name' => 'id', 'type' => Type::int()]
        ];
    }

    public function resolve($root, $args)
    {
        print_r('******');
        exit();
    }

}

And finally my graphql.php file:

    'schemas' => [
        'default' => [
            'query' => [
                'products' => 'App\GraphQL\Query\ProductsQuery'
            ],
            'mutation' => [

            ]
        ]
    ],

    'types' => [
        'Product' => 'App\GraphQL\Type\ProductType'
    ],
kikoseijo commented 6 years ago

You need at least 1 mutation, can't be empty.

mithradantor commented 6 years ago

Mutation cant be empty? thats nonesense... as said, 1:1 copy working on my laptop but on PC it aint working, and if I dont need a mutation im not going to create in obviously so that cant be the problem.

mithradantor commented 6 years ago

still no one? not even the creator of graphql for laravel?...

kevinvdburgt commented 6 years ago

Cannot reproduce this issue, can you create a project on git which I can clone to check it out? (ref: #293)

shbumba commented 6 years ago

@kevinvdburgt i have a similar problem, please check my project https://github.com/shbumba/laravel-graphql-issues

Sever Info: Debian 8 PHP 7.1.13 (PHP-FPM FastCGI) nginx/1.12.2

Lloydinator commented 6 years ago

This is sad that absolutely no one can figure this out.

mfn commented 6 years ago

OP misses the actual GraphQL query. Also it's 9 month old, the last linked repo doesn't exist either.

@Lloydinator if you've a specific issue, please post specific information:

Lloydinator commented 6 years ago

@mfn Thnx but after some more searching I think I figured it out. It seems to be a cache issue. It didn't help either that GraphiQL wasn't working on initial installation. Now I'm seeing actual exceptions being thrown so at least I know it's working now. For future reference, after each change to the 'query' or 'type' file that you make, you have to run php artisan config:cache and ensure you're running a client that will display a stack trace. I was using Altair at first which showed zilch. Now I'm getting a syntax error which I can at least work with.