Options
All
  • Public
  • Public/Protected
  • All
Menu

Package graphiql-react

Changelog | API Docs | NPM

@graphiql/react

A React SDK for building integrated GraphQL developer experiences for the web.

Purpose

This package contains a set of building blocks that allow its users to build GraphQL IDEs with ease. It's the set of components that make up GraphiQL, the first and official GraphQL IDE, owned and maintained by the GraphQL Foundation.

There are two kinds of building blocks that this package provides: Stateful context providers for state management and simple UI components.

Getting started

All the state for your GraphQL IDE lives in multiple contexts. The easiest way to get started is by using the GraphiQLProvider component that renders all the individual providers.

There is one required prop called fetcher. This is a function that performs GraphQL request against a given endpoint. You can easily create a fetcher using the method createGraphiQLFetcher from the @graphiql/toolkit package.

import { GraphiQLProvider } from '@graphiql/react';
import { createGraphiQLFetcher } from '@graphiql/toolkit';

const fetcher = createGraphiQLFetcher({
  url: 'https://my.graphql.api/graphql',
});

function MyGraphQLIDE() {
  return (
    <GraphiQLProvider fetcher={fetcher}>
      <div className="graphiql-container">Hello GraphQL</div>
    </GraphiQLProvider>
  );
}

Inside the provider you can now use any UI component provided by @graphiql/react. For example, you can render a query editor like this:

import { QueryEditor } from '@graphiql/react';

function MyGraphQLIDE() {
  return (
    <GraphiQLProvider fetcher={fetcher}>
      <div className="graphiql-container">
        <QueryEditor />
      </div>
    </GraphiQLProvider>
  );
}

The package also ships the necessary CSS that all its UI components need. You can import them from @graphiql/react/style.css.

Note: In order for these styles to apply, the UI components need to be rendered inside an element that has a class name graphiql-container.

By default, the UI components will try to use the Roboto font for regular text and the Fira Code font for mono-space text. If you want to use the default fonts you can load them using these files:

  • @graphiql/react/font/roboto.css
  • @graphiql/react/font/fira-code.css.

You can of course use any other method to load these fonts (for example loading them from Google Fonts).

Further details on how to use @graphiql/react can be found in the reference implementation of a GraphQL IDE - GraphiQL - in the graphiql package.

Available contexts

There are multiple contexts that own different parts of the state that make up a complete GraphQL IDE. For each context there is a provider component (<name>ContextProvider) that makes sure the context is initialized and managed properly. These components contains all the logic related to state management. In addition, for each context there is also a hook (use<name>Context) that allows you to consume its current value.

Here is a list of all contexts that come with @graphiql/react

  • StorageContext: Provides a storage API that can be used to persist state in the browser (by default using localStorage)
  • EditorContext: Manages all the editors and tabs
  • SchemaContext: Fetches, validates and stores the GraphQL schema
  • ExecutionContext: Executes GraphQL requests
  • HistoryContext: Persists executed requests in storage
  • ExplorerContext: Handles the state for the docs explorer

All context properties are documented using JSDoc comments. If you're using an IDE like VSCode for development these descriptions will show up in auto-complete tooltips. All these descriptions can also be found in the API Docs.

Theming

All the components from @graphiql/react have been designed with customization in mind. We achieve this using CSS variables.

All variables that are available for customization can be found in the root.css file.

Colors

Colors are defined using the HSL format. All CSS variables for colors are defined as a list of the three values that make up HSL (hue, saturation and lightness).

This approach allows @graphiql/react to use transparent colors by passing the value of the CSS variable in the hsla function. This enables us to provide truly reusable UI elements where good contrasts are preserved regardless of the elements background.

Development

If you want to develop with @graphiql/react locally - in particular when working on the graphiql package - all you need to do is run yarn dev in the package folder in a separate terminal. This will build the package using Vite. When using it in combination with yarn dev:graphiql (running in the repo root) this will give you auto-reloading when working on graphiql and @graphiql/react simultaneously.

Index

References

Type aliases

Variables

Functions

Object literals

References

ArgumentIcon

Re-exports ArgumentIcon

Button

Re-exports Button

Button

Re-exports Button

ButtonGroup

Re-exports ButtonGroup

ButtonGroup

Re-exports ButtonGroup

ChevronDownIcon

Re-exports ChevronDownIcon

ChevronLeftIcon

Re-exports ChevronLeftIcon

ChevronUpIcon

Re-exports ChevronUpIcon

CloseIcon

Re-exports CloseIcon

CommonEditorProps

Re-exports CommonEditorProps

CommonEditorProps

Re-exports CommonEditorProps

CopyIcon

Re-exports CopyIcon

DeprecatedArgumentIcon

Re-exports DeprecatedArgumentIcon

DeprecatedEnumValueIcon

Re-exports DeprecatedEnumValueIcon

DeprecatedFieldIcon

Re-exports DeprecatedFieldIcon

Dialog

Re-exports Dialog

Dialog

Re-exports Dialog

DialogRoot

Re-exports DialogRoot

DialogRoot

Re-exports DialogRoot

DirectiveIcon

Re-exports DirectiveIcon

DocsFilledIcon

Re-exports DocsFilledIcon

DocsIcon

Re-exports DocsIcon

DropdownMenu

Re-exports DropdownMenu

DropdownMenu

Re-exports DropdownMenu

EditorContext

Re-exports EditorContext

EditorContext

Re-exports EditorContext

EditorContextProvider

Re-exports EditorContextProvider

EditorContextProvider

Re-exports EditorContextProvider

EditorContextType

Re-exports EditorContextType

EditorContextType

Re-exports EditorContextType

EnumValueIcon

Re-exports EnumValueIcon

ExecuteButton

Re-exports ExecuteButton

ExecuteButton

