Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@graphiql/react

Package Overview
Dependencies
Maintainers
5
Versions
288
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphiql/react

[Changelog](https://github.com/graphql/graphiql/blob/main/packages/graphiql-react/CHANGELOG.md) | [API Docs](https://graphiql-test.netlify.app/typedoc/modules/graphiql_react.html) | [NPM](https://www.npmjs.com/package/@graphiql/react)

  • 0.27.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
Created

What is @graphiql/react?

@graphiql/react is a React component library for building GraphiQL interfaces. It provides a set of React components that can be used to create a GraphQL IDE within your React application, allowing for easy querying, mutation, and schema exploration.

What are @graphiql/react's main functionalities?

GraphiQL Component

This code demonstrates how to use the GraphiQL component from @graphiql/react to create a GraphQL IDE within a React application. The fetcher function is used to send GraphQL queries to a specified endpoint.

import React from 'react';
import { GraphiQL } from '@graphiql/react';
import '@graphiql/react/dist/style.css';

const App = () => (
  <div style={{ height: '100vh' }}>
    <GraphiQL fetcher={async graphQLParams => {
      const data = await fetch('https://my-graphql-endpoint.com/graphql', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify(graphQLParams),
      });
      return data.json();
    }} />
  </div>
);

export default App;

Custom Toolbar

This code demonstrates how to add a custom toolbar button to the GraphiQL interface. The CustomToolbar component includes a ToolbarButton that triggers an alert when clicked.

import React from 'react';
import { GraphiQL, ToolbarButton } from '@graphiql/react';
import '@graphiql/react/dist/style.css';

const CustomToolbar = () => (
  <GraphiQL.Toolbar>
    <ToolbarButton onClick={() => alert('Custom Button Clicked!')} title="Custom Button" />
  </GraphiQL.Toolbar>
);

const App = () => (
  <div style={{ height: '100vh' }}>
    <GraphiQL fetcher={async graphQLParams => {
      const data = await fetch('https://my-graphql-endpoint.com/graphql', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify(graphQLParams),
      });
      return data.json();
    }}>
      <CustomToolbar />
    </GraphiQL>
  </div>
);

export default App;

Custom Query Editor

This code demonstrates how to use a custom query editor within the GraphiQL interface. The CustomQueryEditor component initializes the query editor with a default query and logs any changes to the console.

import React from 'react';
import { GraphiQL, QueryEditor } from '@graphiql/react';
import '@graphiql/react/dist/style.css';

const CustomQueryEditor = () => (
  <QueryEditor value="{ hello }" onEdit={newQuery => console.log(newQuery)} />
);

const App = () => (
  <div style={{ height: '100vh' }}>
    <GraphiQL fetcher={async graphQLParams => {
      const data = await fetch('https://my-graphql-endpoint.com/graphql', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify(graphQLParams),
      });
      return data.json();
    }}>
      <CustomQueryEditor />
    </GraphiQL>
  </div>
);

export default App;

Other packages similar to @graphiql/react

Keywords

FAQs

Package last updated on 09 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc