You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
3.1 KiB

  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 _ from 'lodash'
  18. import React from 'react'
  19. import ReactDOM from 'react-dom'
  20. import GraphiQL from 'graphiql'
  21. import { Voyager } from 'graphql-voyager'
  22. import 'graphiql/graphiql.css'
  23. import 'graphql-voyager/dist/voyager.css'
  24. const fetcher = (qry, respType) => {
  25. return fetch('/graphql', {
  26. method: 'post',
  27. headers: {
  28. 'Accept': 'application/json',
  29. 'Content-Type': 'application/json'
  30. },
  31. body: JSON.stringify(qry),
  32. credentials: 'include'
  33. }).then(response => {
  34. if (respType === 'json') {
  35. return response.json()
  36. } else {
  37. return response.text()
  38. }
  39. }).then(responseBody => {
  40. try {
  41. return JSON.parse(responseBody)
  42. } catch (error) {
  43. return responseBody
  44. }
  45. })
  46. }
  47. let graphiQLInstance
  48. export default {
  49. data() {
  50. return {
  51. selectedTab: '0'
  52. }
  53. },
  54. mounted() {
  55. this.renderGraphiQL()
  56. },
  57. methods: {
  58. tabChanged (tabId) {
  59. switch (tabId) {
  60. case '1':
  61. this.renderVoyager()
  62. break
  63. }
  64. },
  65. renderGraphiQL() {
  66. ReactDOM.render(
  67. React.createElement(GraphiQL, {
  68. ref(el) { graphiQLInstance = el },
  69. async fetcher(qry) {
  70. let resp = await fetcher(qry, 'text')
  71. _.delay(() => {
  72. graphiQLInstance.resultComponent.viewer.refresh()
  73. }, 500)
  74. return resp
  75. },
  76. query: '',
  77. response: null,
  78. variables: null,
  79. operationName: null,
  80. websocketConnectionParams: null
  81. }),
  82. document.getElementById('graphiql')
  83. )
  84. graphiQLInstance.queryEditorComponent.editor.refresh()
  85. graphiQLInstance.variableEditorComponent.editor.refresh()
  86. graphiQLInstance.state.variableEditorOpen = true
  87. },
  88. renderVoyager() {
  89. ReactDOM.render(
  90. React.createElement(Voyager, {
  91. introspection: qry => fetcher({ query: qry }, 'json'),
  92. workerURI: '/js/voyager.worker.js'
  93. }),
  94. document.getElementById('voyager')
  95. )
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang='scss'>
  101. #graphiql {
  102. height: calc(100vh - 230px);
  103. .topBar {
  104. background-color: mc('grey', '200');
  105. background-image: none;
  106. padding: 1.5rem 0;
  107. > .title {
  108. display: none;
  109. }
  110. }
  111. .toolbar {
  112. background-color: initial;
  113. box-shadow: initial;
  114. }
  115. }
  116. #voyager {
  117. height: calc(100vh - 250px);
  118. .title-area {
  119. display: none;
  120. }
  121. .type-doc {
  122. margin-top: 5px;
  123. }
  124. }
  125. </style>