Re-exports ExecuteButton

ExecutionContext

Re-exports ExecutionContext

ExecutionContextProvider

Re-exports ExecutionContextProvider

ExecutionContextType

Re-exports ExecutionContextType

FieldIcon

Re-exports FieldIcon

GraphiQLPlugin

Re-exports GraphiQLPlugin

GraphiQLProvider

Re-exports GraphiQLProvider

HeaderEditor

Re-exports HeaderEditor

HeaderEditor

Re-exports HeaderEditor

HeaderEditor

Re-exports HeaderEditor

HistoryIcon

Re-exports HistoryIcon

ImagePreview

Re-exports ImagePreview

ImagePreview

Re-exports ImagePreview

ImagePreview

Re-exports ImagePreview

ImplementsIcon

Re-exports ImplementsIcon

KeyMap

Re-exports KeyMap

KeyMap

Re-exports KeyMap

KeyboardShortcutIcon

Re-exports KeyboardShortcutIcon

MagnifyingGlassIcon

Re-exports MagnifyingGlassIcon

MarkdownContent

Re-exports MarkdownContent

MarkdownContent

Re-exports MarkdownContent

MergeIcon

Re-exports MergeIcon

PenIcon

Re-exports PenIcon

PlayIcon

Re-exports PlayIcon

PluginContext

Re-exports PluginContext

PluginContextProvider

Re-exports PluginContextProvider

PluginContextType

Re-exports PluginContextType

PlusIcon

Re-exports PlusIcon

PrettifyIcon

Re-exports PrettifyIcon

QueryEditor

Re-exports QueryEditor

QueryEditor

Re-exports QueryEditor

QueryEditor

Re-exports QueryEditor

ReloadIcon

Re-exports ReloadIcon

ResponseEditor

Re-exports ResponseEditor

ResponseEditor

Re-exports ResponseEditor

ResponseEditor

Re-exports ResponseEditor

ResponseTooltipType

Re-exports ResponseTooltipType

ResponseTooltipType

Re-exports ResponseTooltipType

RootTypeIcon

Re-exports RootTypeIcon

SchemaContext

Re-exports SchemaContext

SchemaContextProvider

Re-exports SchemaContextProvider

SchemaContextType

Re-exports SchemaContextType

SettingsIcon

Re-exports SettingsIcon

Spinner

Re-exports Spinner

Spinner

Re-exports Spinner

StarFilledIcon

Re-exports StarFilledIcon

StarIcon

Re-exports StarIcon

StopIcon

Re-exports StopIcon

StorageContext

Re-exports StorageContext

StorageContextProvider

Re-exports StorageContextProvider

StorageContextType

Re-exports StorageContextType

Tab

Re-exports Tab

Tab

Re-exports Tab

Tabs

Re-exports Tabs

Tabs

Re-exports Tabs

TabsState

Re-exports TabsState

TabsState

Re-exports TabsState

Theme

Re-exports Theme

ToolbarButton

Re-exports ToolbarButton

ToolbarButton

Re-exports ToolbarButton

ToolbarMenu

Re-exports ToolbarMenu

ToolbarMenu

Re-exports ToolbarMenu

Tooltip

Re-exports Tooltip

Tooltip

Re-exports Tooltip

TooltipRoot

Re-exports TooltipRoot

TooltipRoot

Re-exports TooltipRoot

TrashIcon

Re-exports TrashIcon

TypeIcon

Re-exports TypeIcon

UnStyledButton

Re-exports UnStyledButton

UnStyledButton

Re-exports UnStyledButton

UseHeaderEditorArgs

Re-exports UseHeaderEditorArgs

UseHeaderEditorArgs

Re-exports UseHeaderEditorArgs

UseQueryEditorArgs

Re-exports UseQueryEditorArgs

UseQueryEditorArgs

Re-exports UseQueryEditorArgs

UseResponseEditorArgs

Re-exports UseResponseEditorArgs

UseResponseEditorArgs

Re-exports UseResponseEditorArgs

UseVariableEditorArgs

Re-exports UseVariableEditorArgs

UseVariableEditorArgs

Re-exports UseVariableEditorArgs

VariableEditor

Re-exports VariableEditor

VariableEditor

Re-exports VariableEditor

VariableEditor

Re-exports VariableEditor

WriteableEditorProps

Re-exports WriteableEditorProps

WriteableEditorProps

Re-exports WriteableEditorProps

cn

Re-exports cn

createContextHook

Re-exports createContextHook

createContextHook

Re-exports createContextHook

createNullableContext

Re-exports createNullableContext

createNullableContext

Re-exports createNullableContext

debounce

Re-exports debounce

debounce

Re-exports debounce

isMacOs

Re-exports isMacOs

isMacOs

Re-exports isMacOs

useAutoCompleteLeafs

Re-exports useAutoCompleteLeafs

useAutoCompleteLeafs

Re-exports useAutoCompleteLeafs

useCopyQuery

Re-exports useCopyQuery

useCopyQuery

Re-exports useCopyQuery

useDragResize

Re-exports useDragResize

useDragResize

Re-exports useDragResize

useEditorContext

Re-exports useEditorContext

useEditorContext

Re-exports useEditorContext

useEditorState

Re-exports useEditorState

useEditorState

Re-exports useEditorState

useExecutionContext

Re-exports useExecutionContext

useHeaderEditor

Re-exports useHeaderEditor

useHeaderEditor

Re-exports useHeaderEditor

useHeadersEditorState

Re-exports useHeadersEditorState

useHeadersEditorState

Re-exports useHeadersEditorState

useMergeQuery

Re-exports useMergeQuery

useMergeQuery

Re-exports useMergeQuery

useOperationsEditorState

Re-exports useOperationsEditorState

useOperationsEditorState

