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

[redesign] docs #2588

Merged
merged 8 commits into from
Jul 27, 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
4 changes: 2 additions & 2 deletions .changeset/five-pillows-fail.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
---

Add new components:
- UI components (`Dropdown`, `Spinner`, `UnStyledButton` and lots of icon components)
- UI components (`Button`, `Dropdown`, `Spinner`, `UnStyledButton` and lots of icon components)
- Editor components (`QueryEditor`, `VariableEditor`, `HeaderEditor` and `ResponseEditor`)
- Toolbar components (`ExecuteButton` and `ToolbarButton`)
- Docs components (`Argument`, `DefaultValue`, `Directive`, `DocExplorer`, `FieldDocumentation`, `FieldLink`, `SchemaDocumentation`, `Search`, `TypeDocumentation` and `TypeLink`)
- Docs components (`Argument`, `DefaultValue`, `DeprecationReason`, `Directive`, `DocExplorer`, `ExplorerSection`, `FieldDocumentation`, `FieldLink`, `SchemaDocumentation`, `Search`, `TypeDocumentation` and `TypeLink`)
- `History` component
1 change: 1 addition & 0 deletions .changeset/red-zoos-divide.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

BREAKING: The following exports of the `graphiql` package have been removed:
- `DocExplorer`: Now exported from `@graphiql/react` as `DocExplorer`
- The `schema` prop has been removed, the component now uses the schema provided by the `ExplorerContext`
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import { render } from '@testing-library/react';
import { GraphQLSchema } from 'graphql';

import { SchemaContext, SchemaContextType } from '../../../schema';
import { ExplorerContextProvider } from '../../context';
import { DocExplorer } from '../doc-explorer';
import { ExampleSchema } from './example-schema';

const defaultSchemaContext: SchemaContextType = {
fetchError: null,
isFetching: false,
schema: ExampleSchema,
schema: new GraphQLSchema({ description: 'GraphQL Schema for testing' }),
setFetchError() {},
setSchema() {},
validationErrors: null,
};

function DocExplorerWithContext(
props: React.ComponentProps<typeof DocExplorer>,
) {
function DocExplorerWithContext() {
return (
<ExplorerContextProvider>
<DocExplorer {...props} />
<DocExplorer />
</ExplorerContextProvider>
);
}
Expand All @@ -45,17 +43,17 @@ describe('DocExplorer', () => {
<DocExplorerWithContext />
</SchemaContext.Provider>,
);
const error = container.querySelectorAll('.error-container');
const error = container.querySelectorAll('.graphiql-doc-explorer-error');
expect(error).toHaveLength(1);
expect(error[0]).toHaveTextContent('No Schema Available');
expect(error[0]).toHaveTextContent('No GraphQL schema available');
});
it('renders with schema', () => {
const { container } = render(
<SchemaContext.Provider value={defaultSchemaContext}>
<DocExplorerWithContext />,
</SchemaContext.Provider>,
);
const error = container.querySelectorAll('.error-container');
const error = container.querySelectorAll('.graphiql-doc-explorer-error');
expect(error).toHaveLength(0);
expect(
container.querySelector('.graphiql-markdown-description'),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
render,
} from '@testing-library/react';
import { GraphQLString, GraphQLObjectType, Kind } from 'graphql';
import { ExplorerContext, ExplorerFieldDef } from '../../context';

import { ExplorerContext, ExplorerFieldDef } from '../../context';
import { FieldDocumentation } from '../field-documentation';
import { mockExplorerContextValue } from './test-utils';

Expand Down Expand Up @@ -64,12 +64,12 @@ function FieldDocumentationWithContext(props: { field: ExplorerFieldDef }) {
name: props.field.name,
def: props.field,
})}>
<FieldDocumentation />
<FieldDocumentation field={props.field} />
</ExplorerContext.Provider>
);
}

describe('FieldDoc', () => {
describe('FieldDocumentation', () => {
it('should render a simple string field', () => {
const { container } = render(
<FieldDocumentationWithContext
Expand All @@ -78,7 +78,7 @@ describe('FieldDoc', () => {
);
expect(
container.querySelector('.graphiql-markdown-description'),
).toHaveTextContent('No Description');
).not.toBeInTheDocument();
expect(
container.querySelector('.graphiql-doc-explorer-type-name'),
).toHaveTextContent('String');
Expand All @@ -95,7 +95,7 @@ describe('FieldDoc', () => {
);
expect(
container.querySelector('.graphiql-markdown-description'),
).toHaveTextContent('No Description');
).not.toBeInTheDocument();
expect(
container.querySelector('.graphiql-doc-explorer-type-name'),
).toHaveTextContent('String');
Expand All @@ -117,7 +117,7 @@ describe('FieldDoc', () => {
});

it('should render a string field with arguments', () => {
const { container } = render(
const { container, getByText } = render(
<FieldDocumentationWithContext
field={exampleObject.getFields().stringWithArgs}
/>,
Expand All @@ -139,7 +139,7 @@ describe('FieldDoc', () => {
container.querySelectorAll('.graphiql-markdown-deprecation'),
).toHaveLength(0);
// make sure deprecation is present
fireEvent.click(container.querySelector('.show-btn'));
fireEvent.click(getByText('Show Deprecated Arguments'));
const deprecationDocs = container.querySelectorAll(
'.graphiql-markdown-deprecation',
);
Expand Down
Loading