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

rename the initialTabs prop to defaultTabs #2908

Merged
merged 3 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/loud-beans-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'graphiql': minor
'@graphiql/react': minor
---

Deprecate the `initialTabs` prop and add a `defaultTabs` props that supersedes
it
2 changes: 1 addition & 1 deletion packages/graphiql-react/src/editor/__tests__/tabs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('getDefaultTabState', () => {
getDefaultTabState({
defaultQuery: '# Default',
headers: null,
initialTabs: [
defaultTabs: [
{
headers: null,
query: 'query Person { person { name } }',
Expand Down
15 changes: 10 additions & 5 deletions packages/graphiql-react/src/editor/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,25 @@ export type EditorContextProviderProps = {
*/
headers?: string;
/**
* This prop can be used to defined the initial set of tabs with their queries,
* variables and headers.
* @deprecated Use `defaultTabs` instead.
*/
initialTabs?: TabDefinition[];
/**
* This prop can be used to define the default set of tabs, with their
* queries, variables, and headers. It will be used as default only if
* there is no tab state persisted in storage.
*
* @example
* ```tsx
* <GraphiQL
* initialTabs={[
* defaultTabs={[
* { query: 'query myExampleQuery {}' },
* { query: '{ id }' }
* ]}
* />
*```
*/
initialTabs?: TabDefinition[];
defaultTabs?: TabDefinition[];
/**
* Invoked when the operation name changes. Possible triggers are:
* - Editing the contents of the query editor
Expand Down Expand Up @@ -278,7 +283,7 @@ export function EditorContextProvider(props: EditorContextProviderProps) {
query,
variables,
headers,
initialTabs: props.initialTabs,
defaultTabs: props.defaultTabs || props.initialTabs,
defaultQuery: props.defaultQuery || DEFAULT_QUERY,
defaultHeaders: props.defaultHeaders,
storage,
Expand Down
6 changes: 3 additions & 3 deletions packages/graphiql-react/src/editor/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ export function getDefaultTabState({
defaultQuery,
defaultHeaders,
headers,
initialTabs,
defaultTabs,
query,
variables,
storage,
}: {
defaultQuery: string;
defaultHeaders?: string;
headers: string | null;
initialTabs?: TabDefinition[];
defaultTabs?: TabDefinition[];
query: string | null;
variables: string | null;
storage: StorageAPI | null;
Expand Down Expand Up @@ -128,7 +128,7 @@ export function getDefaultTabState({
return {
activeTabIndex: 0,
tabs: (
initialTabs || [
defaultTabs || [
{
query: query ?? defaultQuery,
variables,
Expand Down
2 changes: 2 additions & 0 deletions packages/graphiql-react/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function GraphiQLProvider({
dangerouslyAssumeSchemaIsValid,
defaultQuery,
defaultHeaders,
defaultTabs,
externalFragments,
fetcher,
getDefaultFieldNames,
Expand Down Expand Up @@ -55,6 +56,7 @@ export function GraphiQLProvider({
<EditorContextProvider
defaultQuery={defaultQuery}
defaultHeaders={defaultHeaders}
defaultTabs={defaultTabs}
externalFragments={externalFragments}
headers={headers}
initialTabs={initialTabs}
Expand Down
2 changes: 2 additions & 0 deletions packages/graphiql/src/components/GraphiQL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export type GraphiQLProps = Omit<GraphiQLProviderProps, 'children'> &
export function GraphiQL({
dangerouslyAssumeSchemaIsValid,
defaultQuery,
defaultTabs,
externalFragments,
fetcher,
getDefaultFieldNames,
Expand Down Expand Up @@ -133,6 +134,7 @@ export function GraphiQL({
dangerouslyAssumeSchemaIsValid={dangerouslyAssumeSchemaIsValid}
defaultQuery={defaultQuery}
defaultHeaders={defaultHeaders}
defaultTabs={defaultTabs}
externalFragments={externalFragments}
fetcher={fetcher}
headers={headers}
Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,11 @@ describe('GraphiQL', () => {
});
});

it('shows initial tabs', async () => {
it('shows default tabs', async () => {
const { container } = render(
<GraphiQL
fetcher={noOpFetcher}
initialTabs={[
defaultTabs={[
{
query: 'query Person { person { name } }',
},
Expand Down