Re-exports useOperationsEditorState

useOptimisticState

Re-exports useOptimisticState

useOptimisticState

Re-exports useOptimisticState

usePluginContext

Re-exports usePluginContext

usePrettifyEditors

Re-exports usePrettifyEditors

usePrettifyEditors

Re-exports usePrettifyEditors

useQueryEditor

Re-exports useQueryEditor

useQueryEditor

Re-exports useQueryEditor

useResponseEditor

Re-exports useResponseEditor

useResponseEditor

Re-exports useResponseEditor

useSchemaContext

Re-exports useSchemaContext

useStorageContext

Re-exports useStorageContext

useTheme

Re-exports useTheme

useVariableEditor

Re-exports useVariableEditor

useVariableEditor

Re-exports useVariableEditor

useVariablesEditorState

Re-exports useVariablesEditorState

useVariablesEditorState

Re-exports useVariablesEditorState

Type aliases

CodeMirrorEditor

CodeMirrorEditor: Editor & { options?: any }

CodeMirrorEditorWithOperationFacts

CodeMirrorEditorWithOperationFacts: CodeMirrorEditor & { documentAST: DocumentNode | null; operationName: string | null; operations: OperationDefinitionNode[] | null; variableToType: VariableToType | null }

CodeMirrorType

CodeMirrorType: CodeMirror

CommonEditorProps

CommonEditorProps: { editorTheme?: undefined | string; keyMap?: KeyMap }

Type declaration

EditorContextType

EditorContextType: TabsState & { externalFragments: Map<string, FragmentDefinitionNode>; headerEditor: CodeMirrorEditor | null; initialHeaders: string; initialQuery: string; initialResponse: string; initialVariables: string; queryEditor: CodeMirrorEditorWithOperationFacts | null; responseEditor: CodeMirrorEditor | null; shouldPersistHeaders: boolean; validationRules: ValidationRule[]; variableEditor: CodeMirrorEditor | null; addTab: any; changeTab: any; closeTab: any; moveTab: any; setHeaderEditor: any; setOperationName: any; setQueryEditor: any; setResponseEditor: any; setShouldPersistHeaders: any; setVariableEditor: any; updateActiveTabValues: any }

ExecutionContextType

ExecutionContextType: { isFetching: boolean; isSubscribed: boolean; operationName: string | null; run: any; stop: any }

Type declaration

  • isFetching: boolean

    If there is currently a GraphQL request in-flight. For multipart requests like subscriptions, this will be true while fetching the first partial response and false while fetching subsequent batches.

  • isSubscribed: boolean

    If there is currently a GraphQL request in-flight. For multipart requests like subscriptions, this will be true until the last batch has been fetched or the connection is closed from the client.

  • operationName: string | null

    The operation name that will be sent with all GraphQL requests.

  • run: function
    • run(): void
  • stop: function
    • stop(): void

GraphiQLPlugin

GraphiQLPlugin: { content: ComponentType; icon: ComponentType; title: string }

Type declaration

  • content: ComponentType

    A component that renders content into the plugin pane.

  • icon: ComponentType

    A component that renders an icon that will be shown inside a button that toggles the plugin visibility.

  • title: string

    The unique title of the plugin. If two plugins are present with the same title the provider component will throw an error.

KeyMap

KeyMap: "sublime" | "emacs" | "vim"

PluginContextType

PluginContextType: { plugins: GraphiQLPlugin[]; referencePlugin?: GraphiQLPlugin; visiblePlugin: GraphiQLPlugin | null; setVisiblePlugin: any }

Type declaration

  • plugins: GraphiQLPlugin[]

    A list of all current plugins, including the built-in ones (the doc explorer and the history).

  • Optional referencePlugin?: GraphiQLPlugin

    The plugin which is used to display the reference documentation when selecting a type.

  • visiblePlugin: GraphiQLPlugin | null

    The plugin which is currently visible.

  • setVisiblePlugin: function
    • Defines the plugin which is currently visible.

      Parameters

      • plugin: GraphiQLPlugin | string | null

        The plugin that should become visible. You can either pass the plugin object (has to be referentially equal to the one passed as prop) or the plugin title as string. If null is passed, no plugin will be visible.

      Returns void

ResponseTooltipType

ResponseTooltipType: ComponentType<{ pos: Position; token: Token }>

SchemaContextType

SchemaContextType: { fetchError: string | null; isFetching: boolean; schema: MaybeGraphQLSchema; schemaReference: SchemaReference | null; setSchemaReference: Dispatch<SchemaReference>; validationErrors: readonly GraphQLError[]; introspect: any }

Type declaration

  • fetchError: string | null

    Stores an error raised during introspecting or building the GraphQL schema from the introspection result.

  • isFetching: boolean

    If there currently is an introspection request in-flight.

  • schema: MaybeGraphQLSchema

    The current GraphQL schema.

  • schemaReference: SchemaReference | null

    The last type selected by the user.

  • setSchemaReference: Dispatch<SchemaReference>

    Set the current selected type.

  • validationErrors: readonly GraphQLError[]

    A list of errors from validating the current GraphQL schema. The schema is valid if and only if this list is empty.

  • introspect: function
    • introspect(): void
    • Trigger building the GraphQL schema. This might trigger an introspection request if no schema is passed via props and if using a schema is not explicitly disabled by passing null as value for the schema prop. If there is a schema (either fetched using introspection or passed via props) it will be validated, unless this is explicitly skipped using the dangerouslyAssumeSchemaIsValid prop.

      Returns void

StorageContextType

StorageContextType: StorageAPI

TabDefinition

TabDefinition: { headers?: string | null; query: string | null; variables?: string | null }

Type declaration

  • Optional headers?: string | null

    The contents of the headers editor of this tab.

  • query: string | null

    The contents of the query editor of this tab.

  • Optional variables?: string | null

    The contents of the variable editor of this tab.

