Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/camunda-community-hub/camunda-platform-7-graphql
GraphQL for Camunda Platform 7
https://github.com/camunda-community-hub/camunda-platform-7-graphql
camunda-7 camunda-platform-7 graphql graphql-java graphql-server java spring-boot springframework
Last synced: 2 days ago
JSON representation
GraphQL for Camunda Platform 7
- Host: GitHub
- URL: https://github.com/camunda-community-hub/camunda-platform-7-graphql
- Owner: camunda-community-hub
- License: apache-2.0
- Created: 2017-03-07T11:28:23.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2024-10-03T18:44:19.000Z (3 months ago)
- Last Synced: 2024-12-14T04:07:43.778Z (10 days ago)
- Topics: camunda-7, camunda-platform-7, graphql, graphql-java, graphql-server, java, spring-boot, springframework
- Language: Java
- Homepage:
- Size: 3.3 MB
- Stars: 113
- Watchers: 21
- Forks: 44
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS.MD
Awesome Lists containing this project
README
[![Community Extension Badge](https://img.shields.io/badge/Community%20Extension-An%20open%20source%20community%20maintained%20project-FF4700)](https://github.com/camunda-community-hub/community)
[![Camunda Platform 7](https://img.shields.io/badge/Compatible%20with-Camunda%20Platform%207-26d07c)](https://img.shields.io/badge/Compatible%20with-Camunda%20Platform%207-26d07c)
[![Lifecycle: Incubating](https://img.shields.io/badge/Lifecycle-Incubating-blue)](https://github.com/Camunda-Community-Hub/community/blob/main/extension-lifecycle.md#incubating-)Camunda Platform GraphQL
===============Camunda Platform GraphQL is a Community Extension for Camunda Platform 7 that allows you to use [GraphQL](http://graphql.org/) to query and mutate [Process Engine data](https://docs.camunda.org/manual/latest/user-guide/process-engine/process-engine-api/) in a simple way.
![Overview](extension/src/main/resources/png/overview_01.png?raw=true "Overview")
Release 0.4.0
-------------
- updated the resolvers to support the GraphQL Kickstart
- GraphiQL endpoint default set to /graphiql
- GraphQL endpoint default set to /graphql
- Added historic queries
- Added relationship between historic types
- refactored the test setup and move test from webapp to extension
- changed the app to execute on Spring Boot
- Updated example
- updated documentationSpring Boot Camunda GraphQL Server Embbedded
--------------------------### Spring Boot (only supported on version 0.4.0 or higher)
In your Camunda Spring Boot project add the following dependencies**Gradle**
Camunda Extension GraphQL
```groovy
implementation group: 'org.camunda.platform7.extension.graphql', name: 'camunda-platform-7-graphql', version: '0.5.0'
```Spring Boot GraphQL Kickstart (the version 11.1.0 or higher)
```groovy
implementation group: 'com.graphql-java-kickstart', name: 'graphql-spring-boot-starter', version: '11.1.0'
implementation group: 'com.graphql-java-kickstart', name: 'graphiql-spring-boot-starter', version: '11.1.0'
implementation group: 'com.graphql-java-kickstart', name: 'graphql-java-tools', version: '11.0.1'
```**Maven**
Camunda Extension GraphQL
```xml
org.camunda.platform7.extension.graphql
camunda-platform-7-graphql
0.5.0
```
Spring Boot GraphQL Kickstart (the version 11.1.0 or higher)
```xml
com.graphql-java-kickstart
graphql-spring-boot-starter
11.1.0
com.graphql-java-kickstart
graphiql-spring-boot-starter
11.1.0
com.graphql-java-kickstart
graphql-java-tools
11.0.1
```Use the [example](https://github.com/camunda-community-hub/camunda-platform-7-graphql/tree/main/example) if necessary.
By default the GraphQL and GraphiQL are available at the uri /graphql and /graphiql respectively, this configuration
and others can be change by properties. The available settings can be consulted directly in the project of
[Spring Boot GraphQL Kick Start](https://github.com/graphql-java-kickstart/graphql-spring-boot)Install the Camunda GraphQL Server on Tomcat or Wildfly
--------------------------Build the GraphQL server
------------------------
1. Checkout or Clone this repository using Git
2. Adapt `extension/src/main/resources/application.properties`:
3. Build the project
for Apache Tomcat: `mvn clean package`
for JBoss WildFly use the profile wildfly: `mvn clean package -Pwildfly`### Tomcat installation
- Get the latest Release (`.war` file) from the
[Camunda Repo](https://artifacts.camunda.com/artifactory/camunda-bpm-community-extensions/org/camunda/platform7/extension/camunda-platform-7-graphql-webapp/)
- deploy it to your Tomcat server e.g. copy it to the Tomcat /webapps` folder### Wildfly installation
For WildFly you have to clone the project and build the `.war` file.
See chapter [Build the GraphQL server](#build-the-graphql-server).
Test the Installation
---------------------
### Access the GraphQL endpoint with a browser
- URL: `http://:/camunda-graphql/graphql/?query=`{_here is your query_}
e.g. [http://localhost:8080/camunda-graphql/graphql/?query={tasks{name}}](http://localhost:8080/camunda-graphql/graphql/?query={tasks{name}})
This will return a JSON object with the names of the current tasks (rendered by your browser).### Access the GraphQL endpoint with GraphiQL _an in-browser IDE for exploring GraphQL_
- GraphiQL is available at `http://:/camunda-graphql/graphiql/`
e.g. [http://localhost:8080/camunda-graphql/graphiql/](http://localhost:8080/camunda-graphql/graphiql/)
- checkout chapter [GraphQL Queries and Mutations](#graphql-queries-and-mutations)
Other GraphQL clients
---------------------
Beside the build-in GraphiQL you can use other GraphQL clients.
Basically...
- ...point your GraphQL client to the GraphQL server endpoint:
`http://:/camunda-graphql/graphql`
- depending on the GraphQL server authentication settings you need to add Authentication Header to your requestsExamples of other GraphQL clients:
* GraphQL IDE - An extensive IDE for exploring GraphQL API's
Link: https://github.com/redound/graphql-ide
(Windows, Mac OS X - needs npm/yarn)
* Light, Electron-based Wrapper around GraphiQL
Link: https://github.com/skevy/graphiql-app
Mac User just type: `brew cask install graphiql`
Windows/Linux User:
- `npm install -g electron`
- download graphiql-app zip/tar.gz from https://github.com/skevy/graphiql-app/releases
- unzip
- type in: `electron` _app-folder_
with _app-folder_ = `GraphiQL.app/Contents/Resources/app` (unzipped from above)
GraphQL Queries and Mutations
-----------------------------**Query Tasks:**
![query tasks](extension/src/main/resources/png/query_tasks.png?raw=true "GraphQL query for Tasks")
**Query Tasks using a Filter:**
![query tasks with filter](extension/src/main/resources/png/query_tasks_w_filter_nameLike.png?raw=true "GraphQL query for Tasks with filter")
**Query Process Instances:**
![query proceses](extension/src/main/resources/png/query_process_instances.png?raw=true "GraphQL query for Process Instances")
**Query Process Instance Variables:**
![query proceses with vars](extension/src/main/resources/png/query_process_instances_w_vars.png?raw=true "GraphQL query for Process Instances with Variables")
**Query Task Variables:**
![query tasks with vars](extension/src/main/resources/png/query_tasks_w_vars.png?raw=true "GraphQL query for Process Instances with Variables")
**Mutation**
**Assign a user to a task**![setAssignee mutation](extension/src/main/resources/png/mutation_01.png?raw=true "simple GraphQL mutation")
**Mutation**
**Start a Process Instance with start variables**
![startProcessInstance](extension/src/main/resources/png/mutation_startProcessInstance.png?raw=true "startProcessInstance")GraphQL Schemas and Types
-------------------------A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations.
![Docs Schema](extension/src/main/resources/png/docs_open.png?raw=true "docs open")
![Docs Root Types](extension/src/main/resources/png/docs_root_types.png?raw=true "docs root types")
### Currently defined queries:
![Docs Queries](extension/src/main/resources/png/docs_queries.png?raw=true "docs queries")
### Currently defined mutations:
![Docs Mutations](extension/src/main/resources/png/docs_mutations.png?raw=true "docs mutations")
Defining / Extending the Camunda GraphQL Schema
-----------------------------------------------We decided to use the Schema Definition Language (a GraphQL DSL) to define the Camunda GraphQL schema instead of coding it in Java.
The Schema Definition Language is very easy to understand.
For example this is the Type Definition of the Camunda Task:
![graphqls TaskEntity](extension/src/main/resources/png/schema_TaskEntity_graphqls.png?raw=true "graphqls TaskEntity")
To get an understanding of Schemas please visit:
- http://graphql.org/learn/schema/
- http://graphql-java.readthedocs.io/en/stable/schema.htmlThe Camunda GraphQL Schema is comprised of several schema files located at `src/main/resource/*.graphqls`.
This is an attempt to group GraphQL Type Definitions by topics![schema files overview](extension/src/main/resources/png/schema_files.png?raw=true "schema files")
The so called _Root Types_ serve as entry points for Queries and Mutations (in the future: Subscriptions etc.)
The Root Types schema file is `src/main/resources/camunda.graphqls`
Introspection
-------------For interactive GraphQL code completion, build-time validation, GraphQL Schema stiching or other fancy things
any GraphQL client can use GraphQLs Introspection to retrieve the whole or parts of the Servers GraphQL Schema.This is a possible and probably quite complete _Introspection Query_ (from [GraphQL Voyager](https://apis.guru/graphql-voyager/)):
```
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
}
}
}
}
}
}
}
}
```
The **response** of the above Introspection Query can be pasted into tools like [GraphQL Voyager](https://apis.guru/graphql-voyager/) as a _Custom Schema_
and within seconds you get a graphical representation of your Schema, like so:![graphical GraphQL Schema](extension/src/main/resources/png/graphql_voyager.png?raw=true "graphical GraphQL Schema")
Awesome!
Authentication
--------------
The Camunda GraphQL server supports three Authentication methods:
* Basic
* JWT ([JSON Web Token](https://jwt.io))
* No authenticationProperties which manage authentication are:
* `auth.Filter`
* `JWT.secret`
* `JWT.issuer`
These properties can be set as
* JNDI attributes from `java:comp/env`
* Java System properties
* OS environment variables
* properties in [application.properties](https://github.com/camunda/camunda-bpm-graphql/blob/master/src/main/resources/application.properties)E.g. if you are using Tomcat you can add them to catalina.properties.
If authentication is switched on (Basic or JWT) the Camunda GraphQL Server expects an Authorization-Header in the client request.
GraphQL clients let you define these request headers, e.g. the [graphiql-app](https://github.com/skevy/graphiql-app) has a link _Edit HTTP headers![http headers 01](extension/src/main/resources/png/http_headers_01.png?raw=true "http headers")
![http headers 02](extension/src/main/resources/png/http_headers_02.png?raw=true "http headers details")
Basic Authentication
--------------------To switch to Basic Authentication use:
`auth.Filter=BASIC`For example if you have a Camunda user `demo` with the password `demo` your Authorization-Header must be:
Key=`Authorization`
Value=`Basic ZGVtbzpkZW1v` ([why?](https://en.wikipedia.org/wiki/Basic_access_authentication))
JWT ([JSON Web Token](https://jwt.io)) Authentication
------------------To switch to JWT you must set three properties:
`auth.Filter=JWT`
`JWT.secret=Whatever_Random_Secret_String_You_Prefer`
`JWT.issuer=Usualy_The_Name_Of_Your_Company`
A JWT Authorization-Header could look like this:
Key=`Authorization`
Value=`Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJjYW11bmRhIiwiZXhwIjoxNDk3NzA4NjY3LCJpYXQiOjE0OTc2MjIyNjcsInVzZXJuYW1lIjoiZGVtbyJ9.Z-7NTGsHYqsEoc98yOgeT5LD9oGnei6jDPs-FQQhqDw`**Important!**
The GraphQL Server can validate **existing** JSON Web Token presented in the Authorization-Header based on
`JWT.secret`
`JWT.issuer`
(future releases will support private/public key)
but cannot provide or issue them. There is no login functionality "out of the box"
There is no JWT provider build into Camunda GraphQL server, because that does not belong to GraphQL at all.
**Workaround (in case you do not have a JWT provider)**
To create valid JWTs you need a JWT provider.
A JWT provider for Camunda can be found here: https://github.com/Loydl/camunda-jwt-provider
The `JWT.secret` and `JWT.issuer` settings of the
- JWT provider
- and the Camunda GraphQL server
must be the same, otherwise the JWT cannot be validated and user do not get authenticated.
(BTW, this is also a good option to basically implement Single Sign On).
Further information about JWT: https://jwt.ioNo Authentication
-----------------To switch off authentication you simply set:
`auth.Filter=NO`
or delete this property, e.g. in catalina.properties put it in a comment:
`#auth.Filter=xyz`
(If the value of `auth.Filter` is equal `JWT` or `BASIC` than authentication is switched on, otherwise it is switched off.)Goals
---------
- expose the complete Camunda Java API in GraphQL
- build modern web and mobile clients for Camunda Platform (freedom to choose your GUI library)
- build GraphQL-based, customizable versions of **Tasklist, Cockpit, Admin**
- Camunda BPM as part of a micro-services architecture. Service accessible through a GraphQL endpoint
(using GraphQL Schema Stiching to combine many GraphQL endpoints to one GraphQL API gateway)
- Realtime GUIs (add GraphQL subscriptions to Camunda GraphQL)Camunda Forum Thread (initial)
------------------------------https://forum.camunda.org/t/developing-the-camunda-graphql-extension