AeroGear DataSync GraphQL based server and React Client
Starter includes:
-
Integration with Graphback (http://graphback.dev) that helps you to generate your backend and client side queries based on user provided business model
-
Example React application that uses Offix client (http://offix.dev) to give you fully featured offline experience.
-
Integration with Keycloak (SSO) for server and client Authentication and User management.
-
GraphQL Subscriptions backed by an MQTT broker (AMQ)
The mobile application uses Offix Client to provide additional offline capabilities on top of Apollo GraphQL.
The GraphQL server uses Graphback to provide GraphQL capabilities.
Requirements:
-
Docker and docker-compose
-
Node.js 12.x or above
-
(optional) access to a running OpenShift instance
Install dependencies
-
Build client
yarn
-
Build client
yarn yarn prepare:client
-
Start the server
cd ./server docker-compose up -d yarn start
Follow these instructions to set up Keycloak for Authentication/Authorization.
-
Start Keycloak Server
cd server npm run keycloak
-
Configure the Keycloak Server
cd server npm run keycloak:init
This command creates the necessary resources in Keycloak and prints instructions you must follow to enable the integration.
Follow the instructions and copy the JSON configurations to the appropriate locations. The DataSync Starter app and server will read these configurations and the integration will be enabled when they are started.
By default, two users that can log into the application are created.
-
username:
developer
, password:developer
-
username:
admin
, password:admin
The GraphQL playground is available after a Keycloak login screen. Initially the following error will be displayed.
{
"error": "Failed to fetch schema. Please check your connection"
}
The playground must be configured to send the Keycloak Authorization
header with requests to the GraphQL server.
In the bottom left corner of the playground there is a field called HTTP Headers which will be added to requests sent by the playground.
Use scripts/getToken.js
to get a valid header for the developer
user.
The following script can be used to get a token for the default Keycloak credentials
cd server/scripts/keycloak
node getToken.js
Alternatively, the user-defined username and password can be passed into the script as arguments, as below
node getToken.js <username> <password>
The output will be in the form of a JSON object
{"Authorization":"Bearer <token string>"}
Copy the entire JSON object, then paste it into the HTTP Headers field in the playground. The error message should disappear and it is now possible to use the playground.
Note
|
The GraphQL server is using a public Keycloak client to redirect browsers to the login page. This is useful for testing the server locally but it is not recommended for production. For production GraphQL server applications you should use a bearer client.
|
Note
|
If Keycloak integration is enabled on the server, and the Keycloak server is running using a self-signed certificate, please make sure set this environment variable before running the server: export NODE_TLS_REJECT_UNAUTHORIZED=0 |
-
Install Ionic
npm install -g @ionic/cli
-
Change directory
cd client
-
Install dependencies
npm install
-
Start the app
npm run start
Rename keycloak.example.json
file in the public
directory to keycloak.json
. Replace the contents of the file
with the keycloak json object generated during the keycloak integration init script.
{
"realm": "<your realm>",
"auth-server-url": "https://your-server/auth",
"ssl-required": "none",
"resource": "<your-client>",
"public-client": true,
"use-resource-role-mappings": true,
"confidential-port": 0
}
NoteWhen running in cloud, developers can swap this file dynamically using config-map or openshift secret
-
Go to scripts ./mqtt
-
Execute docker-compose up
-
Set MQTT_HOST environment variable in .env file
MQTT_HOST=127.0.0.1
Please check .openshift folder for more information.