TabState

TabState: TabDefinition & { hash: string; id: string; operationName: string | null; response: string | null; title: string }

This object describes the state of a single tab.

TabsState

TabsState: { activeTabIndex: number; tabs: TabState[] }

This object describes the state of all tabs.

Type declaration

  • activeTabIndex: number

    The index of the currently active tab with regards to the tabs list of this object.

  • tabs: TabState[]

    A list of state objects for each tab.

Theme

Theme: "light" | "dark" | null

The value null semantically means that the user does not explicitly choose any theme, so we use the system default.

UseAutoCompleteLeafsArgs

UseAutoCompleteLeafsArgs: { caller?: Function; getDefaultFieldNames?: GetDefaultFieldNamesFn }

Type declaration

  • Optional caller?: Function

    This is only meant to be used internally in @graphiql/react.

  • Optional getDefaultFieldNames?: GetDefaultFieldNamesFn

    A function to determine which field leafs are automatically added when trying to execute a query with missing selection sets. It will be called with the GraphQLType for which fields need to be added.

UseCopyQueryArgs

UseCopyQueryArgs: { caller?: Function; onCopyQuery?: undefined | ((query: string) => void) }

Type declaration

  • Optional caller?: Function

    This is only meant to be used internally in @graphiql/react.

  • Optional onCopyQuery?: undefined | ((query: string) => void)

    Invoked when the current contents of the query editor are copied to the clipboard.

    param

    The content that has been copied.

UseHeaderEditorArgs

UseHeaderEditorArgs: WriteableEditorProps & { onEdit?: any }

UsePrettifyEditorsArgs

UsePrettifyEditorsArgs: { caller?: Function; onPrettifyQuery?: undefined | ((query: string) => MaybePromise<string>) }

Type declaration

  • Optional caller?: Function

    This is only meant to be used internally in @graphiql/react.

  • Optional onPrettifyQuery?: undefined | ((query: string) => MaybePromise<string>)

    Invoked when the prettify callback is invoked.

    param

    The current value of the query editor.

    default

    import { parse, print } from 'graphql'

    (query) => print(parse(query))

    returns

    The formatted query.

UseQueryEditorArgs

UseQueryEditorArgs: WriteableEditorProps & Pick<UseCopyQueryArgs, "onCopyQuery"> & Pick<UsePrettifyEditorsArgs, "onPrettifyQuery"> & { onClickReference?: any; onEdit?: any }

UseResponseEditorArgs

UseResponseEditorArgs: CommonEditorProps & { responseTooltip?: ResponseTooltipType }

UseVariableEditorArgs

UseVariableEditorArgs: WriteableEditorProps & { onClickReference?: any; onEdit?: any }

WriteableEditorProps

WriteableEditorProps: CommonEditorProps & { readOnly?: undefined | false | true }

Variables

Const ArgumentIcon

ArgumentIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_ArgumentIcon)

Const Button

Button: ForwardRefExoticComponent<Omit<ButtonProps & ClassAttributes<HTMLButtonElement> & ButtonHTMLAttributes<HTMLButtonElement>, "ref"> & RefAttributes<HTMLButtonElement>> = forwardRef<HTMLButtonElement,ButtonProps & JSX.IntrinsicElements['button']>((props, ref) => (<button{...props}ref={ref}className={clsx('graphiql-button',{success: 'graphiql-button-success',error: 'graphiql-button-error',}[props.state!],props.className,)}/>))

Const ButtonGroup

ButtonGroup: ForwardRefExoticComponent<Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & RefAttributes<HTMLDivElement>> = forwardRef<HTMLDivElement,JSX.IntrinsicElements['div']>((props, ref) => (<div{...props}ref={ref}className={clsx('graphiql-button-group', props.className)}/>))

Const ChevronDownIcon

ChevronDownIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_ChevronDownIcon)

Const ChevronLeftIcon

ChevronLeftIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_ChevronLeftIcon)

Const ChevronUpIcon

ChevronUpIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_ChevronUpIcon)

Const CloseIcon

CloseIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_CloseIcon)

Const CopyIcon

CopyIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_CopyIcon)

Const DEFAULT_EDITOR_THEME

DEFAULT_EDITOR_THEME: "graphiql" = "graphiql"

Const DEFAULT_KEY_MAP

DEFAULT_KEY_MAP: KeyMap = "sublime"

Const DEFAULT_QUERY

DEFAULT_QUERY: "# Welcome to GraphiQL## GraphiQL is an in-browser tool for writing, validating, and# testing GraphQL queries.## Type queries into this side of the screen, and you will see intelligent# typeaheads aware of the current GraphQL type schema and live syntax and# validation errors highlighted within the text.## GraphQL queries typically start with a "{" character. Lines that start# with a # are ignored.## An example GraphQL query might look like:## {# field(arg: "value") {# subField# }# }## Keyboard shortcuts:## Prettify query: Shift-Ctrl-P (or press the prettify button)## Merge fragments: Shift-Ctrl-M (or press the merge button)## Run Query: Ctrl-Enter (or press the play button)## Auto Complete: Ctrl-Space (or just start typing)#" = `# Welcome to GraphiQL## GraphiQL is an in-browser tool for writing, validating, and# testing GraphQL queries.## Type queries into this side of the screen, and you will see intelligent# typeaheads aware of the current GraphQL type schema and live syntax and# validation errors highlighted within the text.## GraphQL queries typically start with a "{" character. Lines that start# with a # are ignored.## An example GraphQL query might look like:## {# field(arg: "value") {# subField# }# }## Keyboard shortcuts:## Prettify query: Shift-Ctrl-P (or press the prettify button)## Merge fragments: Shift-Ctrl-M (or press the merge button)## Run Query: Ctrl-Enter (or press the play button)## Auto Complete: Ctrl-Space (or just start typing)#`

Const DeprecatedArgumentIcon

DeprecatedArgumentIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_DeprecatedArgumentIcon)

