GraphQL 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 time; but it also comes with drawbacks: for example it creates overhead depending of 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!
To enable GraphQL and GraphiQL interface in your API, simply require the graphql-php package using Composer:
$ composer require webonyx/graphql-php
You can now use GraphQL at the endpoint:
If Twig is installed in your project, go to the GraphQL endpoint with your browser. You will see a nice interface provided by GraphiQL to interact with your API.
If you need to disable it, it can be done in the configuration:
# api/config/packages/api_platform.yaml api_platform: graphql: graphiql: enabled: false # ...