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.

101 lines
2.2 KiB

  1. <template lang='pug'>
  2. v-container(fluid, grid-list-lg)
  3. v-layout(row, wrap)
  4. v-flex(xs12)
  5. .admin-header
  6. img(src='/svg/icon-console.svg', alt='Developer Tools', style='width: 80px;')
  7. .admin-header-title
  8. .headline.primary--text Developer Tools
  9. .subheading.grey--text GraphiQL
  10. v-card.mt-3.white.grey--text.text--darken-3
  11. #graphiql
  12. </template>
  13. <script>
  14. import _ from 'lodash'
  15. import React from 'react'
  16. import ReactDOM from 'react-dom'
  17. import GraphiQL from 'graphiql'
  18. import 'graphiql/graphiql.css'
  19. const fetcher = (qry, respType) => {
  20. return fetch('/graphql', {
  21. method: 'post',
  22. headers: {
  23. 'Accept': 'application/json',
  24. 'Content-Type': 'application/json'
  25. },
  26. body: JSON.stringify(qry),
  27. credentials: 'include'
  28. }).then(response => {
  29. if (respType === 'json') {
  30. return response.json()
  31. } else {
  32. return response.text()
  33. }
  34. }).then(responseBody => {
  35. try {
  36. return JSON.parse(responseBody)
  37. } catch (error) {
  38. return responseBody
  39. }
  40. })
  41. }
  42. export default {
  43. data() {
  44. return { }
  45. },
  46. mounted() {
  47. let graphiQLInstance
  48. ReactDOM.render(
  49. React.createElement(GraphiQL, {
  50. ref(el) { graphiQLInstance = el },
  51. async fetcher(qry) {
  52. let resp = await fetcher(qry, 'text')
  53. _.delay(() => {
  54. graphiQLInstance.resultComponent.viewer.refresh()
  55. }, 500)
  56. return resp
  57. },
  58. response: null,
  59. variables: '{}',
  60. operationName: null,
  61. websocketConnectionParams: null
  62. }),
  63. document.getElementById('graphiql')
  64. )
  65. graphiQLInstance.queryEditorComponent.editor.refresh()
  66. graphiQLInstance.variableEditorComponent.editor.refresh()
  67. graphiQLInstance.state.variableEditorOpen = true
  68. graphiQLInstance.state.docExplorerOpen = true
  69. }
  70. }
  71. </script>
  72. <style lang='scss'>
  73. #graphiql {
  74. height: calc(100vh - 270px);
  75. .topBar {
  76. background-color: mc('grey', '200');
  77. background-image: none;
  78. padding: 1.5rem 0;
  79. > .title {
  80. display: none;
  81. }
  82. }
  83. .toolbar {
  84. background-color: initial;
  85. box-shadow: initial;
  86. }
  87. .doc-explorer-title-bar, .history-title-bar {
  88. height: auto;
  89. }
  90. }
  91. </style>