Skip to content
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

Introspection Query always uses initial headers #2442

Closed
3nvi opened this issue May 26, 2022 · 4 comments · Fixed by #2451
Closed

Introspection Query always uses initial headers #2442

3nvi opened this issue May 26, 2022 · 4 comments · Fixed by #2451
Assignees

Comments

@3nvi
Copy link

3nvi commented May 26, 2022

In the latest v1.9.x. release, the headers used for the introspection query (and potentially for other queries as well) are never updated, but instead, retain their initial value.

The culprit here is this effect. Whenever I change the headers in the secondary editor (regardless of whether their value is controlled or not), the useEffect never fires, cause the headerEditor is always null no matter what I've tried here.

Thus the headers.current ref always holds its initial value.

After some searching, I traced it down to the fact that you're attempting to read the EditorContext from within SchemaContextProvider. Funnily though, the SchemaContextProvider wraps the EditorContext and that's why you're not getting any updates there. Reversing the order of the providers should fix it unless the order of the providers was like that for a particular reason (haven't delved deeper into the latter).

I'm willing to work on a PR if you feel that a component order reverse shouldn't create any major problems.

Thanks!

P.S. For anyone else encountering this, at the moment of writing, the last working version is v1.8.10

@acao
Copy link
Member

acao commented May 27, 2022

Thank you for reporting this @3nvi !

@thomasheyenbrock
Copy link
Collaborator

thomasheyenbrock commented May 27, 2022

Hey @3nvi and thanks again for reporting!

Currently the EditorContext currently uses the SchemaContext (see here) for providing some methods on the context object, so just switching would break the EditorContext.

Eventually I wanted to move these methods (autoCompleteLeafs, copy, merge, and prettify) out of the context and into reusable hooks. I didn't do it yet because the main GraphiQLWithContext component is still a class component and can't consume hooks. However we could do this and call the hooks in a new function component that wraps GraphiQLWithContext. This new component would call the hooks and pass the methods down as prop. After we did that, we could switch the context providers. Lmk if that explanation made sense to you 🙂

Happy if you wanna work on this, otherwise I'd address this start of next week!

@3nvi
Copy link
Author

3nvi commented May 27, 2022

Given that you already have a plan laid out, I feel that it would take a lot of back-and-forth between us to align in the approach. I'll let you work on it, but feel free to ping me if you need help or turns out that you don't have any free time :)

@thomasheyenbrock
Copy link
Collaborator

That sounds good to me! I'll take a look into this later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants