@@ -148,6 +148,10 @@ function isStoplight(value) {
148148 return value === "product_doc_stoplight_spec" ;
149149}
150150
151+ function isGraphql ( value ) {
152+ return value === "product_doc_graphql_playground" ;
153+ }
154+
151155function isAsyncApi ( value ) {
152156 return value === "product_doc_asyncapi" ;
153157}
@@ -177,14 +181,20 @@ export function HandleApiSpecSelect({
177181 let oasTemplate =
178182 selector ?. options [ selector . selectedIndex ] ?. getAttribute ( "data-template" ) ;
179183 let path = downloadSelector ?. getAttribute ( "data-path" ) ;
180- let [ , ...docURL ] =
184+ let [ apiID , ...docURL ] =
181185 selector && selector . value ? selector . value . split ( "-" ) : [ ] ;
182186 let tmplIsRedoc = isRedoc ( oasTemplate ) ;
183187 let tmplIsAsyncApi = isAsyncApi ( oasTemplate ) ;
184188 let tmplIsStoplight = isStoplight ( oasTemplate ) ;
189+ let tmplIsGraphql = isGraphql ( oasTemplate ) ;
190+
191+
185192 let url = getURLValue ( docURL ) ;
186193
187- if ( selector && isOAS ( url ) ) {
194+ if ( tmplIsGraphql ) {
195+ let serverEndpoint = selector ?. options [ selector . selectedIndex ] ?. getAttribute ( "data-graphqlendpoint" )
196+ initGraphQL ( apiID , serverEndpoint ) ;
197+ } else if ( selector && isOAS ( url ) ) {
188198 if ( tmplIsRedoc ) {
189199 initRedoc ( url ) ;
190200 } else if ( tmplIsAsyncApi ) {
@@ -200,19 +210,22 @@ export function HandleApiSpecSelect({
200210 let tmplIsRedoc = isRedoc ( oasTemplate ) ;
201211 let tmplIsAsyncApi = isAsyncApi ( oasTemplate ) ;
202212 let tmplIsStoplight = isStoplight ( oasTemplate ) ;
213+ let tmplIsGraphql = isGraphql ( oasTemplate ) ;
203214
204215 let [ apiID , ...docURL ] = e . target . value . split ( "-" ) ;
205216 let url = getURLValue ( docURL ) ;
206217 downloadSelector . action = `${ path } /${ apiID } /docs/download` ;
207-
208- if ( ! isOAS ( url ) ) return ;
209-
210- if ( tmplIsRedoc ) {
211- initRedoc ( url ) ;
212- } else if ( tmplIsAsyncApi ) {
213- initAsyncApi ( url ) ;
214- } else if ( tmplIsStoplight ) {
215- initStoplight ( url ) ;
218+ if ( tmplIsGraphql ) {
219+ let serverEndpoint = selector ?. options [ selector . selectedIndex ] ?. getAttribute ( "data-graphqlendpoint" )
220+ initGraphQL ( apiID , serverEndpoint ) ;
221+ } else {
222+ if ( tmplIsRedoc ) {
223+ initRedoc ( url ) ;
224+ } else if ( tmplIsAsyncApi ) {
225+ initAsyncApi ( url ) ;
226+ } else if ( tmplIsStoplight ) {
227+ initStoplight ( url ) ;
228+ }
216229 }
217230 } ) ;
218231}
@@ -241,6 +254,26 @@ function getOrCreateWrapper(apiDocWrapper, wrapperId) {
241254 return wrapper ;
242255}
243256
257+ function initGraphQL ( apiID , _endpointUrl ) {
258+ let apiDocWrapper = document . getElementById ( "api_doc_wrapper" ) ;
259+
260+ hideAllElements ( apiDocWrapper ) ;
261+
262+ let wrapper = getOrCreateWrapper ( apiDocWrapper , "graphql-playground-wrapper" ) ;
263+
264+ // Reuse the same base path used for downloads to build the iframe src
265+ let downloadSelector = document . getElementById ( "display-download-button" ) ;
266+ let path = downloadSelector ?. getAttribute ( "data-path" ) || "" ;
267+
268+ let iframe = document . createElement ( "iframe" ) ;
269+ iframe . setAttribute ( "src" , `${ path } /${ apiID } /docs?embed=1` ) ;
270+ iframe . setAttribute ( "width" , "100%" ) ;
271+ iframe . setAttribute ( "height" , "600" ) ;
272+ iframe . setAttribute ( "frameborder" , "0" ) ;
273+
274+ handleContent ( wrapper , iframe ) ;
275+ }
276+
244277function initRedoc ( url ) {
245278 let apiDocWrapper = document . getElementById ( "api_doc_wrapper" ) ;
246279
@@ -305,6 +338,7 @@ function initAsyncApi(url) {
305338}
306339
307340function initStoplight ( url ) {
341+ console . log ( "initializing spotlight" )
308342 let apiDocWrapper = document . getElementById ( "api_doc_wrapper" ) ;
309343
310344 hideAllElements ( apiDocWrapper ) ;
0 commit comments