In this year's Code Camp, I wanted to explore GraphQL. Graph.. what!? GraphQL Explained in 100 Seconds might enlighten you 💡
In short, GraphQL is a query language for APIs and a runtime for executing queries on the backend. A specification in the form of a schema defines how data is exchanged between server and client. This schema enables:
- the server to inform clients what data is available and how it can be queried
- the client to craft valid formatted requests
- the server to validate and execute incoming queries
Finally, GraphQL is considered as an alternative to REST, with some key differences between the two.
- With REST, data is often collected by sending requests to multiple endpoints. Whereas with GraphQL, a single request containing a single query is all that is needed.
- REST endpoints usually return fixed data structures, while GraphQL returns exactly the data structure that was asked for.
- GraphQL APIs are statically typed with the underlying schema serving as the contract between server and client.
GraphQL Endpoint
I have implemented a GraphQL endpoint prototype based on graphql-java running on the Ivy Engine. The current endpoint supports querying tasks and users and allows creating new users.
Incomplete extract from the current GraphQL schema:
type Query {
allTasks: [Task]
taskById(id: ID): Task
tasksByState(state: String): [Task]
allUsers: [User]
}
type Mutation {
createUser(userName: String!, password: String!): User!
}
type Task {
id: ID
name: String
description: String
startTimeStamp: String
expiryTimeStamp: String
priority: String
state: String
activator: Activator
caze: Case
customFields: [CustomField]
}
...
Demo
In the following demo, Altair GraphQL Client is used to send queries to Ivy (http://localhost:8081/designer/api/graphql). Any other client that can send POST requests can be used instead.
Query for all tasks:

Query for tasks with state filter:

Create new user:

Future work
I plan to publish this Endpoint to Axon Ivy Market in near future.