Skip to main content
GraphQL client libraries make it easier to work with the Pylon GraphQL API. They handle request formatting, error handling, caching, and more.

Apollo Client

Apollo Client is a popular GraphQL client for React, Vue, Angular, and vanilla JavaScript. Installation:
Setup:
Using with React:

graphql-request

A minimal GraphQL client that works in any JavaScript environment. Installation:
Usage:

Relay

Relay is Facebook’s GraphQL client, optimized for React. Installation:
Relay requires a more complex setup with a compiler. See the Relay documentation for details.

Authentication

All clients need to include the authorization header. Here are patterns for different clients:

Apollo Client

graphql-request

Custom fetch wrapper

Error handling

All clients should handle GraphQL errors:

Caching

Most GraphQL clients provide caching:

Apollo Client

Apollo Client automatically caches queries:

Manual caching

TypeScript support

Most clients support TypeScript. Generate types from your schema:

Using GraphQL code generator

codegen.yml:

Best practices

  1. Use a client library - Don’t manually construct requests
  2. Handle errors - Always check for GraphQL errors
  3. Use TypeScript - Generate types from your schema
  4. Implement caching - Reduce unnecessary requests
  5. Refresh tokens - Handle token expiration gracefully
  6. Use variables - Never hardcode values in queries

Next steps