-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
handle the race condition in updating operationName #344
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,7 +167,18 @@ export class GraphiQL extends React.Component { | |
if (nextSchema !== this.state.schema || | ||
nextQuery !== this.state.query || | ||
nextOperationName !== this.state.operationName) { | ||
this._updateQueryFacts(nextQuery); | ||
const updatedQueryAttributes = this._updateQueryFacts( | ||
nextQuery, | ||
nextOperationName, | ||
this.state.operations, | ||
nextSchema, | ||
); | ||
|
||
if (updatedQueryAttributes !== undefined) { | ||
nextOperationName = updatedQueryAttributes.operationName; | ||
|
||
this.setState(updatedQueryAttributes); | ||
} | ||
} | ||
|
||
// If schema is not supplied via props and the fetcher changed, then | ||
|
@@ -650,34 +661,41 @@ export class GraphiQL extends React.Component { | |
|
||
handleEditQuery = debounce(100, value => { | ||
if (this.state.schema) { | ||
this._updateQueryFacts(value); | ||
this.setState( | ||
this._updateQueryFacts( | ||
value, | ||
this.state.operationName, | ||
this.state.operations, | ||
this.state.schema, | ||
), | ||
); | ||
} | ||
this.setState({ query: value }); | ||
if (this.props.onEditQuery) { | ||
return this.props.onEditQuery(value); | ||
} | ||
}) | ||
|
||
_updateQueryFacts = query => { | ||
const queryFacts = getQueryFacts(this.state.schema, query); | ||
_updateQueryFacts = (query, operationName, operations, schema) => { | ||
const queryFacts = getQueryFacts(schema, query); | ||
if (queryFacts) { | ||
// Update operation name should any query names change. | ||
const operationName = getSelectedOperationName( | ||
this.state.operations, | ||
this.state.operationName, | ||
const updatedOperationName = getSelectedOperationName( | ||
operations, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I'm wrong on this one. This is the previous operations, just was confused by the names |
||
operationName, | ||
queryFacts.operations | ||
); | ||
|
||
// Report changing of operationName if it changed. | ||
const onEditOperationName = this.props.onEditOperationName; | ||
if (onEditOperationName && operationName !== this.state.operationName) { | ||
onEditOperationName(operationName); | ||
if (onEditOperationName && operationName !== updatedOperationName) { | ||
onEditOperationName(updatedOperationName); | ||
} | ||
|
||
this.setState({ | ||
operationName, | ||
return { | ||
operationName: updatedOperationName, | ||
...queryFacts | ||
}); | ||
}; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combine this with the above to ensure one call to setState?