2018-03-05 20:49:36 +00:00
|
|
|
<template lang='pug'>
|
2018-09-30 03:30:20 +00:00
|
|
|
v-container(fluid, grid-list-lg)
|
|
|
|
v-layout(row, wrap)
|
|
|
|
v-flex(xs12)
|
|
|
|
.admin-header
|
2018-12-15 22:15:13 +00:00
|
|
|
img(src='/svg/icon-console.svg', alt='Developer Tools', style='width: 80px;')
|
2018-09-30 03:30:20 +00:00
|
|
|
.admin-header-title
|
|
|
|
.headline.primary--text Developer Tools
|
|
|
|
.subheading.grey--text ¯\_(ツ)_/¯
|
2018-03-18 02:41:16 +00:00
|
|
|
|
2018-09-30 03:30:20 +00:00
|
|
|
v-card.mt-3
|
|
|
|
v-tabs(
|
|
|
|
v-model='selectedTab'
|
|
|
|
color='grey darken-2'
|
|
|
|
fixed-tabs
|
|
|
|
slider-color='white'
|
|
|
|
show-arrows
|
|
|
|
dark
|
2019-01-01 06:40:31 +00:00
|
|
|
@change='tabChanged'
|
2018-09-30 03:30:20 +00:00
|
|
|
)
|
|
|
|
v-tab(key='0') Graph API Playground
|
|
|
|
v-tab(key='1') Graph API Map
|
|
|
|
v-tabs-items(v-model='selectedTab')
|
|
|
|
v-tab-item(key='0', :transition='false', :reverse-transition='false')
|
|
|
|
#graphiql
|
|
|
|
|
|
|
|
v-tab-item(key='1', :transition='false', :reverse-transition='false')
|
|
|
|
#voyager
|
2018-03-18 02:41:16 +00:00
|
|
|
|
2018-03-05 20:49:36 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-03-20 04:37:55 +00:00
|
|
|
import _ from 'lodash'
|
2018-03-17 01:31:28 +00:00
|
|
|
import React from 'react'
|
|
|
|
import ReactDOM from 'react-dom'
|
|
|
|
import GraphiQL from 'graphiql'
|
2018-03-18 02:41:16 +00:00
|
|
|
import { Voyager } from 'graphql-voyager'
|
|
|
|
import 'graphiql/graphiql.css'
|
|
|
|
import 'graphql-voyager/dist/voyager.css'
|
|
|
|
|
|
|
|
const fetcher = (qry, respType) => {
|
|
|
|
return fetch('/graphql', {
|
|
|
|
method: 'post',
|
|
|
|
headers: {
|
|
|
|
'Accept': 'application/json',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
body: JSON.stringify(qry),
|
|
|
|
credentials: 'include'
|
|
|
|
}).then(response => {
|
|
|
|
if (respType === 'json') {
|
|
|
|
return response.json()
|
|
|
|
} else {
|
|
|
|
return response.text()
|
|
|
|
}
|
|
|
|
}).then(responseBody => {
|
|
|
|
try {
|
|
|
|
return JSON.parse(responseBody)
|
|
|
|
} catch (error) {
|
|
|
|
return responseBody
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-03-17 01:31:28 +00:00
|
|
|
|
2018-03-20 04:37:55 +00:00
|
|
|
let graphiQLInstance
|
|
|
|
|
2018-03-05 20:49:36 +00:00
|
|
|
export default {
|
|
|
|
data() {
|
2018-03-18 02:41:16 +00:00
|
|
|
return {
|
2019-01-01 06:40:31 +00:00
|
|
|
selectedTab: 0
|
2018-03-18 02:41:16 +00:00
|
|
|
}
|
2018-03-17 01:31:28 +00:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.renderGraphiQL()
|
|
|
|
},
|
|
|
|
methods: {
|
2018-03-18 02:41:16 +00:00
|
|
|
tabChanged (tabId) {
|
|
|
|
switch (tabId) {
|
2019-01-01 06:40:31 +00:00
|
|
|
case 1:
|
2018-03-18 02:41:16 +00:00
|
|
|
this.renderVoyager()
|
|
|
|
break
|
|
|
|
}
|
|
|
|
},
|
2018-03-17 01:31:28 +00:00
|
|
|
renderGraphiQL() {
|
|
|
|
ReactDOM.render(
|
|
|
|
React.createElement(GraphiQL, {
|
2018-03-20 04:37:55 +00:00
|
|
|
ref(el) { graphiQLInstance = el },
|
|
|
|
async fetcher(qry) {
|
|
|
|
let resp = await fetcher(qry, 'text')
|
|
|
|
_.delay(() => {
|
|
|
|
graphiQLInstance.resultComponent.viewer.refresh()
|
|
|
|
}, 500)
|
|
|
|
return resp
|
|
|
|
},
|
|
|
|
query: '',
|
2018-03-17 01:31:28 +00:00
|
|
|
response: null,
|
|
|
|
variables: null,
|
|
|
|
operationName: null,
|
|
|
|
websocketConnectionParams: null
|
|
|
|
}),
|
|
|
|
document.getElementById('graphiql')
|
|
|
|
)
|
2018-03-20 04:37:55 +00:00
|
|
|
graphiQLInstance.queryEditorComponent.editor.refresh()
|
|
|
|
graphiQLInstance.variableEditorComponent.editor.refresh()
|
|
|
|
graphiQLInstance.state.variableEditorOpen = true
|
2018-03-18 02:41:16 +00:00
|
|
|
},
|
|
|
|
renderVoyager() {
|
|
|
|
ReactDOM.render(
|
|
|
|
React.createElement(Voyager, {
|
|
|
|
introspection: qry => fetcher({ query: qry }, 'json'),
|
|
|
|
workerURI: '/js/voyager.worker.js'
|
|
|
|
}),
|
|
|
|
document.getElementById('voyager')
|
|
|
|
)
|
2018-03-17 01:31:28 +00:00
|
|
|
}
|
2018-03-05 20:49:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang='scss'>
|
|
|
|
|
2018-03-17 01:31:28 +00:00
|
|
|
#graphiql {
|
2018-03-20 04:37:55 +00:00
|
|
|
height: calc(100vh - 230px);
|
2018-03-17 01:31:28 +00:00
|
|
|
|
|
|
|
.topBar {
|
|
|
|
background-color: mc('grey', '200');
|
|
|
|
background-image: none;
|
|
|
|
padding: 1.5rem 0;
|
|
|
|
|
|
|
|
> .title {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.toolbar {
|
|
|
|
background-color: initial;
|
|
|
|
box-shadow: initial;
|
|
|
|
}
|
2018-03-18 02:41:16 +00:00
|
|
|
}
|
2018-03-17 01:31:28 +00:00
|
|
|
|
2018-03-18 02:41:16 +00:00
|
|
|
#voyager {
|
|
|
|
height: calc(100vh - 250px);
|
2018-03-19 03:12:56 +00:00
|
|
|
|
|
|
|
.title-area {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
.type-doc {
|
|
|
|
margin-top: 5px;
|
|
|
|
}
|
2018-03-17 01:31:28 +00:00
|
|
|
}
|
2018-03-05 20:49:36 +00:00
|
|
|
</style>
|