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.
- In your home directory, the Lagoon CLI has created a
- Save.
- 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": [] } }
- Read more about GraphQL here in our documentation.
- 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:
kubectl -n lagoon describe secret $(kubectl -n lagoon get secret | grep kubernetes-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.