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

graphiql 3.x Upgrade #79

Open
brettwilcox opened this issue Jan 26, 2024 · 0 comments
Open

graphiql 3.x Upgrade #79

brettwilcox opened this issue Jan 26, 2024 · 0 comments

Comments

@brettwilcox
Copy link

Hello Dadish!

I wanted to share graphiql 3 example code. You can copy + paste the example into your 'graphiql.php' teplate for a working example that also includes the explorer plugin. I merged your code as best I could with the examples provided.

<?php
/*

// Add these to the header of _main.php
foreach($config->scripts as $url) echo "<script type='text/javascript' src='$url'></script>";
foreach($config->styles as $url) echo "<link rel='stylesheet' type='text/css' href='$url' />";

// Example for on-prem
$config->scripts->add($config->urls->templates . 'js/graphiql3/react.production.min.js');
$config->scripts->add($config->urls->templates . 'js/graphiql3/react-dom.production.min.js');
$config->scripts->add($config->urls->templates . 'js/graphiql3/graphiql.min.js');
$config->scripts->add($config->urls->templates . 'js/graphiql3/explorer.js');
$config->styles->add($config->urls->templates . 'css/graphiql3.css');
$config->styles->add($config->urls->templates . 'css/explorer.css');
*/

// Example for unpkg.com
$config->scripts->add('https://unpkg.com/react@18/umd/react.development.js');
$config->scripts->add('https://unpkg.com/react-dom@18/umd/react-dom.development.js');
$config->scripts->add('https://unpkg.com/graphiql/graphiql.min.js');
$config->scripts->add('https://unpkg.com/@graphiql/plugin-explorer/dist/index.umd.js');
$config->styles->add('https://unpkg.com/graphiql/graphiql.min.css');
$config->styles->add('https://unpkg.com/@graphiql/plugin-explorer/dist/style.css');

?>

<div id="content">

    <div id="graphiql">Loading...</div>
    <script>
        const root = ReactDOM.createRoot(document.getElementById("graphiql"));
        const fetcher = GraphiQL.createFetcher({
            url: "/graphql/",
            headers: {
                Accept: 'application/json',
                'Content-Type': 'application/json',
                'X-Requested-With': 'XMLHttpRequest',
            },
            credentials: 'include',
        });
        const explorerPlugin = GraphiQLPluginExplorer.explorerPlugin();
        root.render(
            React.createElement(GraphiQL, {
                fetcher,
                defaultEditorToolsVisibility: true,
                plugins: [explorerPlugin],
            })
        );
    </script>

    <style>
        #graphiql {
            height: 86vh;
            margin-top: 20px;
        }
    </style>

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

No branches or pull requests

1 participant