Const DeprecatedEnumValueIcon

DeprecatedEnumValueIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_DeprecatedEnumValueIcon)

Const DeprecatedFieldIcon

DeprecatedFieldIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_DeprecatedFieldIcon)

Const Dialog

Dialog: FC<DialogProps> & { Close: ForwardRefExoticComponent<Omit<DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & RefAttributes<HTMLButtonElement>>; Description: ForwardRefExoticComponent<DialogDescriptionProps & RefAttributes<HTMLParagraphElement>>; Title: ForwardRefExoticComponent<DialogTitleProps & RefAttributes<HTMLHeadingElement>>; Trigger: ForwardRefExoticComponent<DialogTriggerProps & RefAttributes<HTMLButtonElement>> } = Object.assign(DialogRoot, {Close: DialogClose,Title: D.Title,Trigger: D.Trigger,Description: D.Description,})

Const DirectiveIcon

DirectiveIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_DirectiveIcon)

Const DocsFilledIcon

DocsFilledIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_DocsFilledIcon)

Const DocsIcon

DocsIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_DocsIcon)

Const DropdownMenu

DropdownMenu: FC<DropdownMenuProps> & { Button: ForwardRefExoticComponent<Omit<DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & RefAttributes<HTMLButtonElement>>; Content: FC<DropdownMenuContentProps>; Item: FC<DropdownMenuItemProps> } = Object.assign(Root, {Button,Item,Content,})

Const EditorContext

EditorContext: Context<null | EditorContextType> = createNullableContext<EditorContextType>('EditorContext')

Const EnumValueIcon

EnumValueIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_EnumValueIcon)

Const ExecutionContext

ExecutionContext: Context<null | ExecutionContextType> = createNullableContext<ExecutionContextType>('ExecutionContext')

Const FieldIcon

FieldIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_FieldIcon)

Const HistoryIcon

HistoryIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_HistoryIcon)

Const ImagePreview

ImagePreview: FC<ImagePreviewProps> & { shouldRender: any } = Object.assign(ImagePreview_, {shouldRender(token: Token) {const url = tokenToURL(token);return url ? isImageURL(url) : false;},})

Const ImplementsIcon

ImplementsIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_ImplementsIcon)

Const KeyboardShortcutIcon

KeyboardShortcutIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_KeyboardShortcutIcon)

Const MagnifyingGlassIcon

MagnifyingGlassIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_MagnifyingGlassIcon)

Const MarkdownContent

MarkdownContent: ForwardRefExoticComponent<Omit<MarkdownContentProps & Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "children">, "ref"> & RefAttributes<HTMLDivElement>> = forwardRef<HTMLDivElement,MarkdownContentProps & Omit<JSX.IntrinsicElements['div'], 'children'>>(({ children, onlyShowFirstChild, type, ...props }, ref) => (<div{...props}ref={ref}className={clsx(`graphiql-markdown-${type}`,onlyShowFirstChild && 'graphiql-markdown-preview',props.className,)}dangerouslySetInnerHTML={{ __html: markdown.render(children) }}/>))

Const MergeIcon

MergeIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_MergeIcon)

Const PenIcon

PenIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_PenIcon)

Const PlayIcon

PlayIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_PlayIcon)

Const PluginContext

PluginContext: Context<null | PluginContextType> = createNullableContext<PluginContextType>('PluginContext')

Const PlusIcon

PlusIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_PlusIcon)

Const PrettifyIcon

PrettifyIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_PrettifyIcon)

Const ReloadIcon

ReloadIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_ReloadIcon)

Const RootTypeIcon

RootTypeIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_RootTypeIcon)

Const STORAGE_KEY

STORAGE_KEY: "headers" = "headers"

Const STORAGE_KEY

STORAGE_KEY: "tabState" = "tabState"

Const STORAGE_KEY

STORAGE_KEY: "variables" = "variables"

Const STORAGE_KEY_QUERY

STORAGE_KEY_QUERY: "query" = "query"

Const SchemaContext

SchemaContext: Context<null | SchemaContextType> = createNullableContext<SchemaContextType>('SchemaContext')

Const SettingsIcon

SettingsIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_SettingsIcon)

Const Spinner

Spinner: ForwardRefExoticComponent<Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & RefAttributes<HTMLDivElement>> = forwardRef<HTMLDivElement, JSX.IntrinsicElements['div']>((props, ref) => (<div{...props}ref={ref}className={clsx('graphiql-spinner', props.className)}/>),)

Const StarFilledIcon

StarFilledIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_StarFilledIcon)

Const StarIcon

StarIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_StarIcon)

Const StopIcon

StopIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_StopIcon)

Const StorageContext

StorageContext: Context<null | StorageAPI> = createNullableContext<StorageContextType>('StorageContext')

Const Tab

Tab: ForwardRefExoticComponent<TabProps & RefAttributes<HTMLLIElement>> & { Button: ForwardRefExoticComponent<Omit<DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & RefAttributes<HTMLButtonElement>>; Close: ForwardRefExoticComponent<Omit<DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & RefAttributes<HTMLButtonElement>> } = Object.assign(TabRoot, {Button: TabButton,Close: TabClose,})

Const Tabs

Tabs: ForwardRefExoticComponent<TabsProps & RefAttributes<HTMLUListElement>> = forwardRef<HTMLUListElement, TabsProps>(({ values, onReorder, children, className, ...props }, ref) => (<Reorder.Group{...props}ref={ref}values={values}onReorder={onReorder}axis="x"role="tablist"className={clsx('graphiql-tabs', className)}>{children}</Reorder.Group>),)

