/Aqls-client

Primary LanguageJavaScriptMIT LicenseMIT

Aqls-Client

Overview

GraphQL analytics toolkit and dashboard that integrate with Apollo Client and Apollo Server Express. It is an easy to use analytics suite that monitors GraphQL subscriptions concurrency, latency, errors, and resolver frequency. Our integrated dashboard displays your GraphQL analytics on dynamic and interactive charts.

This package is for setting up your client-side. For the server-side package please refer to the Aqls-server package.

Note: Aqls is currently in BETA and improvements will continue to be implemented. If any issues are encountered while using our application, please submit a PR.

Requirements

  • React version 16.8+
  • apollo-client version 3.2.1+

Install

With npm:

npm install --save @aqls/client

Tracking GraphQL Subscriptions

  • 1. Import useqAqlSubscription:
import { useAqlSubscription } from '@aqls/client';

  • 2. Include aql in GraphQL query:
const colorSubscription = gql`
    subscription {
      updatedColor {
        cssColor
        aql {
          mutationSendTime
          mutationReceived
          subscriberReceived
          mutationId
          resolver
          userToken
        }
      }
    }
  `;

  • 3. Invoke useAqlSubscription hook:
 const { data, loading, error } = useAqlSubscription(
    graphQLQuery,
    { optionsObject },
    subscriptionResolver,
  );

Note: optionsObject accepts any options available in the Apollo-client useSubscription hook

useAqlSubscription hook example:

 const { data, loading, error } = useAqlSubscription(
    colorSubscription,
    {
      onSubscriptionData: (client) => {
        setColor(client.subscriptionData.data.updatedColor.cssColor);
      },
    },
    'updatedColor',
  );

Tracking GraphQL Mutations

  • 1. Import useqAqlMutation:
import { useAqlMutation } from '@aqls/client';

  • 2. Invoke useAqlMutation hook:
useAqlMutation(query)

This hook takes a GraphQL query and automatically injects analytics into it. You can use .then() if you want to access async functionality. Below is an example using the hook as part of a click handler.

const handleClick = (chosenColor) => {
    const colorQuery = `mutation{newColor(colorArg: "${chosenColor}"){id cssColor}}`;
    useAqlMutation(colorQuery)
      .then((data) =>
        setColor(data.chosenColor)
      )
      .catch((err) => setError(err));

  • Lastly, Connect with the Aqls Team!

aqlorgteam@gmail.com

Case Simmons: Case's Github and Case's LinkedIn

Julie Pinchak: Julie's Github and Julie's LinkedIn

Michael O'Halloran: Michael's Github and Michael's LinkedIn

Rocio Infante: Rocio's Github and Rocio's LinkedIn