|
| 1 | +# How to Run A GraphQL Query |
| 2 | + |
| 3 | +This guide explains how to run a GRAPHQL query for workflows using the Workflows |
| 4 | +Dashboard or alternative tools. |
| 5 | +The Workflows Dashboard does provide a GraphiQL client to write queries to |
| 6 | +the GraphQL endpoint which is shown below. |
| 7 | + |
| 8 | +## Available Endpoints |
| 9 | +[Production](https://workflows.diamond.ac.uk/graphql) |
| 10 | + |
| 11 | +[Staging](https://staging.workflows.diamond.ac.uk/graphql) |
| 12 | + |
| 13 | +## The Dashboard |
| 14 | + |
| 15 | +The Workflows Dashboard includes a built-in GraphiQL client for writing and testing queries against |
| 16 | +the GRAPHQL endppoint. |
| 17 | + |
| 18 | +### iGraphQL Client |
| 19 | + |
| 20 | + |
| 21 | +## Exploring the Schema |
| 22 | + |
| 23 | +Click the *Docs* button (top-left) to browse the schema. |
| 24 | +Alternatively, use Ctrl - Space inside the query editor to view available fields an options. |
| 25 | + |
| 26 | +### Example Query |
| 27 | + |
| 28 | +``` |
| 29 | +query WorkflowTemplates { |
| 30 | + workflowTemplates(limit: 4) { |
| 31 | + edges { |
| 32 | + node { |
| 33 | + name |
| 34 | + maintainer |
| 35 | + suite |
| 36 | + description |
| 37 | + arguments |
| 38 | + uiSchema |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +## Adding Authentication |
| 46 | + |
| 47 | +All queries require an *authentication token* in the request headers. |
| 48 | + |
| 49 | +Add the following header: |
| 50 | +```JSON |
| 51 | +{ |
| 52 | + "Authorization": "Bearer <your-access-token>" |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +### Obtaining a Token |
| 57 | +Run the following command to get a token in with the correct client id. |
| 58 | +Please take attention to which oidc-client-id you are using. |
| 59 | +Enter your username and password if prompted. |
| 60 | + |
| 61 | +```sh |
| 62 | +module load argus |
| 63 | +# Production |
| 64 | +kubectl oidc-login get-token --oidc-issuer-url=https://authn.diamond.ac.uk/realms/master --oidc-client-id=workflows-cluster --grant-type=password --oidc-use-access-token | jq -r '.status.token' |
| 65 | +# Staging |
| 66 | +kubectl oidc-login get-token --oidc-issuer-url=https://authn.diamond.ac.uk/realms/master --oidc-client-id=workflows-cluster-staging --grant-type=password --oidc-use-access-token | jq -r '.status.token' |
| 67 | +``` |
| 68 | + |
| 69 | +Paste the token into the *Authorization* header before executing your query. |
| 70 | + |
| 71 | +## Further Reading |
| 72 | + |
| 73 | +For more information on how to use the GraphQL Dashboard please have a look at the official |
| 74 | +GraphiQL docs [here](https://github.com/graphql/graphiql) |
| 75 | + |
| 76 | +## Alternative Clients |
| 77 | + |
| 78 | +There are alternative clients that can be used such as [*Postman*.](https://www.postman.com/) |
| 79 | +When configuring authorization for these tools: |
| 80 | +- store any sensitive data (passwords, tokens) securley as variables |
| 81 | +- avoid hardcoding credentials in requests |
| 82 | + |
0 commit comments