-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate @storybook/addon-graphql to typescript (#6935)
Migrate @storybook/addon-graphql to typescript
- Loading branch information
Showing
11 changed files
with
89 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...raphql/src/components/FullScreen/index.js → ...aphql/src/components/FullScreen/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import React from 'react'; | ||
import React, { FunctionComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import style from './style'; | ||
import { style } from './style'; | ||
|
||
export default function FullScreen({ children }) { | ||
export const FullScreen: FunctionComponent = ({ children }) => { | ||
return <div style={style.wrapper}>{children}</div>; | ||
} | ||
}; | ||
|
||
FullScreen.defaultProps = { children: null }; | ||
FullScreen.propTypes = { children: PropTypes.node }; |
4 changes: 2 additions & 2 deletions
4
...raphql/src/components/FullScreen/style.js → ...raphql/src/components/FullScreen/style.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
29 changes: 7 additions & 22 deletions
29
addons/graphql/src/manager.js → addons/graphql/src/manager.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react'; | ||
import GraphiQL from 'graphiql'; | ||
|
||
import 'graphiql/graphiql.css'; | ||
|
||
import { FullScreen } from './components/FullScreen'; | ||
import { reIndentQuery, getDefaultFetcher } from './shared'; | ||
|
||
export interface FetcherParams { | ||
query: string; | ||
variables?: string; | ||
operationName?: string; | ||
} | ||
|
||
export interface SetupGraphiQLConfig { | ||
url: string; | ||
fetcher?: (params: FetcherParams) => Promise<any>; | ||
} | ||
|
||
export const setupGraphiQL = (config: SetupGraphiQLConfig) => ( | ||
_query: string, | ||
variables = '{}' | ||
) => { | ||
const query = reIndentQuery(_query); | ||
const fetcher = config.fetcher || getDefaultFetcher(config.url); | ||
return () => ( | ||
<FullScreen> | ||
<GraphiQL query={query} variables={variables} fetcher={fetcher} /> | ||
</FullScreen> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { fetch } from 'global'; | ||
|
||
import { FetcherParams } from './preview'; | ||
|
||
const FETCH_OPTIONS = { | ||
method: 'post', | ||
headers: { 'Content-Type': 'application/json' }, | ||
}; | ||
|
||
export const getDefaultFetcher = (url: string) => { | ||
return (params: FetcherParams) => { | ||
const body = JSON.stringify(params); | ||
const options = Object.assign({ body }, FETCH_OPTIONS); | ||
return fetch(url, options).then((res: any) => res.json()); | ||
}; | ||
}; | ||
|
||
export const reIndentQuery = (query: string) => { | ||
const lines = query.split('\n'); | ||
const spaces = lines[lines.length - 1].length - 1; | ||
return lines.map((l, i) => (i === 0 ? l : l.slice(spaces))).join('\n'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
declare module 'global'; | ||
|
||
// There are no types for graphiql | ||
declare module 'graphiql' { | ||
const GraphiQL: any; | ||
export default GraphiQL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"types": ["webpack-env"] | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
], | ||
"exclude": [ | ||
"src/__tests__/**/*" | ||
] | ||
} |