Skip to content

Querying with GraphQL#

  1. You’ll need an app for sending and receiving GraphQL queries. We recommend GraphiQL.
  2. If you’re using Homebrew, you can install it with brew install --cask graphiql.
  3. We need to tell Lagoon Core about the Kubernetes cluster. The GraphQL endpoint is: https://<YOUR-API-URL>/graphql
  4. Go to Edit HTTP Headers, and Add Header.
  5. Header Name: Authorization
  6. Value: Bearer YOUR-TOKEN-HERE
    1. 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.
  7. Save.
  8. Now you’re ready to run some queries. Run the following test query to ensure everything is working correctly: query allProjects {allProjects {name } }
  9. This should give you the following response:

    {
      "data": {
        "allProjects": []
      }
    }
    
    1. Read more about GraphQL here in our documentation.
    2. Once you get the correct response, we need to add a mutation.
    3. 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}
     }
    
    1. consoleUrl: API Endpoint of Kubernetes Cluster
    2. 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.