Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How do I configure GraphQL settings in Statamic's Control Panel
    Statamic GraphQL Statamic Control Panel GraphQL configuration Statamic setup API settings GraphQL resources Statamic authentication


How do I configure GraphQL settings in Statamic's Control Panel


here are the key steps to configure GraphQL settings in Statamic's Control Panel:

1. Enable GraphQL: First, ensure that the GraphQL API is enabled in your Statamic project. This can be done by adding the following to your `.env` file:


   STATAMIC_GRAPHQL_ENABLED=true
   

Alternatively, you can enable it for all environments in the `config/statamic/graphql.php` file:

php
   'enabled' => true,
   

2. Enable Resources: By default, all resources (e.g., Collections, Taxonomies) are disabled for GraphQL. You need to explicitly enable the resources you want to be available in the `config/statamic/graphql.php` file:

php
   'resources' => [
       'collections' => true,
       'taxonomies' => true,
       // Enable other resources as needed
   ]
   

You can also enable specific sub-resources within a resource type:

php
   'resources' => [
       'collections' => [
           'articles' => true,
           'pages' => true,
           // Disable 'events' collection
       ],
       'taxonomies' => true,
   ]
   

3. Configure Authentication and Authorization: By default, all GraphQL queries are allowed by anyone. You can define custom authorization logic for any query by providing a closure to the static `auth` method:

php
   EntriesQuery::auth(function () {
       return true; // true authorizes, false denies
   });
   

You can also control access to the GraphQL API with API tokens and user permissions in Statamic.

4. Set up Caching and Query Complexity: Statamic allows you to configure caching and query complexity settings in the `config/statamic/graphql.php` file to optimize performance.

5. Explore the GraphQL Schema: Once GraphQL is enabled, you can access the GraphiQL interface in the Statamic Control Panel to explore the available queries and fields in your GraphQL schema.

By following these steps, you can configure the GraphQL settings in Statamic's Control Panel to suit your project's needs, including enabling resources, setting up authentication and authorization, and optimizing performance.

Citations:
[1] https://statamic.dev/graphql
[2] https://accreditly.io/articles/how-to-use-graphql-in-statamic
[3] https://statamic.com/blog/statamic-3.1-lunch-party
[4] https://stackoverflow.com/questions/75373946/can-we-use-statamic-cms-as-a-backend-and-vue-with-graphql-on-the-frontend-for
[5] https://statamic.com/blog/statamic-3.1-preview