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

migrate graphiql-explorer into the repo, ts conversion #3374

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
156 changes: 156 additions & 0 deletions packages/graphiql-explorer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
Interactive explorer plugin for GraphiQL.

Try it live with the [GraphiQL Plugins Demo](https://graphiql-test.netlify.app/webpack).

## Created by OneGraph

[OneGraph](https://www.onegraph.com) provides easy, consistent access to the APIs that underlie your business--all through the power of GraphQL.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[OneGraph](https://www.onegraph.com) provides easy, consistent access to the APIs that underlie your business--all through the power of GraphQL.
[OneGraph](https://www.onegraph.com) provides easy, consistent access to the APIs that underlie your businessall through the power of GraphQL.


Sign up at [https://www.onegraph.com](http://www.onegraph.com).

[![npm version](http://img.shields.io/npm/v/graphiql-explorer.svg?style=flat)](https://npmjs.org/package/graphiql-explorer 'View this project on npm')

## Example usage

The recommended way to use `graphiql-explorer` is via the `graphiql` plugin - [`@graphiql/plugin-explorer`](../graphiql-plugin-explorer/)

[Read the rationale on the OneGraph blog](https://www.onegraph.com/blog/2019/01/24/How_OneGraph_onboards_users_new_to_GraphQL.html).

## Changes from the OneGraph version

1. Converted to Typescript
2. Split into multiple files
3. new `ExplorerInner` and `GraphiQLExplorerInnerProps` exports which remove some of the presentation complexity for the graphiql plugin.
4. uses modern targets and only exports esm build, does not export cjs, bundle and transpile as needed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
4. uses modern targets and only exports esm build, does not export cjs, bundle and transpile as needed
4. uses modern targets and only exports esm build; does not export cjs; bundle and transpile as needed


## Customizing styles

The default styling matches for the Explorer matches the default styling for GraphiQL. If you've customized your GraphiQL styling, you can customize the Explorer's styling to match.

### Customizing colors

The Explorer accepts a `colors` prop as a map of the class names in GraphiQL's css to hex colors. If you've edited the GraphiQL class names that control colors (e.g. `cm-def`, `cm-variable`, `cm-string`, etc.) use those same colors in the colors map. The naming of the keys in the colors map tries to align closely with the names of the class names in GraphiQL's css (note that the Explorer can't just apply the classes because of conflicts with how the css file styles inputs).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The Explorer accepts a `colors` prop as a map of the class names in GraphiQL's css to hex colors. If you've edited the GraphiQL class names that control colors (e.g. `cm-def`, `cm-variable`, `cm-string`, etc.) use those same colors in the colors map. The naming of the keys in the colors map tries to align closely with the names of the class names in GraphiQL's css (note that the Explorer can't just apply the classes because of conflicts with how the css file styles inputs).
The Explorer accepts a `colors` prop as a map of the class names in GraphiQL's css to hex colors. If you've edited the GraphiQL class names that control colors (e.g. `cm-def`, `cm-variable`, `cm-string`, etc.), use those same colors in the colors map. The naming of the keys in the colors map tries to align closely with the class names in GraphiQL's css (note that the Explorer can't just apply the classes because of conflicts with how the css file styles inputs).


Example style map:

```jsx
<Explorer
colors={{
keyword: '#B11A04',
// OperationName, FragmentName
def: '#D2054E',
// FieldName
property: '#1F61A0',
// FieldAlias
qualifier: '#1C92A9',
// ArgumentName and ObjectFieldName
attribute: '#8B2BB9',
number: '#2882F9',
string: '#D64292',
// Boolean
builtin: '#D47509',
// Enum
string2: '#0B7FC7',
variable: '#397D13',
// Type
atom: '#CA9800',
}}
/>
```

### Customizing arrows and checkboxes

The explorer accepts props for setting custom checkboxes (for leaf fields) and arrows (for object fields).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The explorer accepts props for setting custom checkboxes (for leaf fields) and arrows (for object fields).
The explorer accepts properties for setting custom checkboxes (for leaf fields) and arrows (for object fields).


The props are `arrowOpen`, `arrowClosed`, `checkboxChecked`, and `checkboxUnchecked`. You can pass any react node for those props.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The props are `arrowOpen`, `arrowClosed`, `checkboxChecked`, and `checkboxUnchecked`. You can pass any react node for those props.
The properties are `arrowOpen`, `arrowClosed`, `checkboxChecked`, and `checkboxUnchecked`. You can pass any react node for those props.


The defaults are

arrowOpen

```jsx
<svg width="12" height="9">
<path fill="#666" d="M 0 2 L 9 2 L 4.5 7.5 z" />
</svg>
```

arrowClosed

```jsx
<svg width="12" height="9">
<path fill="#666" d="M 0 0 L 0 9 L 5.5 4.5 z" />
</svg>
```

checkboxChecked

```jsx
<svg
style={{ marginRight: '3px', marginLeft: '-3px' }}
width="12"
height="12"
viewBox="0 0 18 18"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M16 0H2C0.9 0 0 0.9 0 2V16C0 17.1 0.9 18 2 18H16C17.1 18 18 17.1 18 16V2C18 0.9 17.1 0 16 0ZM16 16H2V2H16V16ZM14.99 6L13.58 4.58L6.99 11.17L4.41 8.6L2.99 10.01L6.99 14L14.99 6Z"
fill="#666"
/>
</svg>
```

checkboxUnchecked

```jsx
<svg
style={{ marginRight: '3px', marginLeft: '-3px' }}
width="12"
height="12"
viewBox="0 0 18 18"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M16 2V16H2V2H16ZM16 0H2C0.9 0 0 0.9 0 2V16C0 17.1 0.9 18 2 18H16C17.1 18 18 17.1 18 16V2C18 0.9 17.1 0 16 0Z"
fill="#CCC"
/>
</svg>
```

### Customizing the buttons to create new operations

You can modify the styles for the buttons that allow you to create new operations.

Pass the `styles` prop when you create the component. It's an object with two keys, `explorerActionsStyle` and `buttonStyle`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Pass the `styles` prop when you create the component. It's an object with two keys, `explorerActionsStyle` and `buttonStyle`.
Pass the `styles` property when you create the component. It's an object with two keys, `explorerActionsStyle` and `buttonStyle`.


Example styles map:

```jsx
<Explorer
styles={{
buttonStyle: {
fontSize: '1.2em',
padding: '0px',
backgroundColor: 'white',
border: 'none',
margin: '5px 0px',
height: '40px',
width: '100%',
display: 'block',
maxWidth: 'none',
},

explorerActionsStyle: {
margin: '4px -8px -8px',
paddingLeft: '8px',
bottom: '0px',
width: '100%',
textAlign: 'center',
background: 'none',
borderTop: 'none',
borderBottom: 'none',
},
}}
/>
```
27 changes: 27 additions & 0 deletions packages/graphiql-explorer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "graphiql-explorer",
"version": "0.10.0",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
Copy link
Member Author

@acao acao Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some other thoughts about the package @sgrove & @dwwoelfel :

  • we can include a CJS export as well for backwards compatibility
  • we can import and triage existing issues and PRs
  • when we move to stylesheets and css variables, we would make it 0.11, and continue incrementing minor versions for breaking changes as such

"contributors": [
{
"name": "Daniel Woelfel",
"email": "[email protected]"
},
{
"name": "Sean Grove",
"email": "[email protected]"
}
],
"peerDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"graphql": "^15.0.0 || ^16.0.0"
},
"devDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"graphql": "^16.4.0"
}
}
Loading