URQL

URQL is a lighter library than the apollo client but allows you to query the API all the same.

Installing

open the terminal in your client and run:

$ npm install urql graphql

Usage

Exposing the client

You can create the URQLClient which you then use for all public API queries like:

import { createClient } from 'urql'

const APIURL = 'https://api-mumbai.lens.dev/';

export const urqlClient= new createClient({
  url: APIURL,
})

Querying the API

Then you can use it to query the Lens public API:

import { urqlClient } from './urql-client';

const pingQuery = `
  query {
    ping
  }
`

export const queryExample = async () => {
  const response = await urqlClient.query(pingQuery).toPromise();
  console.log('Lens example data: ', response)
}

Did this page help you?