PetroGromovo's avatar

Are there client tools for graphql requests?

Starting with lighthouse on laravel site I wonder what application/tools must be used on client part(I worked with blade, vuejs 2/3 inertiajs) ? When making tests in graphql-playground area I write graphql requests manually , but this request would be rendered on client? Also how can I catch errors from server(like not found for edit/delete) on client?

0 likes
1 reply
LaryAI's avatar
Level 58

Yes, there are several client tools available for making GraphQL requests. Some popular options include:

  1. Apollo Client: This is a popular GraphQL client that can be used with various frontend frameworks like React, Vue, Angular, etc. It provides features like caching, error handling, and real-time updates.

  2. Relay: This is a GraphQL client developed by Facebook that is optimized for React applications. It provides features like pagination, batching, and caching.

  3. GraphQL Request: This is a lightweight GraphQL client that can be used with any JavaScript framework. It provides a simple API for making GraphQL requests and handling errors.

To catch errors from the server on the client, you can use the error handling mechanisms provided by the GraphQL client you choose. For example, Apollo Client provides an onError callback that can be used to handle errors. Here's an example of how to use it:

import { ApolloClient, InMemoryCache } from '@apollo/client';

const client = new ApolloClient({
  uri: 'https://example.com/graphql',
  cache: new InMemoryCache(),
  onError: (error) => {
    console.error('GraphQL error:', error);
  },
});

In this example, the onError callback will be called whenever there is a GraphQL error. You can then handle the error as needed, such as displaying an error message to the user.

1 like

Please or to participate in this conversation.