ariadne icon indicating copy to clipboard operation
ariadne copied to clipboard

GraphQL Playground retired, switch to GraphiQL?

Open bartenra opened this issue 3 years ago • 3 comments

GraphQL Playground has been retired, and will no longer receive updates: https://github.com/graphql/graphql-playground/issues/1143

Down the line, I think it would make sense for Ariadne to switch to GraphiQL because of this.

bartenra avatar Jun 07 '21 11:06 bartenra

I've tagged this as decision needed because GraphiQL is still behind Playground.

rafalp avatar Jul 05 '21 11:07 rafalp

I think it is good to switch to GraphiQL although I will miss the color scheme on Playground. GraphiQL does autofill some of the queries making it easier to use.

ccsv avatar Aug 05 '22 05:08 ccsv

Let's keep an eye on https://github.com/graphql/graphiql/issues/2328

Once released, if Ariadne adopts it would be handy to allow passing settings so the user can configure the theme and other params https://github.com/mirumee/ariadne/issues/469

dacevedo12 avatar Aug 05 '22 14:08 dacevedo12

My plan for this is to have an option on GraphQL app named explorer. If this is set to None, we'll use whatever is default GraphQL explorer for Ariadne at time. We will default to GraphiQL2 but will support Playground if you want and accept the risks. This will also let us provide special "404" explorer which always return 404 NOT FOUND response to the clients.

rafalp avatar Oct 03 '22 16:10 rafalp

Can we get the GraphiQL2 with the explorer plug in?

https://graphql.org/swapi-graphql? << without explorer

https://www.youtube.com/watch?v=8DmtCPX4tdo << with explorer panel (around 2:09 minutes into video)

davlee1972 avatar Oct 04 '22 21:10 davlee1972

Looks nice, @davlee1972. Is that version of GraphiQL available on CDN? We don't want to maintain and serve custom API explorer builds for Ariadne.

rafalp avatar Oct 05 '22 09:10 rafalp

Yes this is the latest version: https://www.npmjs.com/package/graphiql

But the Explorer functionality is a plug-in.. The YouTube video above goes through the plug-in installation steps.

At some point GraphiQL will include the Explorer I believe and it is discussed in: https://github.com/graphql/graphiql/issues/2328

davlee1972 avatar Oct 05 '22 17:10 davlee1972

But the Explorer functionality is a plug-in.. The YouTube video above goes through the plug-in installation steps.

I understand, but Ariadne never served any static files for API explorers, only HTML that pulled assets from CDN.

rafalp avatar Oct 05 '22 17:10 rafalp

There is a HTML file for this.. https://www.npmjs.com/package/graphiql

Examples Unpkg (CDN) - A single HTML file using CDN assets and a script tag

Found more info on the explorer plug-in here: https://github.com/graphql/graphiql/tree/4270007671ce52f6c2250739916083611748b657/packages/graphiql-plugin-explorer

CDN bundles You can also use add this plugin when using the CDN bundle to render GraphiQL. Check out the example HTML file that shows how you can do this.

https://github.com/graphql/graphiql/blob/4270007671ce52f6c2250739916083611748b657/packages/graphiql-plugin-explorer/examples/index.html

davlee1972 avatar Oct 05 '22 18:10 davlee1972

The last index.html works.. I just plugged it into Ariadne

from ariadne.constants import PLAYGROUND_HTML

def get_graphiql_html():
    with open("Fund_API/graphQL/index.html") as f:
        return f.read()

GRAPHIQL_HTML = get_graphiql_html()

I did have to modify the index.html to swap in the URL of my graphql server and default query to show. These can probably be part of some initialization routine to modify the html.

var fetcher = GraphiQL.createFetcher({
        url: 'https://swapi-graphql.netlify.app/.netlify/functions/index',
      });

      function GraphiQLWithExplorer() {
        var [query, setQuery] = React.useState(
          'query AllFilms {\n  allFilms {\n    films {\n      title\n    }\n  }\n}',
        );

davlee1972 avatar Oct 05 '22 21:10 davlee1972

After some experimentation (and having to implement custom template engine) I've got this:

Zrzut ekranu 2022-10-6 o 17 19 50

So explorers are strategy objects, and each explorer is free to implement custom features specific to it.

And if you are unhappy, you can always implement your own behaviour without having to dive into Ariadne's code.

rafalp avatar Oct 06 '22 15:10 rafalp

Here's the apollo client html, but it has a lot of extra apollo links in the html..

https://studio.apollographql.com/public/star-wars-swapi/explorer?variant=current

<div style="width: 100%; height: 100%;" id='embedded-sandbox'></div>
<script src="https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js"></script> 
<script>
  new window.EmbeddedSandbox({
    target: '#embedded-sandbox',
    initialEndpoint: 'http://localhost:4000',
    includeCookies: false,
  });
</script>

davlee1972 avatar Oct 11 '22 21:10 davlee1972

I'm not sure we can do that in Ariadne core, seeing how Apollo keeps client part of their product, and there's no mention anywhere about running IDE on your own location or licensing.

https://github.com/apollographql/apollo-studio-community/issues/2

rafalp avatar Oct 11 '22 21:10 rafalp

I'm not sure.. the github code says MIT..

https://www.apollographql.com/docs/studio/explorer/sandbox/ You can use Sandbox offline and without an Apollo account. You also embed Sandbox on your own website.

https://github.com/apollographql/embeddable-explorer/blob/main/LICENSE

davlee1972 avatar Oct 11 '22 22:10 davlee1972

Perfect, this is what I was looking for!

rafalp avatar Oct 11 '22 23:10 rafalp

@davlee1972 support for multiple explorers has been merged to Ariadne. I've did a skim of Apollo's client and decided to open separate issue for that, but I'll prioritize other work for 0.17 release now. If you can contribute it with separate PR, I'll be happy to merge it.

rafalp avatar Oct 13 '22 10:10 rafalp