GraphQL API
GraphQL is a query language for APIs. You can use it to request the exact data you need, and therefore limit the number of requests you need.
GraphQL data is arranged in types, so your client can use client-side GraphQL libraries to consume the API and avoid manual parsing.
The GraphQL API is versionless.
Accessing GraphIQL
The easiest way to use the GraphQL API is through GraphIQL
using the following steps.
- Sign into IRIDA Next
http://my.irida.server/users/sign_in
- Go to the GraphIQL url
http://my.irida.server/graphiql
You will be greeted with the in browser tool for writing, validating and testing GraphQL queries.
For more on GraphIQL see the official docs
GraphQL Examples
Example | Query | Response |
Get Current User |
|
|
Get Samples |
|
|
Get a specific samples details |
|
|
Authentication with Personal Access Tokens
To use the GraphQL API with any of the GraphQL Clients, you will need to generate a Personal Access Token.
Navigate to the Access Tokens screen
Once you are signed in to IRIDA Next follow these steps.
- From the top bar on the left sidebar, select the Profile Icon next to the plus sign
- From the drop down options, select Edit profile
- From the left sidebar, select Access Tokens
This page lets you add new personal access tokens, and view/remove existing tokens.
Token Scopes
There are 2 scopes for your access token, api
and read_api
If your GraphQL queries will only be reading data, and not making any changes, select read_api
.
If your GraphQL queries will be modifying data or uploading new data, select api
.
Generate a Token
When Create personal access token
is clicked, a secret token will be generated for you. This will be used to authenticate your GraphQL API requests.
It is important that you do not share this token with anyone else as it is directly tied to your account.
Using Token for Sessionless Authentication
Tokens generated by IRIDA Next are Basic Authentication
tokens. They are tied to your email.
This uses Basic HTTP Authentication, in the form of $USEREMAIL:$ACCESSTOKEN that is Base64 encoded.
e.g. admin@email.com:yK1euURqVRtQ1D-3uKsW
becomes YWRtaW5AZW1haWwuY29tOnlLMWV1VVJxVlJ0UTFELTN1S3NX
Which would be used like the following:
e.g. Authorization: Basic YWRtaW5AZW1haWwuY29tOnlLMWV1VVJxVlJ0UTFELTN1S3NX
You can test your token by doing the encoding and executing the following curl
command.
curl "http://localhost:3000/api/graphql" --header "Authorization: Basic <your token here>" --header "Content-Type: application/json" --request POST --data "{\"query\": \"query {currentUser{email}}}\"}"
response
{"data":{"currentUser":{"email":"admin@email.com"}}}