admin-dev.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template lang='pug'>
  2. v-card(flat)
  3. v-card(color='grey lighten-5')
  4. .pa-3.pt-4
  5. .headline.primary--text Developer Tools
  6. .subheading.grey--text ¯\_(ツ)_/¯
  7. v-tabs(v-model='selectedTab', color='grey lighten-4', fixed-tabs, slider-color='primary', show-arrows, @input='tabChanged')
  8. v-tab(key='0') Graph API Playground
  9. v-tab(key='1') Graph API Map
  10. v-tabs-items(v-model='selectedTab')
  11. v-tab-item(key='0', :transition='false', :reverse-transition='false')
  12. #graphiql
  13. v-tab-item(key='1', :transition='false', :reverse-transition='false')
  14. #voyager
  15. </template>
  16. <script>
  17. import React from 'react'
  18. import ReactDOM from 'react-dom'
  19. import GraphiQL from 'graphiql'
  20. import { Voyager } from 'graphql-voyager'
  21. import 'graphiql/graphiql.css'
  22. import 'graphql-voyager/dist/voyager.css'
  23. const fetcher = (qry, respType) => {
  24. return fetch('/graphql', {
  25. method: 'post',
  26. headers: {
  27. 'Accept': 'application/json',
  28. 'Content-Type': 'application/json'
  29. },
  30. body: JSON.stringify(qry),
  31. credentials: 'include'
  32. }).then(response => {
  33. if (respType === 'json') {
  34. return response.json()
  35. } else {
  36. return response.text()
  37. }
  38. }).then(responseBody => {
  39. try {
  40. return JSON.parse(responseBody)
  41. } catch (error) {
  42. return responseBody
  43. }
  44. })
  45. }
  46. export default {
  47. data() {
  48. return {
  49. selectedTab: '0'
  50. }
  51. },
  52. mounted() {
  53. this.renderGraphiQL()
  54. },
  55. methods: {
  56. tabChanged (tabId) {
  57. switch (tabId) {
  58. case '1':
  59. this.renderVoyager()
  60. break
  61. }
  62. },
  63. renderGraphiQL() {
  64. ReactDOM.render(
  65. React.createElement(GraphiQL, {
  66. fetcher: qry => fetcher(qry, 'text'),
  67. query: null,
  68. response: null,
  69. variables: null,
  70. operationName: null,
  71. websocketConnectionParams: null
  72. }),
  73. document.getElementById('graphiql')
  74. )
  75. },
  76. renderVoyager() {
  77. ReactDOM.render(
  78. React.createElement(Voyager, {
  79. introspection: qry => fetcher({ query: qry }, 'json'),
  80. workerURI: '/js/voyager.worker.js'
  81. }),
  82. document.getElementById('voyager')
  83. )
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang='scss'>
  89. #graphiql {
  90. height: calc(100vh - 250px);
  91. .topBar {
  92. background-color: mc('grey', '200');
  93. background-image: none;
  94. padding: 1.5rem 0;
  95. > .title {
  96. display: none;
  97. }
  98. }
  99. .toolbar {
  100. background-color: initial;
  101. box-shadow: initial;
  102. }
  103. }
  104. #voyager {
  105. height: calc(100vh - 250px);
  106. }
  107. </style>