Skip to content

Commit 2fb29b7

Browse files
committed
e2e test for implicit fragments, readme, handle refresh
1 parent 5183232 commit 2fb29b7

File tree

6 files changed

+57
-12
lines changed

6 files changed

+57
-12
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const endpoints = [`/___graphql`, `/_graphql`, `/___graphiql`]
2+
3+
const testQueryString = `?query=${encodeURIComponent(`{
4+
site {
5+
...TestingFragment
6+
}
7+
}`)}`
8+
9+
describe(`The GraphQL endpoint`, () => {
10+
11+
it(`Should execute operations with implicit fragments`, () => {
12+
// prefill query from query string
13+
cy.visit(endpoint + testQueryString)
14+
cy.get(`.graphiql-container`).should(`be.visible`)
15+
cy.get(`.execute-button`).click()
16+
cy.get(`.result-window .CodeMirror-code`).contains(
17+
`Gatsby Default Starter`
18+
)
19+
})
20+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* eslint-disable */
2+
import { graphql } from "gatsby"
3+
4+
export const GatsbyImageSharpFixed = graphql`
5+
fragment TestingFragment on Site {
6+
siteMetadata {
7+
title
8+
}
9+
}
10+
`

packages/gatsby-graphiql-explorer/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ _Note:_ accessible at `http://localhost:8000/___graphql` after running `gatsby d
1010

1111
- Offline support - for when you need to work on your excellent Gatsby app on a plane, train, or elsewhere off the grid
1212
- [GraphiQL Explorer][graphiql-explorer] - an interactive explorer plugin to visually create and interact with the GraphQL schema
13+
- Support for implied fragments - whether provided by you, core or plugins. Autocompletion, validation & operation execution are all covered!
1314
- _All_ the expected features you know and love from [GraphiQL][graphiql]
1415

1516
[graphiql]: https://github.com/graphql/graphiql

packages/gatsby-graphiql-explorer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"core-js": "^3.8.1",
4343
"cross-env": "^7.0.3",
4444
"css-loader": "^1.0.1",
45-
"graphiql": "^1.3.1",
45+
"graphiql": "^1.3.2",
4646
"graphiql-code-exporter": "^3.0.3",
4747
"graphiql-explorer": "^0.6.2",
4848
"html-webpack-plugin": "^3.2.0",

packages/gatsby-graphiql-explorer/src/app/app.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ function graphQLFetcher(graphQLParams) {
6969
})
7070
}
7171

72+
const fetchFragments = async () =>
73+
fetch(`/___graphiql/fragments`)
74+
.catch(err => console.error(`Error fetching external fragments: \n${err}`))
75+
.then(response => response.json())
76+
7277
// When the query and variables string is edited, update the URL bar so
7378
// that it can be easily shared.
7479
function onEditVariables(newVariables) {
@@ -166,6 +171,7 @@ const storedCodeExporterPaneState =
166171
class App extends React.Component {
167172
state = {
168173
schema: null,
174+
externalFragments: null,
169175
query: DEFAULT_QUERY,
170176
variables: DEFAULT_VARIABLES,
171177
explorerIsOpen: storedExplorerPaneState,
@@ -316,11 +322,21 @@ class App extends React.Component {
316322
Authorization: this.state.refreshToken,
317323
}
318324
}
325+
fetchFragments().then(externalFragments => {
326+
this.setState({ externalFragments })
327+
})
328+
319329
return fetch(`/__refresh`, options)
320330
}
321331

322332
render() {
323-
const { query, variables, schema, codeExporterIsOpen } = this.state
333+
const {
334+
query,
335+
variables,
336+
schema,
337+
codeExporterIsOpen,
338+
externalFragments: externalFragmentsState,
339+
} = this.state
324340
const { externalFragments } = this.props
325341
const codeExporter = codeExporterIsOpen ? (
326342
<CodeExporter
@@ -352,7 +368,7 @@ class App extends React.Component {
352368
onEditQuery={this._handleEditQuery}
353369
onEditVariables={onEditVariables}
354370
onEditOperationName={onEditOperationName}
355-
externalFragments={externalFragments}
371+
externalFragments={externalFragmentsState || externalFragments}
356372
>
357373
<GraphiQL.Toolbar>
358374
<GraphiQL.Button
@@ -393,11 +409,9 @@ class App extends React.Component {
393409
// crude way to fetch fragments on boot time
394410
// it won't hot reload fragments (refresh requires)
395411
// but good enough for initial integration
396-
fetch(`/___graphiql/fragments`)
397-
.then(response => response.json())
398-
.then(externalFragments => {
399-
ReactDOM.render(
400-
<App externalFragments={externalFragments} />,
401-
document.getElementById(`root`)
402-
)
403-
})
412+
fetchFragments().then(externalFragments => {
413+
ReactDOM.render(
414+
<App externalFragments={externalFragments} />,
415+
document.getElementById(`root`)
416+
)
417+
})

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12295,7 +12295,7 @@ graphiql-explorer@^0.6.2:
1229512295
resolved "https://registry.yarnpkg.com/graphiql-explorer/-/graphiql-explorer-0.6.2.tgz#ea81a8770e3e68c2a97fe849b294bad94ed509e3"
1229612296
integrity sha512-hYSM+TI/0IAXltMOL7YXrvnA5xrKoDjjN7qiksxca2DY7yu46cyHVHG0IKIrBozMDBQLvFOhQMPrzplErwVZ1g==
1229712297

12298-
graphiql@^1.3.1:
12298+
graphiql@^1.3.2:
1229912299
version "1.3.2"
1230012300
resolved "https://registry.yarnpkg.com/graphiql/-/graphiql-1.3.2.tgz#fc9123ec63e587e02699983c617f9338bc09cb40"
1230112301
integrity sha512-huo1Uxkcb1wpCGlDjE1N5X3dUrBTnOlj7/VgXwFUF0mcq/l/5RBTYx49pAc92DXO7rx715ZtUtAL60PxzGeh+w==

0 commit comments

Comments
 (0)