Skip to content

Simple GraphQL Java + SpringBoot + WebFlux evaluation.

Notifications You must be signed in to change notification settings

mafor/graphql-annotations

Repository files navigation

codecov Build status

GraphQL annotations

GraphQL Java + SpringBoot + WebFlux evaluation. Prove of concept of a declarative, annotations based configuration (see GraphQLHandler)

Starting the application

To start the application localy, run in the project's root folder:

./gradlew bootRun

To start it on Docker:

./gradlew clean bootJar
docker build -t graphql-library examples/library
docker run -d --rm -p 8080:8080 graphql-library

The application exposes single GraphQL endpoint on http://localhost:8080/graphql

Sample queries

GraphQL schema: schema.graphqls

list books

GraphQL:

query listBooks {
    books {
        id,
        title,
        authors {
            id,
            name
        }
    }
}

Curl:

curl --request POST \
  --url http://localhost:8080/graphql \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --data '{"query":"query listBooks {books {id, title, authors {id, name}}}"}'

list authors

GraphQL:

query listAuthors {
  authors {
    id,
    name,
    books {
      id,
      title
    }
  }
}

Curl:

curl --request POST \
  --url http://localhost:8080/graphql \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --data '{"query":"query listAuthors {authors {id, name, books {id, title}}}"}'

add a book

GraphQL:

mutation createBook {
    addBook(authorIds: ["1"], title: "New book") {
        id
    }
}

Curl:

curl --request POST \
  --url http://localhost:8080/graphql \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --data '{"query":"mutation createBook {addBook(authorIds: [\"1\"], title: \"New book\") {id}}"}'

remove a book

GraphQL:

mutation removeBook {
	removeBook(id: "1")
}

Curl:

curl --request POST \
  --url http://localhost:8080/graphql \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --data '{"query":"mutation removeBook {removeBook(id: \"1\")}"}'

subscribe to notifications

GraphQL:

subscription events {
	events
}

Curl:

curl -N --request POST \
  --url http://localhost:8080/graphql \
  --header 'accept: text/event-stream' \
  --header 'content-type: application/json' \
  --data '{"query":"subscription events {events}"}'

About

Simple GraphQL Java + SpringBoot + WebFlux evaluation.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages