File tree Expand file tree Collapse file tree 2 files changed +90
-3
lines changed
packages/gatsby-graphiql-explorer/src/app Expand file tree Collapse file tree 2 files changed +90
-3
lines changed Original file line number Diff line number Diff line change 1+ import { removeQueryName } from "../snippets"
2+ import { stripIndent } from "common-tags"
3+
4+ describe ( `removeQueryName` , ( ) => {
5+ function getFullQuery ( startOfQuery ) {
6+ return `${ startOfQuery }
7+ allMarkdownRemark {
8+ nodes {
9+ excerpt
10+ }
11+ }
12+ }`
13+ }
14+
15+ it ( `{` , ( ) => {
16+ const startOfQuery = `{`
17+ expect ( removeQueryName ( getFullQuery ( startOfQuery ) ) ) . toMatchInlineSnapshot ( `
18+ "{
19+ allMarkdownRemark {
20+ nodes {
21+ excerpt
22+ }
23+ }
24+ }"
25+ ` )
26+ } )
27+
28+ it ( `query {` , ( ) => {
29+ const startOfQuery = `query {`
30+ expect ( removeQueryName ( getFullQuery ( startOfQuery ) ) ) . toMatchInlineSnapshot ( `
31+ "query {
32+ allMarkdownRemark {
33+ nodes {
34+ excerpt
35+ }
36+ }
37+ }"
38+ ` )
39+ } )
40+
41+ it ( `query NameOfTheQuery {` , ( ) => {
42+ const startOfQuery = `query NameOfTheQuery {`
43+ expect ( removeQueryName ( getFullQuery ( startOfQuery ) ) ) . toMatchInlineSnapshot ( `
44+ "query {
45+ allMarkdownRemark {
46+ nodes {
47+ excerpt
48+ }
49+ }
50+ }"
51+ ` )
52+ } )
53+
54+ it ( `query ($args: String) {` , ( ) => {
55+ const startOfQuery = `query ($args: String) {`
56+ expect ( removeQueryName ( getFullQuery ( startOfQuery ) ) ) . toMatchInlineSnapshot ( `
57+ "query ($args: String) {
58+ allMarkdownRemark {
59+ nodes {
60+ excerpt
61+ }
62+ }
63+ }"
64+ ` )
65+ } )
66+
67+ it ( `query NameOfTheQuery ($args: String) {` , ( ) => {
68+ const startOfQuery = `query NameOfTheQuery ($args: String) {`
69+ expect ( removeQueryName ( getFullQuery ( startOfQuery ) ) ) . toMatchInlineSnapshot ( `
70+ "query ($args: String) {
71+ allMarkdownRemark {
72+ nodes {
73+ excerpt
74+ }
75+ }
76+ }"
77+ ` )
78+ } )
79+ } )
Original file line number Diff line number Diff line change 1+ export function removeQueryName ( query ) {
2+ return query . replace (
3+ / ^ [ ^ { ( ] + ( [ { ( ] ) / ,
4+ ( _match , openingCurlyBracketsOrParenthesis ) =>
5+ `query ${ openingCurlyBracketsOrParenthesis } `
6+ )
7+ }
8+
19const getQuery = ( arg , spaceCount ) => {
210 const { operationDataList } = arg
311 const { query } = operationDataList [ 0 ]
4- const anonymousQuery = query . replace ( / q u e r y \s . + { / gim , `{` )
12+ const anonymousQuery = removeQueryName ( query )
513 return (
614 ` ` . repeat ( spaceCount ) +
715 anonymousQuery . replace ( / \n / g, `\n` + ` ` . repeat ( spaceCount ) )
@@ -16,13 +24,13 @@ const pageQuery = {
1624 generate : arg => `import React from "react"
1725import { graphql } from "gatsby"
1826
19- const ComponentName = ({ data }) => <pre>{JSON.stringify(data, null, 4)}</pre>
27+ const Page = ({ data }) => <pre>{JSON.stringify(data, null, 4)}</pre>
2028
2129export const query = graphql\`
2230${ getQuery ( arg , 2 ) }
2331\`
2432
25- export default ComponentName
33+ export default Page
2634
2735` ,
2836}
You can’t perform that action at this time.
0 commit comments