Const ToolbarButton

ToolbarButton: ForwardRefExoticComponent<Omit<ToolbarButtonProps & ClassAttributes<HTMLButtonElement> & ButtonHTMLAttributes<HTMLButtonElement>, "ref"> & RefAttributes<HTMLButtonElement>> = forwardRef<HTMLButtonElement,ToolbarButtonProps & JSX.IntrinsicElements['button']>(({ label, onClick, ...props }, ref) => {const [error, setError] = useState<Error | null>(null);const handleClick: MouseEventHandler<HTMLButtonElement> = event => {try {// Optional chaining inside try-catch isn't supported yet by react-compilerif (onClick) {onClick(event);}setError(null);} catch (err) {setError(err instanceof Error? err: new Error(`Toolbar button click failed: ${err}`),);}};return (<Tooltip label={label}><UnStyledButton{...props}ref={ref}type="button"className={clsx('graphiql-toolbar-button',error && 'error',props.className,)}onClick={handleClick}aria-label={error ? error.message : label}aria-invalid={error ? 'true' : props['aria-invalid']}/></Tooltip>);})

Const ToolbarMenu

ToolbarMenu: ToolbarMenuRoot & { Item: FC<DropdownMenuItemProps> } = Object.assign(ToolbarMenuRoot, {Item: DropdownMenu.Item,})

Const Tooltip

Tooltip: FC<TooltipContentProps & { label: ReactNode }> & { Provider: FC<TooltipProviderProps> } = Object.assign(TooltipRoot, {Provider: T.Provider,})

Const TrashIcon

TrashIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_TrashIcon)

Const TypeIcon

TypeIcon: FC<SVGProps<SVGSVGElement>> = generateIcon(_TypeIcon)

Const UnStyledButton

UnStyledButton: ForwardRefExoticComponent<Omit<DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & RefAttributes<HTMLButtonElement>> = forwardRef<HTMLButtonElement,JSX.IntrinsicElements['button']>((props, ref) => (<button{...props}ref={ref}className={clsx('graphiql-un-styled', props.className)}/>))

Const invalidCharacters

invalidCharacters: string[] = Array.from({ length: 11 }, (_, i) => {// \u2000 -> \u200areturn String.fromCharCode(0x2000 + i);}).concat(['\u2028', '\u2029', '\u202f', '\u00a0'])

Const isMacOs

isMacOs: boolean = typeof navigator !== 'undefined' && navigator.userAgent.includes('Mac')

Const markdown

markdown: MarkdownIt = new MarkdownIt({// we don't want to convert \n to <br> because in markdown a single newline is not a line break// https://github.com/graphql/graphiql/issues/3155breaks: false,linkify: true,})

Const useEditorContext

useEditorContext: useGivenContext = createContextHook(EditorContext)

Const useExecutionContext

useExecutionContext: useGivenContext = createContextHook(ExecutionContext)

Const usePluginContext

usePluginContext: useGivenContext = createContextHook(PluginContext)

Const useSchemaContext

useSchemaContext: useGivenContext = createContextHook(SchemaContext)

Const useStorageContext

useStorageContext: useGivenContext = createContextHook(StorageContext)

Functions

Const DialogRoot

  • DialogRoot(__namedParameters: { children: ReactNode; props: props }): Element

Const EditorContextProvider

  • EditorContextProvider(props: EditorContextProviderProps): Element

Const ExecuteButton

  • ExecuteButton(): Element

Const ExecutionContextProvider

  • ExecutionContextProvider(__namedParameters: { children: ReactNode; fetcher: Fetcher; getDefaultFieldNames: undefined | GetDefaultFieldNamesFn; operationName: undefined | string }): Element

Const GraphiQLProvider

  • GraphiQLProvider(__namedParameters: { children: ReactNode; dangerouslyAssumeSchemaIsValid: undefined | false | true; defaultHeaders: undefined | string; defaultQuery: undefined | string; defaultTabs: undefined | TabDefinition[]; externalFragments: undefined | string | FragmentDefinitionNode[]; fetcher: Fetcher; getDefaultFieldNames: undefined | GetDefaultFieldNamesFn; headers: undefined | string; inputValueDeprecation: undefined | false | true; introspectionQueryName: undefined | string; onEditOperationName: undefined | onEditOperationName; onSchemaChange: undefined | onSchemaChange; onTabChange: undefined | onTabChange; onTogglePluginVisibility: undefined | onTogglePluginVisibility; operationName: undefined | string; plugins: undefined | GraphiQLPlugin[]; query: undefined | string; referencePlugin: undefined | GraphiQLPlugin; response: undefined | string; schema: undefined | null | GraphQLSchema | IntrospectionQuery; schemaDescription: undefined | false | true; shouldPersistHeaders: undefined | false | true; storage: undefined | Storage; validationRules: undefined | ValidationRule[]; variables: undefined | string; visiblePlugin: undefined | string | GraphiQLPlugin }): Element
  • Parameters

    • __namedParameters: { children: ReactNode; dangerouslyAssumeSchemaIsValid: undefined | false | true; defaultHeaders: undefined | string; defaultQuery: undefined | string; defaultTabs: undefined | TabDefinition[]; externalFragments: undefined | string | FragmentDefinitionNode[]; fetcher: Fetcher; getDefaultFieldNames: undefined | GetDefaultFieldNamesFn; headers: undefined | string; inputValueDeprecation: undefined | false | true; introspectionQueryName: undefined | string; onEditOperationName: undefined | onEditOperationName; onSchemaChange: undefined | onSchemaChange; onTabChange: undefined | onTabChange; onTogglePluginVisibility: undefined | onTogglePluginVisibility; operationName: undefined | string; plugins: undefined | GraphiQLPlugin[]; query: undefined | string; referencePlugin: undefined | GraphiQLPlugin; response: undefined | string; schema: undefined | null | GraphQLSchema | IntrospectionQuery; schemaDescription: undefined | false | true; shouldPersistHeaders: undefined | false | true; storage: undefined | Storage; validationRules: undefined | ValidationRule[]; variables: undefined | string; visiblePlugin: undefined | string | GraphiQLPlugin }
      • children: ReactNode
      • dangerouslyAssumeSchemaIsValid: undefined | false | true
      • defaultHeaders: undefined | string
      • defaultQuery: undefined | string
      • defaultTabs: undefined | TabDefinition[]
      • externalFragments: undefined | string | FragmentDefinitionNode[]
      • fetcher: Fetcher
      • getDefaultFieldNames: undefined | GetDefaultFieldNamesFn
      • headers: undefined | string
      • inputValueDeprecation: undefined | false | true
      • introspectionQueryName: undefined | string
      • onEditOperationName: undefined | onEditOperationName
      • onSchemaChange: undefined | onSchemaChange
      • onTabChange: undefined | onTabChange
      • onTogglePluginVisibility: undefined | onTogglePluginVisibility
      • operationName: undefined | string
      • plugins: undefined | GraphiQLPlugin[]
      • query: undefined | string
      • referencePlugin: undefined | GraphiQLPlugin
      • response: undefined | string
      • schema: undefined | null | GraphQLSchema | IntrospectionQuery
      • schemaDescription: undefined | false | true
      • shouldPersistHeaders: undefined | false | true
      • storage: undefined | Storage
      • validationRules: undefined | ValidationRule[]
      • variables: undefined | string
      • visiblePlugin: undefined | string | GraphiQLPlugin

    Returns Element

Const HeaderEditor

  • HeaderEditor(__namedParameters: { hookArgs: hookArgs; isHidden: undefined | false | true }): Element

Const PluginContextProvider

  • PluginContextProvider(__namedParameters: { $plugins: undefined | GraphiQLPlugin[]; children: ReactNode; onTogglePluginVisibility: undefined | onTogglePluginVisibility; referencePlugin: undefined | GraphiQLPlugin; visiblePlugin: undefined | string | GraphiQLPlugin }): Element

Const QueryEditor

Const ResponseEditor

Const SchemaContextProvider

  • SchemaContextProvider(__namedParameters: { children: ReactNode; dangerouslyAssumeSchemaIsValid: undefined | false | true; fetcher: Fetcher; onSchemaChange: undefined | onSchemaChange; props: props }): Element
  • Parameters

    • __namedParameters: { children: ReactNode; dangerouslyAssumeSchemaIsValid: undefined | false | true; fetcher: Fetcher; onSchemaChange: undefined | onSchemaChange; props: props }
      • children: ReactNode
      • dangerouslyAssumeSchemaIsValid: undefined | false | true
      • fetcher: Fetcher
      • onSchemaChange: undefined | onSchemaChange
      • props: props

    Returns Element

Const StorageContextProvider

  • StorageContextProvider(__namedParameters: { children: ReactNode; storage: undefined | Storage }): Element

Const TooltipRoot

  • TooltipRoot(__namedParameters: { align: "center" | "start" | "end"; children: ReactNode; label: ReactNode; side: "top" | "right" | "bottom" | "left"; sideOffset: number }): Element
  • Parameters

    • __namedParameters: { align: "center" | "start" | "end"; children: ReactNode; label: ReactNode; side: "top" | "right" | "bottom" | "left"; sideOffset: number }
      • align: "center" | "start" | "end"
      • children: ReactNode
      • label: ReactNode
      • side: "top" | "right" | "bottom" | "left"
      • sideOffset: number

    Returns Element

Const VariableEditor

  • VariableEditor(__namedParameters: { hookArgs: hookArgs; isHidden: undefined | false | true }): Element

clearHeadersFromTabs

createContextHook

createNullableContext

  • createNullableContext<T>(name: string): Context<T | null>

createTab

  • createTab(__namedParameters?: { headers: null | string; query: null | string; variables: null | string }): TabState

debounce

  • debounce<F>(duration: number, fn: F): debounce

fuzzyExtractOperationName

  • fuzzyExtractOperationName(str: string): string | null

getDefaultTabState

  • getDefaultTabState(__namedParameters: { defaultHeaders: undefined | string; defaultQuery: string; defaultTabs: undefined | TabDefinition[]; headers: null | string; query: null | string; shouldPersistHeaders: undefined | false | true; storage: null | StorageAPI; variables: null | string }): getDefaultTabState
  • Parameters

    • __namedParameters: { defaultHeaders: undefined | string; defaultQuery: string; defaultTabs: undefined | TabDefinition[]; headers: null | string; query: null | string; shouldPersistHeaders: undefined | false | true; storage: null | StorageAPI; variables: null | string }
      • defaultHeaders: undefined | string
      • defaultQuery: string
      • defaultTabs: undefined | TabDefinition[]
      • headers: null | string
      • query: null | string
      • shouldPersistHeaders: undefined | false | true
      • storage: null | StorageAPI
      • variables: null | string

    Returns getDefaultTabState

importCodeMirror

  • importCodeMirror(addons: Promise<any>[], options?: undefined | { useCommonAddons?: undefined | false | true }): importCodeMirror

normalizeWhitespace

onHasCompletion

  • onHasCompletion(_cm: Editor, data: EditorChange | undefined, __namedParameters: { schema: MaybeGraphQLSchema; setSchemaReference: Dispatch<SchemaReference> }, plugin: PluginContextType | null, callback?: undefined | ((type: GraphQLNamedType) => void)): void
  • Render a custom UI for CodeMirror's hint which includes additional info about the type and description for the selected context.

    Parameters

    • _cm: Editor
    • data: EditorChange | undefined
    • __namedParameters: { schema: MaybeGraphQLSchema; setSchemaReference: Dispatch<SchemaReference> }
    • plugin: PluginContextType | null
    • Optional callback: undefined | ((type: GraphQLNamedType) => void)

    Returns void

serializeTabState

setPropertiesInActiveTab

useAutoCompleteLeafs

useChangeHandler

  • useChangeHandler(editor: CodeMirrorEditor | null, callback: ((value: string) => void) | undefined, storageKey: string | null, tabProperty: "variables" | "headers", caller: Function): useChangeHandler

useCompletion

useCopyQuery

  • useCopyQuery(__namedParameters?: { caller: undefined | Function; onCopyQuery: undefined | ((query: string) => void) }): useCopyQuery
  • Parameters

    • Default value __namedParameters: { caller: undefined | Function; onCopyQuery: undefined | ((query: string) => void) } = {}
      • caller: undefined | Function
      • onCopyQuery: undefined | ((query: string) => void)

    Returns useCopyQuery

useDragResize

  • useDragResize(__namedParameters: { defaultSizeRelation: number; direction: "horizontal" | "vertical"; initiallyHidden: undefined | "first" | "second"; onHiddenElementChange: undefined | onHiddenElementChange; sizeThresholdFirst: number; sizeThresholdSecond: number; storageKey: undefined | string }): useDragResize
  • Parameters

    • __namedParameters: { defaultSizeRelation: number; direction: "horizontal" | "vertical"; initiallyHidden: undefined | "first" | "second"; onHiddenElementChange: undefined | onHiddenElementChange; sizeThresholdFirst: number; sizeThresholdSecond: number; storageKey: undefined | string }
      • defaultSizeRelation: number
      • direction: "horizontal" | "vertical"
      • initiallyHidden: undefined | "first" | "second"
      • onHiddenElementChange: undefined | onHiddenElementChange
      • sizeThresholdFirst: number
      • sizeThresholdSecond: number
      • storageKey: undefined | string

    Returns useDragResize

Const useEditorState

  • useEditorState(editor: "query" | "variable" | "header"): [string, (val: string) => void]

useHeaderEditor

Const useHeadersEditorState

  • useHeadersEditorState(): [headers: string, setHeaders: (content: string) => void]

useKeyMap

useMergeQuery

  • useMergeQuery(__namedParameters?: { caller: undefined | Function }): useMergeQuery

Const useOperationsEditorState

  • useOperationsEditorState(): [operations: string, setOperations: (content: string) => void]

useOptimisticState

  • useOptimisticState(__namedParameters: [string, (val: string) => void]): ReturnType<typeof useEditorState>
  • Implements an optimistic caching strategy around a useState-like hook in order to prevent loss of updates when the hook has an internal delay and the update function is called again before the updated state is sent out.

    Use this as a wrapper around useOperationsEditorState, useVariablesEditorState, or useHeadersEditorState if you anticipate calling them with great frequency (due to, for instance, mouse, keyboard, or network events).

    example
    const [operationsString, handleEditOperations] =
      useOptimisticState(useOperationsEditorState());

    Parameters

    • __namedParameters: [string, (val: string) => void]

    Returns ReturnType<typeof useEditorState>

usePrettifyEditors

  • usePrettifyEditors(__namedParameters?: { caller: undefined | Function; onPrettifyQuery: (query: string) => MaybePromise<string> }): usePrettifyEditors

useQueryEditor

  • useQueryEditor(__namedParameters?: { editorTheme: string; keyMap: KeyMap; onClickReference: undefined | onClickReference; onCopyQuery: undefined | ((query: string) => void); onEdit: undefined | onEdit; onPrettifyQuery: undefined | ((query: string) => MaybePromise<string>); readOnly: boolean }, caller?: Function): useQueryEditor

useResponseEditor

  • useResponseEditor(__namedParameters?: { editorTheme: string; keyMap: KeyMap; responseTooltip: undefined | ComponentClass<{ pos: Position; token: Token }, any> | FunctionComponent<{ pos: Position; token: Token }> }, caller?: Function): useResponseEditor
  • Parameters

    • Default value __namedParameters: { editorTheme: string; keyMap: KeyMap; responseTooltip: undefined | ComponentClass<{ pos: Position; token: Token }, any> | FunctionComponent<{ pos: Position; token: Token }> } = {}
      • editorTheme: string
      • keyMap: KeyMap
      • responseTooltip: undefined | ComponentClass<{ pos: Position; token: Token }, any> | FunctionComponent<{ pos: Position; token: Token }>
    • Optional caller: Function

    Returns useResponseEditor

useSetEditorValues

useStoreTabs

  • useStoreTabs(__namedParameters: { shouldPersistHeaders: undefined | false | true; storage: null | StorageAPI }): useStoreTabs

useSynchronizeActiveTabValues

useSynchronizeOption

useSynchronizeValue

useTheme

useVariableEditor

Const useVariablesEditorState

  • useVariablesEditorState(): [variables: string, setVariables: (content: string) => void]

Object literals

Const commonKeys

commonKeys: object

Alt-Left

Alt-Left: string = "goGroupLeft"

Alt-Right

Alt-Right: string = "goGroupRight"

Cmd-G

Cmd-G: string = "findPersistent"

Ctrl-G

Ctrl-G: string = "findPersistent"

Ctrl-Left

Ctrl-Left: string = "goSubwordLeft"

Ctrl-Right

Ctrl-Right: string = "goSubwordRight"

[isMacOs ? 'Cmd-F' : 'Ctrl-F']

[isMacOs ? 'Cmd-F' : 'Ctrl-F']: string = "findPersistent"

Generated using TypeDoc