|
107 | 107 | }
|
108 | 108 | }
|
109 | 109 | </style>
|
| 110 | + <link rel="stylesheet" href="./voyager.css" /> |
| 111 | + <script src="./voyager.standalone.js"></script> |
110 | 112 | </head>
|
111 | 113 | <body>
|
| 114 | + <script type="module"> |
| 115 | + // FIXME: switch to import |
| 116 | + const { renderVoyager, voyagerIntrospectionQuery } = GraphQLVoyager; |
| 117 | + const PRESETS = { |
| 118 | + 'Star Wars': await fetchPreset('swapi'), |
| 119 | + Yelp: await fetchPreset('yelp'), |
| 120 | + 'Shopify Storefront': await fetchPreset('shopify'), |
| 121 | + GitHub: await fetchPreset('github'), |
| 122 | + }; |
| 123 | + |
| 124 | + const defaultPreset = PRESETS['Star Wars']; |
| 125 | + |
| 126 | + const currentUrl = new URL(window.location.href); |
| 127 | + const url = currentUrl.searchParams.get('url'); |
| 128 | + const withCredentials = currentUrl.searchParams.get('withCredentials'); |
| 129 | + |
| 130 | + const introspection = |
| 131 | + url != null ? fetchIntrospection(url, withCredentials) : defaultPreset; |
| 132 | + |
| 133 | + renderVoyager(document.getElementById('root'), { |
| 134 | + introspection, |
| 135 | + introspectionPresets: PRESETS, |
| 136 | + allowToChangeSchema: true, |
| 137 | + hideVoyagerLogo: false, |
| 138 | + }); |
| 139 | + |
| 140 | + async function fetchPreset(name) { |
| 141 | + const response = await fetch(`./presets/${name}_introspection.json`); |
| 142 | + return response.json(); |
| 143 | + } |
| 144 | + |
| 145 | + async function fetchIntrospection(url, withCredentials) { |
| 146 | + const response = await fetch(url, { |
| 147 | + method: 'post', |
| 148 | + headers: { |
| 149 | + Accept: 'application/json', |
| 150 | + 'Content-Type': 'application/json', |
| 151 | + }, |
| 152 | + body: JSON.stringify({ query: voyagerIntrospectionQuery }), |
| 153 | + ...(withCredentials === 'true' |
| 154 | + ? { credentials: 'include', mode: 'cors' } |
| 155 | + : {}), |
| 156 | + }); |
| 157 | + return response.json(); |
| 158 | + } |
| 159 | + </script> |
112 | 160 | <main id="root">
|
113 | 161 | <h1 style="text-align: center; color: #5d7e86">Loading...</h1>
|
114 | 162 | </main>
|
|
0 commit comments