Skip to content

Feature Request: Better way to drop into server. #4

@reggi

Description

@reggi

Right now I have this file in a utils.js somewhere on my server.

It would be sweet if I didn't need to rely on any other services here and really utilize the npm dependency. This feels kind of hacky.

export let staticDocsHTML = () => {
  return `
    <!DOCTYPE html>
    <html>
        <head>
            <title>GraphQL Docs</title>
        </head>

        <body>
            <div id="app"></div>

            <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.2/react.js"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.2/react-dom.js"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js"></script>
            <script src="https://github.com/mhallin/graphql-docs/releases/download/v0.1.4/graphql-docs.min.js"></script>
            <script>
                function fetcher(query) {
                    return fetch(window.location.origin + '/graphql', {
                        method: 'POST',
                        headers: {
                            Accept: 'application/json',
                            'Content-Type': 'application/json',
                        },
                        body: JSON.stringify({
                            query: query,
                        }),
                    }).then(function(r) {
                        return r.json();
                    });
                }
                const rootElem = document.getElementById('app');
                ReactDOM.render(
                    React.createElement(
                        GraphQLDocs.GraphQLDocs,
                        {
                            fetcher: fetcher,
                        }),
                    rootElem
                );
            </script>
        </body>
    </html>
  `
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions