Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add @graphiql/plugin-batch-request #2994

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
59 changes: 58 additions & 1 deletion packages/graphiql-plugin-batch-request/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,58 @@
# GraphiQL Batch Request Plugin
# GraphiQL Batch Request Plugin

This package provides a plugin that allows sending a batch request to a GraphQL Server into the GraphiQI UI.
samuelAndalon marked this conversation as resolved.
Show resolved Hide resolved

## Install

Use your favoriton package manager to install the package:

```sh
npm i -S @graphiql/plugin-batch-request
```

The following packages are peer dependencies, so make sure you have them installed as well:

```sh
npm i -S react react-dom graphql
```

## Usage

The plugin scope is for sending multiple GraphQL operations as an array, so GraphQL server requires to be configured to allow
arrays.
samuelAndalon marked this conversation as resolved.
Show resolved Hide resolved

```jsx
import { useBatchRequestPlugin } from '@graphiql/plugin-batch-request';
import { createGraphiQLFetcher } from '@graphiql/toolkit';
import { GraphiQL } from 'graphiql';
import { useState } from 'react';

import 'graphiql/graphiql.css';
import '@graphiql/plugin-batch-request/dist/style.css';

const url = 'https://countries.trevorblades.com/graphql';

const fetcher = createGraphiQLFetcher({
url
});

function GraphiQLWithExplorer() {
const [query, setQuery] = useState(DEFAULT_QUERY);
const batchRequestPlugin = useBatchRequestPlugin({ url });
return (
<GraphiQL
fetcher={fetcher}
query={query}
onEditQuery={setQuery}
plugins={[batchRequestPlugin]}
/>
);
}
```


### Example

Sending a batch request to spacex GraphQL server:

https://user-images.githubusercontent.com/6611331/212411159-336abe77-5f0a-4453-9de3-62abe039168f.mov