Introduction

Below is a description of consuming the API with different clients. We assume that at this stage you have already completed the steps included in the Getting Started section of this chapter and that you are familiar with the basic setup of the AVII GraphQL API.

Python

The API can be used from any client that supports GraphQL, here we’ll show examples to make some requests in python.

Using gql

from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport

_transport = RequestsHTTPTransport( 
  url='https://api.avii.ai/graphql', 
  use_json=True, )

_transport.headers = { 
  "User-Agent": "Mozilla/5.0 (X11; buntu; " + "Linux x86_64; rv:58.0) Gecko/0100101 Firefox/58.0", "Authorization": "Bearer {}".format(YOUR_TOKEN), 
  "content-type": "application/json", }
  
client = Client( transport=_transport, fetch_schema_from_transport=True, )

query = gql(
  """ { computerVisionModel { data(first: 10) { edges { node { id name precision recall} } } } } """)

print(client.execute(query))

Javascript

The API can be used from any client that supports GraphQL, here we’ll show examples to make some requests in javascript.

Using graphql-request

import { GraphQLClient} from 'graphql-request'

async function main() {
  const endpoint = 'https://api.avii.ai/graphql'

  const graphQLClient = new GraphQLClient(endpoint, {
    headers: {
      authorization: 'Bearer TOKEN',
    },
  })

  const query = /* GraphQL */ `
  { 
    computerVisionModel { 
      data(first: 10) { 
        edges { 
          node { 
            id 
            name 
            precision 
            recall
          } 
        } 
      } 
    } 
  }
  `
  const data = await graphQLClient.request(query)
  console.log(JSON.stringify(data, undefined, 2))
}

main().catch(error => console.error(error))