Skip to content

Commit

Permalink
[redesign] docs (#2588)
Browse files Browse the repository at this point in the history
* add icons

* add `Button` component to `@graphiql/react`

* add explorer section component

* redesign `SchemaDocumentation` component

* redesign `TypeDocumentation` component

* redesign `FieldDocumentation` component

* redesign `DocExplorer` component

* extend changeset message
  • Loading branch information
thomasheyenbrock committed Aug 9, 2022
1 parent 2fdd5fd commit beaf61b
Show file tree
Hide file tree
Showing 40 changed files with 805 additions and 758 deletions.
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,26 +1,24 @@
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,
introspect() {},
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 @@ -46,17 +44,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

0 comments on commit beaf61b

Please sign in to comment.