Last active
March 23, 2018 11:05
-
-
Save hipertracker/2272d2bfc9c83c0816c1e9d98f8dfaab to your computer and use it in GitHub Desktop.
Vue + Quasar + Apollo + Nuxt + persistent cache (setup)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // plugins/apollo.js | |
| import { ApolloClient } from 'apollo-client' | |
| import { ApolloLink } from 'apollo-link' | |
| import { HttpLink } from 'apollo-link-http' | |
| import { InMemoryCache } from 'apollo-cache-inmemory' | |
| import VueApollo from 'vue-apollo' | |
| import { persistCache } from 'apollo-cache-persist' | |
| import { withClientState } from 'apollo-link-state' | |
| const cache = new InMemoryCache() | |
| persistCache({ | |
| cache, | |
| storage: window.localStorage, | |
| }) | |
| export default ({ app, Vue }) => { | |
| // Register the VueApollo plugin with Vue. | |
| Vue.use(VueApollo) | |
| const httpLink = new HttpLink({ | |
| uri: `http://localhost:3000/graphql`, | |
| }) | |
| const stateLink = withClientState({ | |
| cache, | |
| resolvers: { | |
| Mutation: { | |
| setLanguage: (_, { language }, { cache }) => { | |
| const data = { language } | |
| cache.writeData({ data }) | |
| return null | |
| }, | |
| }, | |
| }, | |
| defaults: { | |
| language: 'en', | |
| }, | |
| }) | |
| const apolloClient = new ApolloClient({ | |
| cache, | |
| link: ApolloLink.from([stateLink, httpLink]), | |
| connectToDevTools: true, | |
| }) | |
| // let loading = 0 | |
| const apolloProvider = new VueApollo({ | |
| clients: { | |
| a: apolloClient, | |
| }, | |
| defaultClient: apolloClient, | |
| defaultOptions: {}, | |
| // watchLoading(state, mod) { | |
| // loading += mod | |
| // console.log('Global loading', loading, mod) | |
| // }, | |
| // errorHandler(error) { | |
| // console.log('Global error handler') | |
| // console.error(error) | |
| // }, | |
| }) | |
| app.provide = apolloProvider.provide() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template> | |
| <q-select | |
| v-model="select" | |
| radio | |
| color="faded" | |
| stack-label="Language:" | |
| :options="languages" | |
| /> | |
| </template> | |
| <script> | |
| import gql from 'graphql-tag' | |
| const LANGUAGE = gql` | |
| query @client { | |
| language | |
| } | |
| ` | |
| const LANGUAGES = gql` | |
| query Languages { | |
| languages { | |
| value: name | |
| label | |
| } | |
| } | |
| ` | |
| const CHANGE_LANGUAGE = gql` | |
| mutation setLanguage($language: String!) { | |
| setLanguage(language: $language) @client | |
| } | |
| ` | |
| export default { | |
| name: 'Language', | |
| data() { | |
| return { | |
| language: '', | |
| languages: [], | |
| } | |
| }, | |
| computed: { | |
| select: { | |
| get() { | |
| return this.language | |
| }, | |
| set(val) { | |
| this.$apollo.mutate({ | |
| mutation: CHANGE_LANGUAGE, | |
| variables: { language: val }, | |
| }) | |
| }, | |
| }, | |
| }, | |
| apollo: { | |
| language: { | |
| query: LANGUAGE, | |
| }, | |
| languages: { | |
| query: LANGUAGES, | |
| options: { | |
| fetchPolicy: 'cache-and-network', | |
| }, | |
| }, | |
| }, | |
| } | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = function(ctx) { | |
| return { | |
| // app plugins (/src/plugins) | |
| plugins: ['i18n', 'axios', 'apollo', 'vuelidate'], | |
| css: ['app.styl'], | |
| extras: [ | |
| ctx.theme.mat ? 'roboto-font' : null, | |
| 'material-icons', | |
| // 'ionicons', | |
| // 'mdi', | |
| // 'fontawesome' | |
| ], | |
| supportIE: false, | |
| vendor: { | |
| add: [], | |
| remove: [], | |
| }, | |
| build: { | |
| scopeHoisting: true, | |
| vueRouterMode: 'history', | |
| // gzip: true, | |
| // analyze: true, | |
| // extractCSS: false, | |
| // useNotifier: false, | |
| extendWebpack(cfg) { | |
| cfg.module.rules.push({ | |
| enforce: 'pre', | |
| test: /\.(js|vue)$/, | |
| loader: 'eslint-loader', | |
| exclude: /(node_modules|quasar)/, | |
| }) | |
| }, | |
| }, | |
| devServer: { | |
| // https: true, | |
| // port: 8080, | |
| proxy: { | |
| '/api': { | |
| // target: 'https://api.mybible.pl/graphql', | |
| target: 'http://localhost:3000/graphql', | |
| changeOrigin: true, | |
| pathRewrite: { | |
| '^/api': '', | |
| }, | |
| // logLevel: 'debug', | |
| // secure: false, | |
| // headers: { | |
| // Origin: 'https://api.mybible.pl' | |
| // }, | |
| }, | |
| }, | |
| open: false, // opens browser window automatically | |
| }, | |
| // framework: 'all' --- includes everything; for dev only! | |
| framework: { | |
| components: [ | |
| 'QCard', | |
| 'QCardSeparator', | |
| 'QCardTitle', | |
| 'QCheckbox', | |
| 'QCollapsible', | |
| 'QField', | |
| 'QInput', | |
| 'QItem', | |
| 'QLayout', | |
| 'QList', | |
| 'QLayoutHeader', | |
| 'QLayoutDrawer', | |
| 'QModal', | |
| 'QModalLayout', | |
| 'QOptionGroup', | |
| 'QPageContainer', | |
| 'QPage', | |
| 'QPageSticky', | |
| 'QPopover', | |
| 'QSelect', | |
| 'QToolbar', | |
| 'QToolbarTitle', | |
| 'QBtn', | |
| 'QIcon', | |
| 'QList', | |
| 'QListHeader', | |
| 'QItem', | |
| 'QItemMain', | |
| 'QItemSide', | |
| ], | |
| directives: ['Ripple'], | |
| // Quasar plugins | |
| plugins: ['Notify'], | |
| }, | |
| // animations: 'all' --- includes all animations | |
| animations: 'all', | |
| pwa: { | |
| cacheExt: | |
| 'js,html,css,ttf,eot,otf,woff,woff2,json,svg,gif,jpg,jpeg,png,wav,ogg,webm,flac,aac,mp4,mp3', | |
| manifest: { | |
| // name: 'Quasar App', | |
| // short_name: 'Quasar-PWA', | |
| // description: 'Best PWA App in town!', | |
| display: 'standalone', | |
| orientation: 'portrait', | |
| background_color: '#ffffff', | |
| theme_color: '#027be3', | |
| icons: [ | |
| { | |
| src: 'statics/icons/icon-128x128.png', | |
| sizes: '128x128', | |
| type: 'image/png', | |
| }, | |
| { | |
| src: 'statics/icons/icon-192x192.png', | |
| sizes: '192x192', | |
| type: 'image/png', | |
| }, | |
| { | |
| src: 'statics/icons/icon-256x256.png', | |
| sizes: '256x256', | |
| type: 'image/png', | |
| }, | |
| { | |
| src: 'statics/icons/icon-384x384.png', | |
| sizes: '384x384', | |
| type: 'image/png', | |
| }, | |
| { | |
| src: 'statics/icons/icon-512x512.png', | |
| sizes: '512x512', | |
| type: 'image/png', | |
| }, | |
| ], | |
| }, | |
| }, | |
| cordova: { | |
| // id: 'org.cordova.quasar.app' | |
| }, | |
| electron: { | |
| extendWebpack(cfg) { | |
| // do something with cfg | |
| }, | |
| packager: { | |
| // OS X / Mac App Store | |
| // appBundleId: '', | |
| // appCategoryType: '', | |
| // osxSign: '', | |
| // protocol: 'myapp://path', | |
| // Window only | |
| // win32metadata: { ... } | |
| }, | |
| }, | |
| // leave this here for Quasar CLI | |
| starterKit: '1.0.0', | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment