Skip to content

Commit ef03591

Browse files
authored
fix(graphiql): fix GraphiQL version 0.9.3 integration (#410)
1 parent 45e5971 commit ef03591

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"@types/pluralize": "0.0.26",
6464
"connect": "^3.5.0",
6565
"express": "^4.14.0",
66-
"graphiql": "^0.9.1",
66+
"graphiql": "0.9.1",
6767
"graphql": "^0.9.3",
6868
"jest": "^18.1.0",
6969
"koa": "^2.0.0",

src/postgraphql/graphiql/src/components/PostGraphiQL.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class PostGraphiQL extends React.Component {
7676
// TODO: Send the introspection query results in the server sent event?
7777
async updateSchema () {
7878
// Don’t allow users to see a schema while we update.
79-
this.setState({ schema: null })
79+
this.setState({ schema: undefined })
8080

8181
// Fetch the schema using our introspection query and report once that has
8282
// finished.
@@ -117,13 +117,21 @@ class PostGraphiQL extends React.Component {
117117
// Ok, so if you look at GraphiQL source code, the `navStack` is made up of
118118
// objects that are either types or fields. Let’s use that to search in
119119
// our new schema for matching (updated) types and fields.
120-
const nextNavStack = navStack.map((typeOrField, i) => {
120+
const nextNavStack = navStack.map((navStackItem, i) => {
121121
// If we are not ok, abort!
122122
if (!allOk)
123123
return null
124124

125+
// Get the definition from the nav stack item.
126+
const typeOrField = navStackItem.def
127+
128+
// If there is no type or field then this is likely the root schema view,
129+
// or a search. If this is the case then just return that nav stack item!
130+
if (!typeOrField) {
131+
return navStackItem
132+
}
125133
// If this is a type, let’s do some shenanigans...
126-
if (isType(typeOrField)) {
134+
else if (isType(typeOrField)) {
127135
// Let’s see if we can get a type with the same name.
128136
const nextType = nextSchema.getType(typeOrField.name)
129137

@@ -136,7 +144,7 @@ class PostGraphiQL extends React.Component {
136144

137145
// If there is a type with the same name, let’s return it! This is the
138146
// new type with all our new information.
139-
return nextType
147+
return { ...navStackItem, def: nextType }
140148
}
141149
// If you thought this function was already pretty bad, it’s about to get
142150
// worse. We want to update the information for an object field.
@@ -168,7 +176,7 @@ class PostGraphiQL extends React.Component {
168176
}
169177

170178
// Otherwise we hope very much that it is correct.
171-
return nextField
179+
return { ...navStackItem, def: nextField }
172180
}
173181
})
174182

0 commit comments

Comments
 (0)