0.0.47 • Published 5 months ago

@inigolabs/graphql-explorer v0.0.47

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

GraphQL Explorer Component for React

This repository contains an open-source GraphQL Explorer Component for React, enabling developers to easily integrate an interactive GraphQL playground into their React applications.

Features

The GraphQL Explorer is designed with developers in mind, offering features that simplify workflows and enhance productivity. Here’s what it includes:

  • Query Builder: Construct complex GraphQL queries with an easy-to-use interface.
  • History: Quickly access and reuse previous queries.
  • Saved Collections: Keep your frequently used queries organized and ready.
  • Define Extension Headers: Customize and add extension headers to your GraphQL requests for advanced use cases.
  • Share Queries: Share queries with others, whether or not they include variables.
  • Multi-Tab Support: Work on multiple queries simultaneously for better multitasking.
  • Run 10x Options: Send multiple queries at once to test performance and scalability.
  • Response Viewer with Headers: Debug effectively with detailed response and header insights.
  • Schema Viewer: Navigate and explore your schema with a visual overview.
  • PreFlight Scripts: Set up login or other pre-configurations before running queries.
  • Local Preferences: Save and retrieve user preferences, such as layout and active tabs.

Installation

Install the package via npm or yarn:

npm install @inigolabs/graphql-explorer

or

yarn add @inigolabs/graphql-explorer

Usage

Import the Explorer component and include it in your application. The defaultState prop is required to initialize the explorer.

import "@inigolabs/graphql-explorer/styles";
import Explorer from "@inigolabs/graphql-explorer";

function App() {
  const defaultState = {};

  return (
    <div>
      <Explorer
        defaultState={defaultState}
        onStateChange={(state) => console.log("Explorer state updated:", state)}
      />
    </div>
  );
}

API

Props

PropTypeRequiredDescription
theme"light" \| "dark"NoSets the theme for the explorer interface.
access"admin" \| "user"NoSpecifies the access level of the current user.
defaultStateExplorerStateYesInitial state for the explorer, including tabs, collections, and layout preferences.
onStateChange(state: ExplorerState) => voidNoCallback triggered when the state of the explorer changes.

ExplorerState Description

The ExplorerState object represents the state of the GraphQL Explorer, which is essential for initializing and managing the component's behavior.

Structure

KeyTypeDescription
urlstringThe base URL for the GraphQL endpoint.
collectionsExplorerCollection[]Saved collections of reusable queries and their variables.
historyExplorerTabHistoryItem[]History of previously executed queries.
headersstringJSON string representing custom headers for GraphQL requests.
envVariablesstringJSON string of environment variables used during queries.
preflightScriptstringScript executed before sending requests, useful for custom logic.
preflightEnabledbooleanFlag indicating if the preflight script is enabled.
tabsExplorerTab[]Array of tabs representing open queries in the explorer.
activeTabIdstringThe ID of the currently active tab.
proxyEnabledbooleanFlag indicating if a proxy is enabled for requests.
historyEnabledbooleanFlag indicating if query history is enabled.
layout{ tab?: [number, number]; request?: [number, number] }Layout configuration for the explorer's UI components, such as tab and request panels.

Children Types

ExplorerCollection

Represents a collection of saved queries.

KeyTypeDescription
idstringUnique identifier for the collection.
namestringName of the collection.
operationsExplorerCollectionOperation[]List of operations (queries) in the collection.

ExplorerCollectionOperation

Represents an operation (query) within a collection.

KeyTypeDescription
namestringName of the operation.
querystringGraphQL query string.
variablesstringJSON string of query variables.

ExplorerTab

Represents a tab in the explorer.

KeyTypeDescription
idstringUnique identifier for the tab.
querystringThe GraphQL query in the tab.
variablesstringJSON string of variables associated with the query.
responseExplorerTabInfoResponseThe response data for the query.
docReturnType<typeof parse>Parsed GraphQL document from the query.

ExplorerTabHistoryItem

Extends ExplorerTab with additional metadata for history entries.

KeyTypeDescription
operationNamestringThe name of the operation in the history.
createdAtstringTimestamp when the history entry was created.

ExplorerTabInfoResponse

Represents the response information for a tab's query.

KeyTypeDescription
dataanyThe response data from the query.
headersanyHeaders returned from the response.
statusnumberHTTP status code of the response.
sizenumberSize of the response data in bytes.
timenumberTime taken for the request in milliseconds.

Contribution

We welcome contributions to enhance this component. Please follow these steps:

  1. Fork the repository.
  2. Install dependencies: npm install
  3. Start the development server: npm run dev
  4. Create a new branch: git checkout -b feature-name.
  5. Commit your changes: git commit -m 'Add feature'.
  6. Push the branch: git push origin feature-name.
  7. Submit a pull request.

FAQ

  • To run the Expoler on Next JS, disable server side rendering.
  • create-react-app is deprecated and no longer supported.

License

This project is licensed under the MIT License. See the LICENSE file for details.

0.0.47

5 months ago

0.0.46

5 months ago

0.0.45

5 months ago

0.0.44

5 months ago

0.0.43

5 months ago

0.0.42

6 months ago

0.0.41

6 months ago

0.0.40

7 months ago

0.0.39

7 months ago

0.0.38

7 months ago

0.0.37

7 months ago

0.0.36

7 months ago

0.0.35

7 months ago

0.0.34

7 months ago

0.0.33

7 months ago

0.0.32

7 months ago

0.0.31

7 months ago

0.0.30

7 months ago

0.0.29

8 months ago

0.0.28

8 months ago

0.0.27

8 months ago

0.0.26

8 months ago

0.0.25

8 months ago

0.0.24

8 months ago

0.0.23

8 months ago

0.0.22

8 months ago

0.0.21

8 months ago

0.0.20

8 months ago

0.0.19

8 months ago

0.0.18

8 months ago

0.0.17

8 months ago

0.0.16

9 months ago

0.0.15

9 months ago

0.0.14

9 months ago

0.0.13

9 months ago

0.0.12

9 months ago

0.0.11

9 months ago

0.0.10

9 months ago

0.0.9

9 months ago

0.0.8

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

10 months ago