VueJS + ApolloServer + ApolloClient

#1

Hi there,

I’m lost, I need your help.

I’m new with Javascript, Vue, Apollo, client/server so please, talk to me with simple words haha :slight_smile:

I created an instance of VueJS thanks to vue-cli 3 (vue create…)

After that, I created a server.js file with apollo-server

const { ApolloServer } = require('apollo-server')

const server = new ApolloServer({
  modules: [
    require('./src/modules/product'),
    require('./src/modules/category')
  ]
})

server.listen().then(({url}) => console.log(`server started at ${url}`))

I have a folder src, and in this folder I have a main.js file where I have ApolloClient linked to my ApolloServer

import Vue from 'vue'

import App from './App.vue'
import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import VueApollo from 'vue-apollo'

const httpLink = new HttpLink({
   uri: 'http://localhost:4000' //my apolloserver
})

// Cache implementation
const cache = new InMemoryCache()

// Create the apollo client
const apolloClient = new ApolloClient({
   link: httpLink,
   cache,
   connectToDevTools: true
})

const apolloProvider = new VueApollo({
   defaultClient: apolloClient
})

Vue.use(VueApollo)
Vue.config.productionTip = false

new Vue({
   apolloProvider,
   render: h => h(App)
}).$mount('#app')

Now, I would like to know, why on this tutorial: https://github.com/Akryum/apollo-server-example/blob/master/index.js

They use express.js for builiding an apollo-server ?

What is the difference between express and apollo-server ?

The way I did is correct? Or I’m completly wrong ?