('ExecutionContext');
-export type ExecutionContextProviderProps = {
+export type ExecutionContextProviderProps = Pick<
+ UseAutoCompleteLeafsArgs,
+ 'getDefaultFieldNames'
+> & {
children: ReactNode;
/**
* A function which accepts GraphQL HTTP parameters and returns a `Promise`,
@@ -40,12 +57,6 @@ export type ExecutionContextProviderProps = {
* @see {@link https://graphiql-test.netlify.app/typedoc/modules/graphiql_toolkit.html#creategraphiqlfetcher-2|`createGraphiQLFetcher`}
*/
fetcher: Fetcher;
- /**
- * 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.
- */
- getDefaultFieldNames?: GetDefaultFieldNamesFn;
/**
* This prop sets the operation name that is passed with a GraphQL request.
*/
diff --git a/packages/graphiql-react/src/explorer/components/argument.tsx b/packages/graphiql-react/src/explorer/components/argument.tsx
index 10824e991cc..f38d127501a 100644
--- a/packages/graphiql-react/src/explorer/components/argument.tsx
+++ b/packages/graphiql-react/src/explorer/components/argument.tsx
@@ -7,8 +7,21 @@ import './argument.css';
import { MarkdownContent } from '../../ui';
type ArgumentProps = {
+ /**
+ * The argument that should be rendered.
+ */
arg: GraphQLArgument;
+ /**
+ * Toggle if the default value for the argument is shown (if there is one)
+ * @default false
+ */
showDefaultValue?: boolean;
+ /**
+ * Toggle whether to render the whole argument including description and
+ * deprecation reason (`false`) or to just render the argument name, type,
+ * and default value in a single line (`true`).
+ * @default false
+ */
inline?: boolean;
};
diff --git a/packages/graphiql-react/src/explorer/components/default-value.tsx b/packages/graphiql-react/src/explorer/components/default-value.tsx
index 44ee3ff8cb7..4e3cb0e83be 100644
--- a/packages/graphiql-react/src/explorer/components/default-value.tsx
+++ b/packages/graphiql-react/src/explorer/components/default-value.tsx
@@ -12,6 +12,9 @@ const printDefault = (ast?: ValueNode | null): string => {
};
type DefaultValueProps = {
+ /**
+ * The field or argument for which to render the default value.
+ */
field: ExplorerFieldDef;
};
diff --git a/packages/graphiql-react/src/explorer/components/deprecation-reason.tsx b/packages/graphiql-react/src/explorer/components/deprecation-reason.tsx
index 3ad2f5f99ef..84a9170638c 100644
--- a/packages/graphiql-react/src/explorer/components/deprecation-reason.tsx
+++ b/packages/graphiql-react/src/explorer/components/deprecation-reason.tsx
@@ -2,7 +2,12 @@ import { MarkdownContent } from '../../ui';
import './deprecation-reason.css';
-type DeprecationReasonProps = { children?: string | null };
+type DeprecationReasonProps = {
+ /**
+ * The deprecation reason as markdown string.
+ */
+ children?: string | null;
+};
export function DeprecationReason(props: DeprecationReasonProps) {
return props.children ? (
diff --git a/packages/graphiql-react/src/explorer/components/directive.tsx b/packages/graphiql-react/src/explorer/components/directive.tsx
index 1ff48a3d3f4..087d83c585a 100644
--- a/packages/graphiql-react/src/explorer/components/directive.tsx
+++ b/packages/graphiql-react/src/explorer/components/directive.tsx
@@ -3,6 +3,9 @@ import { DirectiveNode } from 'graphql';
import './directive.css';
type DirectiveProps = {
+ /**
+ * The directive that should be rendered.
+ */
directive: DirectiveNode;
};
diff --git a/packages/graphiql-react/src/explorer/components/doc-explorer.tsx b/packages/graphiql-react/src/explorer/components/doc-explorer.tsx
index a582d89b7cc..6c7227c449c 100644
--- a/packages/graphiql-react/src/explorer/components/doc-explorer.tsx
+++ b/packages/graphiql-react/src/explorer/components/doc-explorer.tsx
@@ -76,9 +76,7 @@ export function DocExplorer() {
{prevName}
)}
-
- {navItem.title || navItem.name}
-
+ {navItem.name}
diff --git a/packages/graphiql-react/src/explorer/components/field-documentation.tsx b/packages/graphiql-react/src/explorer/components/field-documentation.tsx
index a3ddfcfd386..655e37b9d64 100644
--- a/packages/graphiql-react/src/explorer/components/field-documentation.tsx
+++ b/packages/graphiql-react/src/explorer/components/field-documentation.tsx
@@ -9,7 +9,12 @@ import { Directive } from './directive';
import { ExplorerSection } from './section';
import { TypeLink } from './type-link';
-type FieldDocumentationProps = { field: ExplorerFieldDef };
+type FieldDocumentationProps = {
+ /**
+ * The field or argument that should be rendered.
+ */
+ field: ExplorerFieldDef;
+};
export function FieldDocumentation(props: FieldDocumentationProps) {
return (
diff --git a/packages/graphiql-react/src/explorer/components/field-link.tsx b/packages/graphiql-react/src/explorer/components/field-link.tsx
index 6a3d5753b19..09245b90cc0 100644
--- a/packages/graphiql-react/src/explorer/components/field-link.tsx
+++ b/packages/graphiql-react/src/explorer/components/field-link.tsx
@@ -3,6 +3,9 @@ import { ExplorerFieldDef, useExplorerContext } from '../context';
import './field-link.css';
type FieldLinkProps = {
+ /**
+ * The field or argument that should be linked to.
+ */
field: ExplorerFieldDef;
};
diff --git a/packages/graphiql-react/src/explorer/components/schema-documentation.tsx b/packages/graphiql-react/src/explorer/components/schema-documentation.tsx
index 2c5ea55bd5c..481dc87cf67 100644
--- a/packages/graphiql-react/src/explorer/components/schema-documentation.tsx
+++ b/packages/graphiql-react/src/explorer/components/schema-documentation.tsx
@@ -6,7 +6,12 @@ import { TypeLink } from './type-link';
import './schema-documentation.css';
-type SchemaDocumentationProps = { schema: GraphQLSchema };
+type SchemaDocumentationProps = {
+ /**
+ * The schema that should be rendered.
+ */
+ schema: GraphQLSchema;
+};
export function SchemaDocumentation(props: SchemaDocumentationProps) {
const queryType = props.schema.getQueryType();
diff --git a/packages/graphiql-react/src/explorer/components/section.tsx b/packages/graphiql-react/src/explorer/components/section.tsx
index 9d98fa19c2e..4071889a2a1 100644
--- a/packages/graphiql-react/src/explorer/components/section.tsx
+++ b/packages/graphiql-react/src/explorer/components/section.tsx
@@ -17,6 +17,10 @@ import './section.css';
type ExplorerSectionProps = {
children: ReactNode;
+ /**
+ * The title of the section, which will also determine the icon rendered next
+ * to the headline.
+ */
title:
| 'Root Types'
| 'Fields'
diff --git a/packages/graphiql-react/src/explorer/components/type-documentation.tsx b/packages/graphiql-react/src/explorer/components/type-documentation.tsx
index 03aff28649f..205ab71a3b5 100644
--- a/packages/graphiql-react/src/explorer/components/type-documentation.tsx
+++ b/packages/graphiql-react/src/explorer/components/type-documentation.tsx
@@ -22,7 +22,12 @@ import { TypeLink } from './type-link';
import './type-documentation.css';
-type TypeDocumentationProps = { type: GraphQLNamedType };
+type TypeDocumentationProps = {
+ /**
+ * The type that should be rendered.
+ */
+ type: GraphQLNamedType;
+};
export function TypeDocumentation(props: TypeDocumentationProps) {
return isNamedType(props.type) ? (
diff --git a/packages/graphiql-react/src/explorer/components/type-link.tsx b/packages/graphiql-react/src/explorer/components/type-link.tsx
index 78c75d2c4cf..a472fa7dbdc 100644
--- a/packages/graphiql-react/src/explorer/components/type-link.tsx
+++ b/packages/graphiql-react/src/explorer/components/type-link.tsx
@@ -6,6 +6,9 @@ import { renderType } from './utils';
import './type-link.css';
type TypeLinkProps = {
+ /**
+ * The type that should be linked to.
+ */
type: GraphQLType;
};
diff --git a/packages/graphiql-react/src/explorer/context.tsx b/packages/graphiql-react/src/explorer/context.tsx
index ba6f43723d9..e380594b70e 100644
--- a/packages/graphiql-react/src/explorer/context.tsx
+++ b/packages/graphiql-react/src/explorer/context.tsx
@@ -23,8 +23,14 @@ export type ExplorerFieldDef =
| GraphQLArgument;
export type ExplorerNavStackItem = {
+ /**
+ * The name of the item.
+ */
name: string;
- title?: string;
+ /**
+ * The definition object of the item, this can be a named type, a field, an
+ * input field or an argument.
+ */
def?: GraphQLNamedType | ExplorerFieldDef;
};
@@ -34,18 +40,39 @@ export type ExplorerNavStack = [
...ExplorerNavStackItem[],
];
-const initialNavStackItem: ExplorerNavStackItem = {
- name: 'Schema',
- title: 'Docs',
-};
+const initialNavStackItem: ExplorerNavStackItem = { name: 'Docs' };
export type ExplorerContextType = {
+ /**
+ * A stack of navigation items. The last item in the list is the current one.
+ * This list always contains at least one item.
+ */
explorerNavStack: ExplorerNavStack;
+ /**
+ * Hide the doc explorer.
+ */
hide(): void;
+ /**
+ * If the doc explorer should be shown.
+ */
isVisible: boolean;
+ /**
+ * Push an item to the navigation stack.
+ * @param item The item that should be pushed to the stack.
+ */
push(item: ExplorerNavStackItem): void;
+ /**
+ * Pop the last item from the navigation stack.
+ */
pop(): void;
+ /**
+ * Reset the navigation stack to its initial state, this will remove all but
+ * the initial stack item.
+ */
reset(): void;
+ /**
+ * Show the doc explorer.
+ */
show(): void;
};
diff --git a/packages/graphiql-react/src/history/context.tsx b/packages/graphiql-react/src/history/context.tsx
index 97cd4785d30..15200407fc6 100644
--- a/packages/graphiql-react/src/history/context.tsx
+++ b/packages/graphiql-react/src/history/context.tsx
@@ -5,12 +5,24 @@ import { useStorageContext } from '../storage';
import { createContextHook, createNullableContext } from '../utility/context';
export type HistoryContextType = {
+ /**
+ * Add an operation to the history.
+ * @param operation The operation that was executed, consisting of the query,
+ * variables, headers and the operation name.
+ */
addToHistory(operation: {
query?: string;
variables?: string;
headers?: string;
operationName?: string;
}): void;
+ /**
+ * Change the custom label of an item from the history.
+ * @param args An object containing the label (`undefined` if it should be
+ * unset) and properties that identify the history item that the label should
+ * be applied to. (This can result in the label being applied to multiple
+ * history items.)
+ */
editLabel(args: {
query?: string;
variables?: string;
@@ -19,11 +31,33 @@ export type HistoryContextType = {
label?: string;
favorite?: boolean;
}): void;
+ /**
+ * Hide the history.
+ */
hide(): void;
+ /**
+ * If the history should be shown.
+ */
isVisible: boolean;
+ /**
+ * The list of history items.
+ */
items: readonly QueryStoreItem[];
+ /**
+ * Show the history.
+ */
show(): void;
+ /**
+ * Toggle the visibility state of the history.
+ */
toggle(): void;
+ /**
+ * Toggle the favorite state of an item from the history.
+ * @param args An object containing the favorite state (`undefined` if it
+ * should be unset) and properties that identify the history item that the
+ * label should be applied to. (This can result in the label being applied
+ * to multiple history items.)
+ */
toggleFavorite(args: {
query?: string;
variables?: string;
diff --git a/packages/graphiql-react/src/index.ts b/packages/graphiql-react/src/index.ts
index 80872755eda..bb8fe798df5 100644
--- a/packages/graphiql-react/src/index.ts
+++ b/packages/graphiql-react/src/index.ts
@@ -5,7 +5,6 @@ export {
EditorContextProvider,
HeaderEditor,
ImagePreview,
- onHasCompletion,
QueryEditor,
ResponseEditor,
useAutoCompleteLeafs,
diff --git a/packages/graphiql-react/src/schema.tsx b/packages/graphiql-react/src/schema.tsx
index c082b932b1a..154d780c70b 100644
--- a/packages/graphiql-react/src/schema.tsx
+++ b/packages/graphiql-react/src/schema.tsx
@@ -30,10 +30,32 @@ import { createContextHook, createNullableContext } from './utility/context';
type MaybeGraphQLSchema = GraphQLSchema | null | undefined;
export type SchemaContextType = {
+ /**
+ * Stores an error raised during introspecting or building the GraphQL schema
+ * from the introspection result.
+ */
fetchError: string | null;
+ /**
+ * 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.
+ */
introspect(): void;
+ /**
+ * If there currently is an introspection request in-flight.
+ */
isFetching: boolean;
+ /**
+ * The current GraphQL schema.
+ */
schema: MaybeGraphQLSchema;
+ /**
+ * A list of errors from validating the current GraphQL schema. The schema is
+ * valid if and only if this list is empty.
+ */
validationErrors: readonly GraphQLError[];
};
diff --git a/packages/graphiql-react/src/utility/resize.tsx b/packages/graphiql-react/src/utility/resize.tsx
index ca3d6f4ade8..83c17986bf0 100644
--- a/packages/graphiql-react/src/utility/resize.tsx
+++ b/packages/graphiql-react/src/utility/resize.tsx
@@ -13,12 +13,39 @@ import debounce from './debounce';
type ResizableElement = 'first' | 'second';
type UseDragResizeArgs = {
+ /**
+ * Set the default sizes for the two resizable halves by passing their ratio
+ * (first divided by second).
+ */
defaultSizeRelation?: number;
+ /**
+ * The direction in which the two halves should be resizable.
+ */
direction: 'horizontal' | 'vertical';
+ /**
+ * Choose one of the two halves that should initially be hidden.
+ */
initiallyHidden?: ResizableElement;
+ /**
+ * Invoked when the visibility of one of the halves changes.
+ * @param hiddenElement The element that is now hidden after the change
+ * (`null` if both are visible).
+ */
onHiddenElementChange?(hiddenElement: ResizableElement | null): void;
+ /**
+ * The minimum width in pixels for the first half. If it is resized to a
+ * width smaller than this threshold, the half will be hidden.
+ */
sizeThresholdFirst?: number;
+ /**
+ * The minimum width in pixels for the second half. If it is resized to a
+ * width smaller than this threshold, the half will be hidden.
+ */
sizeThresholdSecond?: number;
+ /**
+ * A key for which the state of resizing is persisted in storage (if storage
+ * is available).
+ */
storageKey?: string;
};
@@ -33,12 +60,13 @@ export function useDragResize({
}: UseDragResizeArgs) {
const storage = useStorageContext();
- const store = useCallback(
- debounce(500, (value: string) => {
- if (storage && storageKey) {
- storage.set(storageKey, value);
- }
- }),
+ const store = useMemo(
+ () =>
+ debounce(500, (value: string) => {
+ if (storage && storageKey) {
+ storage.set(storageKey, value);
+ }
+ }),
[storage, storageKey],
);
diff --git a/packages/graphiql/__mocks__/@graphiql/react.tsx b/packages/graphiql/__mocks__/@graphiql/react.tsx
index 5e06351c4f0..1dc8242fd0d 100644
--- a/packages/graphiql/__mocks__/@graphiql/react.tsx
+++ b/packages/graphiql/__mocks__/@graphiql/react.tsx
@@ -56,7 +56,6 @@ export {
MarkdownContent,
Menu,
MergeIcon,
- onHasCompletion,
PenIcon,
PlayIcon,
PlusIcon,
diff --git a/packages/graphiql/src/components/GraphiQL.tsx b/packages/graphiql/src/components/GraphiQL.tsx
index 5afef4f20f8..a9bc62ce74c 100644
--- a/packages/graphiql/src/components/GraphiQL.tsx
+++ b/packages/graphiql/src/components/GraphiQL.tsx
@@ -73,6 +73,11 @@ if (majorVersion < 16) {
}
export type GraphiQLToolbarConfig = {
+ /**
+ * This content will be rendered after the built-in buttons of the toolbar.
+ * Note that this will not apply if you provide a completely custom toolbar
+ * (by passing `GraphiQL.Toolbar` as child to the `GraphiQL` component).
+ */
additionalContent?: React.ReactNode;
};
@@ -188,7 +193,8 @@ export type GraphiQLInterfaceProps = WriteableEditorProps &
*/
isHeadersEditorEnabled?: boolean;
/**
- * Custom toolbar configuration
+ * An object that allows configuration of the toolbar next to the query
+ * editor.
*/
toolbar?: GraphiQLToolbarConfig;
};