//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
=== GraphQL API

First introduced in Apache Unomi 2.0, a GraphQL API is available as an alternative to REST for interacting with the platform. 
Disabled by default, the GraphQL API is currently considered a beta feature.

We look forward for this new GraphQL API to be used, feel free to open discussion on 
https://the-asf.slack.com/messages/CBP2Z98Q7/[Unomi Slack channel] or https://issues.apache.org/jira/projects/UNOMI/issues[create tickets on Jira]

==== Enabling/ the API

The GraphQL API must be enabled using a system property (or environment variable):

[source]
----
# Extract from: etc/custom.system.properties
#######################################################################################################################
## Settings for GraphQL                                                                                              ##
#######################################################################################################################
org.apache.unomi.graphql.feature.activated=${env:UNOMI_GRAPHQL_FEATURE_ACTIVATED:-false}
----

You can either modify the `org.apache.unomi.graphql.feature.activated` property or specify the `UNOMI_GRAPHQL_FEATURE_ACTIVATED` 
environment variable (if using Docker for example).

==== Endpoints

Two endpoints were introduced for Apache Unomi 2 GraphQL API:
* `/graphql` is the primary endpoint for interacting programatically with the API and aims at receiving POST requests.
* `/graphql-ui` provides access to the GraphQL Playground UI and aims at being accessed by a Web Browser.

==== GraphQL Schema

Thanks to GraphQL introspection, there is no dedicated documentation per-se as the Schema itself serves as documentation. 

You can easily view the schema by navigrating to `/graphql-ui`, depending on your setup (localhost, public host, ...), 
you might need to adjust the URL to point GraphQL Playground to the `/graphql` endpoint.
