admin-dev.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template lang='pug'>
  2. v-container(fluid, grid-list-lg)
  3. v-layout(row, wrap)
  4. v-flex(xs12)
  5. .admin-header
  6. v-icon(size='80', color='grey lighten-2') weekend
  7. .admin-header-title
  8. .headline.primary--text Developer Tools
  9. .subheading.grey--text ¯\_(ツ)_/¯
  10. v-card.mt-3
  11. v-tabs(
  12. v-model='selectedTab'
  13. color='grey darken-2'
  14. fixed-tabs
  15. slider-color='white'
  16. show-arrows
  17. dark
  18. @input='tabChanged'
  19. )
  20. v-tab(key='0') Graph API Playground
  21. v-tab(key='1') Graph API Map
  22. v-tabs-items(v-model='selectedTab')
  23. v-tab-item(key='0', :transition='false', :reverse-transition='false')
  24. #graphiql
  25. v-tab-item(key='1', :transition='false', :reverse-transition='false')
  26. #voyager
  27. </template>
  28. <script>
  29. import _ from 'lodash'
  30. import React from 'react'
  31. import ReactDOM from 'react-dom'
  32. import GraphiQL from 'graphiql'
  33. import { Voyager } from 'graphql-voyager'
  34. import 'graphiql/graphiql.css'
  35. import 'graphql-voyager/dist/voyager.css'
  36. const fetcher = (qry, respType) => {
  37. return fetch('/graphql', {
  38. method: 'post',
  39. headers: {
  40. 'Accept': 'application/json',
  41. 'Content-Type': 'application/json'
  42. },
  43. body: JSON.stringify(qry),
  44. credentials: 'include'
  45. }).then(response => {
  46. if (respType === 'json') {
  47. return response.json()
  48. } else {
  49. return response.text()
  50. }
  51. }).then(responseBody => {
  52. try {
  53. return JSON.parse(responseBody)
  54. } catch (error) {
  55. return responseBody
  56. }
  57. })
  58. }
  59. let graphiQLInstance
  60. export default {
  61. data() {
  62. return {
  63. selectedTab: '0'
  64. }
  65. },
  66. mounted() {
  67. this.renderGraphiQL()
  68. },
  69. methods: {
  70. tabChanged (tabId) {
  71. switch (tabId) {
  72. case '1':
  73. this.renderVoyager()
  74. break
  75. }
  76. },
  77. renderGraphiQL() {
  78. ReactDOM.render(
  79. React.createElement(GraphiQL, {
  80. ref(el) { graphiQLInstance = el },
  81. async fetcher(qry) {
  82. let resp = await fetcher(qry, 'text')
  83. _.delay(() => {
  84. graphiQLInstance.resultComponent.viewer.refresh()
  85. }, 500)
  86. return resp
  87. },
  88. query: '',
  89. response: null,
  90. variables: null,
  91. operationName: null,
  92. websocketConnectionParams: null
  93. }),
  94. document.getElementById('graphiql')
  95. )
  96. graphiQLInstance.queryEditorComponent.editor.refresh()
  97. graphiQLInstance.variableEditorComponent.editor.refresh()
  98. graphiQLInstance.state.variableEditorOpen = true
  99. },
  100. renderVoyager() {
  101. ReactDOM.render(
  102. React.createElement(Voyager, {
  103. introspection: qry => fetcher({ query: qry }, 'json'),
  104. workerURI: '/js/voyager.worker.js'
  105. }),
  106. document.getElementById('voyager')
  107. )
  108. }
  109. }
  110. }
  111. </script>
  112. <style lang='scss'>
  113. #graphiql {
  114. height: calc(100vh - 230px);
  115. .topBar {
  116. background-color: mc('grey', '200');
  117. background-image: none;
  118. padding: 1.5rem 0;
  119. > .title {
  120. display: none;
  121. }
  122. }
  123. .toolbar {
  124. background-color: initial;
  125. box-shadow: initial;
  126. }
  127. }
  128. #voyager {
  129. height: calc(100vh - 250px);
  130. .title-area {
  131. display: none;
  132. }
  133. .type-doc {
  134. margin-top: 5px;
  135. }
  136. }
  137. </style>