-
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
Improvements for a better embedding several instances of GraphiQL on the same page #152
Comments
Hi @OlegIlyenko! These issues all look legitimate to me - I'll see what I can do soon. Meanwhile, if you'd like to take a stab at it yourself I'm all for it! |
sure, I can try to put a PR together during the next days, not sure I can address all points though. I also have concerns about backwards compatibility. For example changing |
I feel like we have a couple of choices here. One would be generating a breaking change and substitute <div id="graphiql-container" class="graphiql-container"> BTW, although I agree that having |
You brought up a good point. I also doubt that that there is many projects that are relying on a top-level div |
I tried to find a solution for CodeMirror rendering issue. Turns out that one needs to call I tried to use this addon and it works for the most part. Unfortunately, for some reason, it does not work for variable editor if editor does not have any variables defined yet (in this case variable editor is rendered in collapsed state). 😿 One can explicitly call |
@OlegIlyenko about the collapsed variable editor, does it still have a weird gutter size when opening it up? On top of my head this sounds very much possible that it might be a CodeMirror bug - some workaround I could think of is to render an empty JSON string when the editor is empty ( |
yeah, variable editor will have an issue with the gutter size if I expand it after page was loaded, so autorefresh addon does not handle this for some reason. To be honest, I'm not very happy how autorefresh addon implemented anyways - it heavily relies on a timeouts which can cause unpredictable behavior in some cases. So I feel that it's better to avoid it. Explicitly calling |
@OlegIlyenko - sorry about a delayed response. I began to think if what you're doing is already towards a right approach. I figure we have two cases here: Another option we may consider is to call In any case, I was thinking |
To be honest I'm not quite sure either. The last option sounds like a good one if it will work with DOM resize events (it's still a bit of a mystery to me how and when does codemirror calculates the sizes). The second option sounds like a good compromise as well. Though in this case I would prefer a single Generally I would trust your judgment on this one :) I'm not quite sure what would be the best solution considering the browser compatibility and development/maintenance effort. I also updated the last item in my list. I thought about it for a while, and I think it's not right to put it as a TODO item. I guess it's a valid point to consider, but it does not necessarily belongs to this issue or even should be implemented now or later. |
Closes #152 This adds two new public API methods to the `<GraphiQL>` component. `getVariableEditor()` gets the CodeMirror instance for editing variables. `refresh()` will refresh all CodeMirror instances, this may be helpful after changing the size of the containing element or after making it visible for the first time.
…transform-es2015-modules-commonjs-6.24.1 Update babel-plugin-transform-es2015-modules-commonjs to the latest version 🚀
Update eslint to the latest version 🚀
Recently I implemented a small app that builds on top of GraphiQL and provides additional functionality like tabs, headers, etc. http://toolbox.sangria-graphql.org/graphiql
Along the way I faced several issues when I tried to include several instances of GraphiQL on the same page. I also tried to use single instance and control it's state via props based on the selected tab, but it did not really worked very well at all. I found "fragile workarounds" for all of the issues, but I would like to list some of the issues with possible solutions in order to provide a better alternatives in future.
id
of the element which is not appropriate if one wants to include several instances on the same page. This also makes styling a bit harder. I thinkclass
would be a better choice here._runQueryAtCursor
which I'm not suppose to use from the outside (I assume that underscore == private). It would be nice to "officially" expose this method as well.display: none;
) div. The gutter size gets messed up a bit. I had to use a trick where I render an empty div on a tab change (first time only) and then, on a next "frame", i render the actual thing. I'm not 100% sure what the actual problem is :)A minor thing to consider
GraphiQL uses
box-sizing: content-box;
. As far as i saw, many people and css frameworks, like bootstrap and foundation, start to adoptbox-sizing: border-box;
. it's easy to fix withI'm not very familiar with this field, so i'm not sure what would be a better choice, but still maybe it's a point worth considering
The text was updated successfully, but these errors were encountered: