All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.graphql.adoc Maven / Gradle / Ivy

The newest version!
///////////////////////////////////////////////////////////////////////////////

    Copyright (c) 2019, 2024 Oracle and/or its affiliates.

    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 Server Introduction
:description: Helidon GraphQL Server Introduction
:keywords: helidon, graphql, java
:feature-name: GraphQL
:rootdir: {docdir}/..

include::{rootdir}/includes/se.adoc[]


== Contents

- <>
- <>
- <>
- <>
- <>
- <>

== Overview

The Helidon GraphQL Server provides a framework for creating link:https://github.com/graphql-java/graphql-java[GraphQL]
applications that integrate with the Helidon WebServer. GraphQL is a query language to access server data.
The Helidon GraphQL integration enables HTTP clients to issue queries over the network and retrieve data;
it is an alternative to other protocols such as REST or GRPC.

include::{rootdir}/includes/dependencies.adoc[]

[source,xml]
----

    io.helidon.graphql
    helidon-graphql-server

----

== API

An instance of `GraphQlSupport` must be registered in the Helidon WebServer routes to enable
GraphQL support in your application. In addition, a GraphQL schema needs to be specified
to verify and execute queries.

The following code fragment creates an instance of `GraphQlSupport` and registers it in the
Helidon WebServer.

[source,java]
----
include::{sourcedir}/se/GraphQlSnippets.java[tag=snippet_1, indent=0]
----

By default, `GraphQlSupport` will reserve  `/graphql` as the URI path to process queries.
The `buildSchema` method creates the schema and defines 2 types of queries for this
application:

[source,java]
----
include::{sourcedir}/se/GraphQlSnippets.java[tag=snippet_2, indent=0]
----

The following is a description of each of these steps:

<1> Define the GraphQL schema.
<2> Create a `DataFetcher` to return a list of hellos in different languages.
<3> Wire up the `DataFetcher` s.
<4> Generate the GraphQL schema.

== Configuration

include::{rootdir}/includes/graphql.adoc[]

== Examples

Using the schema defined in Section <>, you can probe the following endpoints:

1. Hello world endpoint
+
[source,bash]
----
curl -X POST http://127.0.0.1:PORT/graphql -d '{"query":"query { hello }"}'

"data":{"hello":"world"}}
----

2. Hello in different languages
+
[source,bash]
----
curl -X POST http://127.0.0.1:PORT/graphql -d '{"query":"query { helloInDifferentLanguages }"}'

{"data":{"helloInDifferentLanguages":["Bonjour","Hola","Zdravstvuyte","Nǐn hǎo","Salve","Gudday","Konnichiwa","Guten Tag"]}}
----

== Additional Information

 * link:{graphql-javadoc-base-url}/module-summary.html[GraphQL Javadocs]




© 2015 - 2024 Weber Informatics LLC | Privacy Policy