npm.io
1.0.1 • Published 1 month ago

@apollo-link-debug/handle-request

Licence
MIT
Version
1.0.1
Deps
0
Size
4 kB
Vulns
0
Weekly
0

Debugs the operation name and variables used for a GraphQL request via apollo.

Installation

Requires @apollo/client v4.

npm i @apollo/client @apollo-link-debug/handle-request
# - or -
yarn add @apollo/client @apollo-link-debug/handle-request

Usage

import { ApolloClient, ApolloLink, InMemoryCache } from "@apollo/client";
import { RequestLink } from "@apollo-link-debug/handle-request";

const client = new ApolloClient({
  uri: "https://localhost:3000/",
  cache: new InMemoryCache(),
  link: ApolloLink.from([new RequestLink()]),
});

const query = client.query({
  query: gql`query MyOperationName { ... }`,
  variables: {
    variableName: "variableValue",
  },
});

Example output:

MyOperationName {
  "variableName": "variableValue"
}

Options

onRequest: ({ operation }) => void

A callback which occurs on every GraphQL request as the request is made. The default is to log the operation name and the variables (as JSON) used for the query.