소스 검색

add graphql deps and minimal example

axolotle 3 년 전
부모
커밋
af608b9487
6개의 변경된 파일58개의 추가작업 그리고 4개의 파일을 삭제
  1. 2 0
      package.json
  2. 9 0
      src/api/index.js
  3. 5 0
      src/api/queries/TextRef.gql
  4. 14 2
      src/pages/Home.vue
  5. 18 2
      src/store/index.js
  6. 10 0
      vue.config.js

+ 2 - 0
package.json

@@ -35,6 +35,8 @@
     "eslint-plugin-standard": "^4.0.0",
     "eslint-plugin-vue": "^6.2.2",
     "eslint-plugin-vue-a11y": "0.0.31",
+    "graphql": "^15.5.0",
+    "graphql-tag": "^2.9.0",
     "node-sass": "^4.12.0",
     "sass-loader": "^8.0.2",
     "vue-template-compiler": "^2.6.11"

+ 9 - 0
src/api/index.js

@@ -0,0 +1,9 @@
+import axios from 'axios'
+
+export default axios.create({
+  baseURL: window.location.origin + '/api/gql',
+  headers: {
+    Accept: 'application/json',
+    'Content-Type': 'application/json'
+  }
+})

+ 5 - 0
src/api/queries/TextRef.gql

@@ -0,0 +1,5 @@
+query TextRef ($id: Int!) {
+  textref (id: $id) {
+    title
+  }
+}

+ 14 - 2
src/pages/Home.vue

@@ -1,11 +1,23 @@
 <template>
   <div class="home">
-    Home
+    {{ text }}
   </div>
 </template>
 
 <script>
 export default {
-  name: 'Home'
+  name: 'Home',
+
+  data () {
+    return {
+      text: null
+    }
+  },
+
+  created () {
+    this.$store.dispatch('GET_TEXT', 1).then(({ data }) => {
+      this.text = data.data.textref
+    })
+  }
 }
 </script>

+ 18 - 2
src/store/index.js

@@ -1,11 +1,27 @@
 import Vue from 'vue'
 import Vuex from 'vuex'
 
-// import Corpus from './modules/corpus'
+import api from '@/api'
+import { print } from 'graphql/language/printer'
+import TextRef from '@/api/queries/TextRef.gql'
+
 
 Vue.use(Vuex)
+
+
 export default new Vuex.Store({
   modules: {
-    // Corpus
+  },
+
+  state: {
+  },
+
+  mutations: {
+  },
+
+  actions: {
+    'GET_TEXT' ({ state }, id) {
+      return api.post('', { query: print(TextRef), variables: { id } })
+    }
   }
 })

+ 10 - 0
vue.config.js

@@ -1,4 +1,14 @@
 module.exports = {
+  chainWebpack: config => {
+    // GraphQL Loader
+    config.module
+      .rule('graphql')
+      .test(/\.gql$/)
+      .use('graphql-tag/loader')
+      .loader('graphql-tag/loader')
+      .end()
+  },
+
   publicPath: '/',
   devServer: {
     clientLogLevel: 'warning',