add @graphiql/plugin-explorer package
#2715
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a the first official GraphiQL plugin as package, which is the OneGraph Explorer!
The only export of the package is a hook called
useExplorerPluginwhich will return the plugin object that can be passed to theGraphiQLcomponent. An example of how this works is included in the package README.This PR also proposes a solution of how to use these plugin packages in CDN bundles. The crux here is that we mustn't load
graphql-jsmore than once, otherwise we run into the "different realms" problem. The solution has two parts:graphiqlalready includesgraphql-js, so we now set a static propertyGraphiQL.GraphQLthat contains all the exports fromgraphql-js.graphqlas external and set the global toGraphiQL.GraphQL, that way the CDN bundle for the plugin won't contain any parts ofgraphql-jsand it will use the module from thegraphiqlCDN bundle.(Note that we do basically the same thing with
@graphiql/reactas we already need to include it in thegraphiqlCDN bundle. That way we don't need to load the same code twice in plugin CDN bundles that need any of the exports from that package.)There is a tiny breaking change hidden here, because we remove the three hooks that we previously directly added as static properties on
GraphiQLin the CDN bundle. I reckon it's fine as we only added that two days ago, also there is a simply fix to that by just using the hook fromGraphiQL.React.useXYZ.