Giter Site home page Giter Site logo

Comments (6)

IvanGoncharov avatar IvanGoncharov commented on May 19, 2024 2

@BuiChiTrung Published 1.0.1 📦 Can you please try it?
It should allow using Voyager as a normal React component.

from graphql-voyager.

prakhathi-m avatar prakhathi-m commented on May 19, 2024 1

You are getting an error because you are not passing the JSON object. you could return the parsed JSON like this:

function introspectionProvider(query) {
  return fetch(window.location.origin + '/graphql', {
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ query: query }),
  })
  .then((response) => response.json())      
  .catch((err) => {
        console.log(err);
     });
}

from graphql-voyager.

IvanGoncharov avatar IvanGoncharov commented on May 19, 2024

@BuiChiTrung Can you try it on 1.0.0-rc.31?
If it fixed your issue then you have the same exact issue as #259

from graphql-voyager.

BuiChiTrung avatar BuiChiTrung commented on May 19, 2024

@prakhathi-m I have tried this before, I doesn't work :((

from graphql-voyager.

BuiChiTrung avatar BuiChiTrung commented on May 19, 2024

@IvanGoncharov This version doesn't work, too. It doesn't ask me to install @emotion and viz.js module manually, but the same error is raised: "Unexpected token '<'" and the diagram keeps saying "Transmitting".

For now, the following approach work for me:

  • Add the script in the index.html file at the root of my React repo:
<script src="https://cdn.jsdelivr.net/npm/react@16/umd/react.production.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/react-dom@16/umd/react-dom.production.min.js"></script>
  • React component:
const ServiceVisualize: React.FC = () => {
    let {name} = useParams()

    useEffect(() => {
        const script = document.createElement('script');

        script.async = true;
        script.text = "function introspectionProvider(introspectionQuery) {\n" +
            "        // This example expects a GraphQL server at the path /graphql.\n" +
            "        // Change this to point wherever you host your GraphQL server.\n" +
            `        return fetch('http://localhost:8000/${name}/graphql', {\n` +
            "            method: 'post',\n" +
            "            headers: {\n" +
            "                Accept: 'application/json',\n" +
            "                'Content-Type': 'application/json',\n" +
            "            },\n" +
            "            body: JSON.stringify({ query: introspectionQuery }),\n" +
            "            credentials: 'include',\n" +
            "        })\n" +
            "            .then(function (response) {\n" +
            "                return response.text();\n" +
            "            })\n" +
            "            .then(function (responseBody) {\n" +
            "                try {\n" +
            "                    return JSON.parse(responseBody);\n" +
            "                } catch (error) {\n" +
            "                    return responseBody;\n" +
            "                }\n" +
            "            });\n" +
            "    }\n"+
            " GraphQLVoyager.init(document.getElementById('voyager'), {\n" +
            "        introspection: introspectionProvider,\n" +
            "    });"

        document.body.appendChild(script);

        return () => {
            document.body.removeChild(script);
        }
    }, [name]);


    return <div id="voyager" style={{"height": "100vh"}}></div>
}

from graphql-voyager.

BuiChiTrung avatar BuiChiTrung commented on May 19, 2024

@IvanGoncharov sorry for the late response. Version 1.0.1 works. Many thanks!

from graphql-voyager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.