# GraphQL Support [GraphQL](https://graphql.org/) is a query language made to communicate with an API and therefore is an alternative to REST. It has some advantages compared to REST: it solves the over-fetching or under-fetching of data, is strongly typed, and is capable of retrieving multiple and nested data in one go, but it also comes with drawbacks. For example it creates overhead depending on the request. API Platform creates a REST API by default. But you can choose to enable GraphQL as well. Once enabled, you have nothing to do: your schema describing your API is automatically built and your GraphQL endpoint is ready to go! ## Enabling GraphQL To enable GraphQL and its IDE (GraphiQL and GraphQL Playground) in your API, simply require the `api-platform/graphql` package using Composer: ```console composer require api-platform/graphql ``` You can now use GraphQL at the endpoint: `https://localhost/graphql`. > [!NOTE] If you used > [the Symfony Variant thanks to Symfony Flex](../symfony/index.md#installing-the-framework) or the > Laravel variant, the default GraphQL endpoint will be available at a relative URL like `/graphql`. > For example: `https://localhost/graphql`. ## Changing Location of the GraphQL Endpoint Sometimes you may want to have the GraphQL endpoint at a different location. This can be done by manually configuring the GraphQL controller. ### Symfony Routes Using the Symfony variant we can do this modification by adding the following code: ```yaml # api/config/routes.yaml api_graphql_entrypoint: path: /graphql controller: api_platform.graphql.action.entrypoint # ... ``` Change `/graphql` to the URI you wish the GraphQL endpoint to be accessible on. ### Laravel Routes Using the Laravel variant we can do this modification by adding the following code: ```php // routes/web.php use Illuminate\Support\Facades\Route; use ApiPlatform\GraphQL\Action\EntrypointAction; Route::post('/graphql', EntrypointAction::class) ->name('api_graphql_entrypoint'); ``` Change `/graphql` to the URI you wish the GraphQL endpoint to be accessible on. ## GraphiQL Go to the GraphQL endpoint with your browser, you will see a nice interface provided by GraphiQL to interact with your API. The GraphiQL IDE can also be found at `/graphql/graphiql`. If you need to disable it, it can be done in the configuration: ### Disabling GraphiQL with Symfony ```yaml # api/config/packages/api_platform.yaml api_platform: graphql: graphiql: enabled: false # ... ``` ### Disabling GraphiQL with Laravel ```php [ 'graphiql' => [ 'enabled' => false, ] ], ]; ``` ### Add another Location for GraphiQL Sometimes you may want to have the GraphiQL at a different location. This can be done by manually configuring the GraphiQL controller. ### Symfony config routes for GraphiQL If you want to add a different location besides `/graphql/graphiql`, you can do it like this if you are using the Symfony variant: ```yaml # app/config/routes.yaml graphiql: path: /docs/graphiql controller: api_platform.graphql.action.graphiql ``` ### Laravel config routes for GraphiQL If you want to add a different location besides `/graphql/graphiql`, you can do it like this if you are using the Laravel variant: ```php // routes/web.php use Illuminate\Support\Facades\Route; use ApiPlatform\GraphQL\Action\GraphiQlAction; Route::post('/docs/graphiql', GraphiQlAction::class) ->name('graphiql'); ``` ### Serving GraphiQL Under a Content Security Policy > [!NOTE] This feature is only available with Symfony. Laravel's GraphiQL page is served from its > own Blade template and controller, which this feature doesn't cover yet. You're welcome to > contribute the Laravel implementation [on GitHub](https://github.com/api-platform/core). GraphiQL renders its data and loads its scripts through several inline and external `