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
. -
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.
-
Now you’re ready to run some queries. Run the following test query to ensure everything is working correctly:
Get all projectsquery allProjects {allProjects {name } }
-
This should give you the following response:
{
"data": {
"allProjects": []
}
}
Read more about GraphQL here in our documentation.
-
Once you get the correct response, we need to add a mutation.
-
Run the following query:
Add mutationmutation addKubernetes { addKubernetes(input: { name: "<TARGET-NAME-FROM-REMOTE-VALUES.yml>", consoleUrl: "<URL-OF-K8S-CLUSTER>", token: "xxxxxx” routerPattern: "${environment}.${project}.lagoon.example.com" }){id} }
name
: get fromlagoon-remote-values.yml
consoleUrl
: API Endpoint of Kubernetes cluster. Get fromvalues.yml
token
: get a token for thessh-core
service account
Get tokenkubectl -n lagoon get secret/lagoon-remote-ssh-core-token -o json | jq -r '.data.token | @base64d'
Info
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.