Querying with GraphQL#
- You’ll need an app for sending and receiving GraphQL queries. We recommend GraphiQL.
- If you’re using Homebrew, you can install it with
brew install --cask graphiql
.
- If you’re using Homebrew, you can install it with
- We need to tell Lagoon Core about the Kubernetes cluster. The GraphQL endpoint is:
https://<YOUR-API-URL>/graphql
- Go to Edit HTTP Headers, and Add Header.
- Header Name:
Authorization
- Value:
Bearer YOUR-TOKEN-HERE
- In your home directory, the Lagoon CLI has created a
.lagoon.yml
file. Copy the token from that file and use it for the value here. - Save.
- Header Name:
-
Now you’re ready to run some queries. Run the following test query to ensure everything is working correctly:
query allProjects {allProjects {name } }
-
This should give you the following response:
{ "data": { "allProjects": [] } }
-
Once you get the correct response, we need to add a mutation.
-
Run the following query:
mutation addKubernetes { addKubernetes(input: { name: "<TARGET-NAME-FROM-REMOTE-VALUES.yml>", consoleUrl: "<URL-OF-K8S-CLUSTER>", token: "xxxxxx” routerPattern: "${environment}.${project}.lagoon.example.com" }){id} }
- consoleUrl: API Endpoint of Kubernetes Cluster
- token: create a token for the lagoon-build-deploy service account
kubectl -n lagoon create token lagoon-build-deploy --duration 3h
Prior to Kubernetes 1.21:
use the lagoon-build-deploy token installed by lagoon-remote
kubectl -n lagoon describe secret \
$(kubectl -n lagoon get secret | grep lagoon-build-deploy | awk '{print $1}') | grep token: | awk '{print $2}'
Note:
Note: Authorization tokens for GraphQL are very short term so you may need to generate a new one. Run lagoon login
and then cat the .lagoon.yml
file to get the new token, and replace the old token in the HTTP header with the new one.