Skip to content

Commit

Permalink
Merge pull request #1 from hasura/initial
Browse files Browse the repository at this point in the history
initial code
  • Loading branch information
kikkupico authored Dec 8, 2021
2 parents 347d97d + 41f7530 commit e8af591
Show file tree
Hide file tree
Showing 30 changed files with 57,371 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
.DS_Store
88 changes: 88 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Hasura GraphiQL Component

Published on NPM at https://www.npmjs.com/package/@hasura/public-graphiql

## Usage

Usage example -

```javascript
render(
<HasuraGraphiQL
defaultUrl="https://hasura.io/graphql"
defaultSubscriptionUrl="wss://hasura.io/graphql"
defaultHeaders={{ "Content-Type": "application/json" }}
maskedHeaders={["Content-Type"]}
/>,
container
);
```

Sample usage with component customisation -

```javascript
<HasuraGraphiQL
defaultUrl={defaultUrl}
defaultSubscriptionUrl={defaultSubscriptionUrl}
defaultHeaders={defaultHeaders}
isCloud
graphiQLOptions={{ readOnly: true }}
explorerOptions={{
colors: {
keyword: "red",
// OperationName, FragmentName
def: "blue",
// FieldName
property: "yellow",
},
}}
/>
```

NOTE FOR TAILWIND USERS: To make the component styles compatible with Tailwind, add this line - `import "@hasura/public-graphiql/dist/tailwind-override.css`

### Props

defaultUrl:string - initial graphql endpoint to be loaded

defaultSubscriptionUrl:string - initial graphql subscription endpoint to be loaded

defaultHeaders:Record<string, string> - initial set of request headers to be loaded;

hiddenHeaders:string[] - headers whose values are masked

defaultQuery:string - intial query to be shown

defaultVariables:string - intial variables to be shown

graphiQLOptions:Omit<GraphiQLProps, fetcher> - props to pass through to GraphiQL component; fetcher cannot be customised

explorerOptions:ExplorerProps - props to pass through to GraphiQLExplorer component

customToolbar: React.ReactNode - elements to be shown next to the endpoint input

children: React.ReactNode - nodes to be added as GraphiQL children

All props are optional.

### Exports

HasuraGraphiQL(default)
GraphiQL.Button as GraphiQLButton
GraphiQL.Toolbar as GraphiQLToolbar


## Development

To run a dev server with a sample UI, run
`npm i` and then `npm start`

The sample UI takes configuration info from the URL params. Visit http://localhost:3000/?subscription-endpoint=wss://thankful-beetle-75.hasura.app/v1/graphql&endpoint=https://thankful-beetle-75.hasura.app/v1/graphql&header=x-hasura-admin-secret:q3qsst5kj9xwYg7nvJw73uX0TgvSObwcNqjj0vcGaB89AX5pxvsFshvgxidV5l9j to get sample data populated.

To run tests, run
`yarn cypress open-ct`

To build a package for publishing to NPM, run
`npm run build`

This will create a 'dist' folder which can be published to NPM using `npm publish` flow.
27 changes: 27 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"presets": [
[
"@babel/env",
{
"targets": {
"edge": "17",
"firefox": "60",
"chrome": "67",
"safari": "11.1"
},
"useBuiltIns": "usage",
"corejs": "3.6.5"
}
],
[
"@babel/preset-typescript",
{
"isTSX": true,
"allExtensions": true
}
],
[
"@babel/preset-react"
]
]
}
6 changes: 6 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"component": {
"testFiles": "**/*.test.{js,ts,jsx,tsx}",
"componentFolder": "src"
}
}
1 change: 1 addition & 0 deletions cypress/fixtures/schema.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const injectDevServer = require("@cypress/react/plugins/react-scripts")

module.exports = (on, config) => {
injectDevServer(on, config)
return config
}
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading

0 comments on commit e8af591

Please sign in to comment.