forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gatsby-graphiql-explorer): Implement CodeExporter (gatsbyjs#17120)
* Implement CodeExporter into graphiql * Add some formatting * Added a createPages snippet * use same local storage key, as one that is being set * invert condition - we want to check if it's explicitely set to true * make createPages snippet richer, so full flow is accounted for * Generate more detailed query * Formatting * Return name as default * Return always from getFieldQuery * Use named components
- Loading branch information
1 parent
03173a1
commit ee9ffd5
Showing
4 changed files
with
123 additions
and
2 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
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,72 @@ | ||
const getQuery = (arg, spaceCount) => { | ||
const { operationDataList } = arg | ||
const { query } = operationDataList[0] | ||
const anonymousQuery = query.replace(/query\s.+{/gim, `{`) | ||
return ( | ||
` `.repeat(spaceCount) + | ||
anonymousQuery.replace(/\n/g, `\n` + ` `.repeat(spaceCount)) | ||
) | ||
} | ||
|
||
const pageQuery = { | ||
name: `Page query`, | ||
language: `JavaScript`, | ||
codeMirrorMode: `jsx`, | ||
options: [], | ||
generate: arg => `import React from "react" | ||
import { graphql } from "gatsby" | ||
const ComponentName = ({ data }) => <pre>{JSON.stringify(data, null, 4)}</pre> | ||
export const query = graphql\` | ||
${getQuery(arg, 2)} | ||
\` | ||
export default ComponentName | ||
`, | ||
} | ||
|
||
const staticHook = { | ||
name: `StaticQuery hook`, | ||
language: `JavaScript`, | ||
codeMirrorMode: `jsx`, | ||
options: [], | ||
generate: arg => `import React from "react" | ||
import { useStaticQuery, graphql } from "gatsby" | ||
const ComponentName = () => { | ||
const data = useStaticQuery(graphql\` | ||
${getQuery(arg, 4)} | ||
\`) | ||
return <pre>{JSON.stringify(data, null, 4)}</pre> | ||
} | ||
export default ComponentName | ||
`, | ||
} | ||
|
||
const staticQuery = { | ||
name: `StaticQuery`, | ||
language: `JavaScript`, | ||
codeMirrorMode: `jsx`, | ||
options: [], | ||
generate: arg => `import React from "react" | ||
import { StaticQuery, graphql } from "gatsby" | ||
const ComponentName = () => ( | ||
<StaticQuery | ||
query={graphql\` | ||
${getQuery(arg, 6)} | ||
\`} | ||
render={data => <pre>{JSON.stringify(data, null, 4)}</pre>} | ||
></StaticQuery> | ||
) | ||
export default ComponentName | ||
`, | ||
} | ||
|
||
export default [pageQuery, staticHook, staticQuery] |
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