Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How do I enable GraphQL for bonus routes in Statamic


How do I enable GraphQL for bonus routes in Statamic


Statamic's "Bonus Routes" addon does not directly integrate with or enable GraphQL support. The GraphQL API in Statamic is a separate feature that is enabled and configured independently.

Here's a summary of how to enable GraphQL in Statamic, without any specific integration with the Bonus Routes addon:

1. Enable GraphQL in Statamic:
To enable the GraphQL API in Statamic, you need to add the following to your `.env` file:


   STATAMIC_GRAPHQL_ENABLED=true
   

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

php
   'enabled' => true,
   

2. Enable Resources for GraphQL:
By default, all GraphQL resources (e.g., collections, taxonomies) are disabled for security reasons. You need to enable the resources you want to be available through the GraphQL API 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,
           // 'events' => false, // Sub-resources are disabled by default
       ],
       'taxonomies' => true,
   ],
   

3. Use GraphQL Queries:
Once you've enabled GraphQL in Statamic, you can start using GraphQL queries to fetch data from your Statamic-powered application. You can explore and test available queries and fields using the GraphiQL interface in the Statamic control panel.

The search results do not indicate any direct integration between the Bonus Routes addon and Statamic's GraphQL API. The two features serve different purposes and can be used independently.

If you need to expose the content or routes managed by the Bonus Routes addon through the GraphQL API, you would need to manually configure the GraphQL schema and queries to include the relevant data and endpoints.

Citations:
[1] https://statamic.com/addons/jacksleight/bonus-routes
[2] https://statamic.dev/graphql
[3] https://stackoverflow.com/questions/75373946/can-we-use-statamic-cms-as-a-backend-and-vue-with-graphql-on-the-frontend-for
[4] https://statamic.com/addons?page=2&sort=name
[5] https://statamic.dev/controllers