This is an example of the MicroProfile GraphQL API using the SmallRye Implementation. It's done as part of these blog posts:
and these presentations:
The services are exposed with both REST and GraphQL for comparison.
This example expose person data as well as scores that the person got for certain activities.
cd wildfly-example
mvn wildfly:run
cd quarkus-example
mvn quarkus:dev
This will start the application on port 8080.
Go to http://localhost:8080 to test the application.
- Click on the 'REST' link to open Swagger UI to test the JAX-RS services.
- Click on the 'GraphQL' link to open GraphiQL UI to test the MicroProfile GraphQL service.
To stop the application, ctrl-c
in the maven session.
curl -X GET "http://localhost:8080/rest/profile/1" -H "accept: application/json"
{
profileFull(personId:1) {
person{
surname
}
scores{
name
value
}
}
}
{
profile(personId:1){
person{
surname
}
scores{
name
value
}
}
}
in the log file:
======= Getting person [1] =======
======= Getting scores [512-46-5065] =======
without score
{
profile(personId:1){
person{
surname
}
}
}
in the log file:
======= Getting person [1] =======
{
person(personId:1){
surname
scores{
name
value
}
}
}
or without score
{
person(personId:1){
surname
}
}
or more people
{
person1:person(personId:1){
surname
scores{
name
value
}
}
person2:person(personId:2){
surname
}
}
{
people{
surname
}
}
mutation CreatePerson{
updatePerson(person :
{
names: "Phillip"
}
){
id
names
surname
profilePictures
website
}
}
and then update using the generated id
mutation UpdatePerson{
updatePerson(person :
{
id: 101,
names:"Phillip",
surname: "Kruger",
profilePictures: [
"https://pbs.twimg.com/profile_images/1170690050524405762/I8KJ_hF4_400x400.jpg"
],
website: "http://www.phillip-kruger.com"
}){
id
names
surname
profilePictures
website
}
}
and then delete using the id
mutation DeletePerson{
deletePerson(id :101){
id
names
surname
profilePictures
website
}
}
{
people{
surname
scores{
thisDoesNotExist
}
}
}
{
person(personId:1){
names
surname
scores2 {
name
value
}
}
}
{
person(personId:1){
names
surname
scores {
name
value
events{
dateTime
action
}
}
}
}
{
person(personId:1){
names
surname
scores {
name
value
events{
when
action
}
}
}
}
{
__schema{
types {
name
kind
}
}
}
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
description
locations
args {
...InputValue
}
}
}
}
fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}
fragment InputValue on __InputValue {
name
description
type { ...TypeRef }
defaultValue
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}