Schema

Now that we have a type and a query, we have just enough to start querying our GraphQL server! Before we get started though, we must register our Type and Query with GraphQL so it's aware of them.

Schema File

We are going to create a new file to hold our schema. We'll name it graphql.php and place it in the routes folder.

<?php

// routes/graphql.php

GraphQL::schema()->group(['namespace' => 'App\\Http\\GraphQL'], function () {
    GraphQL::schema()->type('user', 'Types\\UserType');

    GraphQL::schema()->query('viewer', 'Queries\\ViewerQuery');
});

Update Lighthouse Config

Since we created a new schema file, we need to adjust our lighthouse.php config file to tell it were to look for our schema file.

// config/lighthouse.php

return [
    // ..

    'schema' => [
        // ...
        'register' => base_path('routes/graphql.php'),
    ],
]

results matching ""

    No results matching ""