Skip to content

Instantly share code, notes, and snippets.

Avatar
🌍
Earth good hmm

Amenallah Hsoumi LazyFatArrow

🌍
Earth good hmm
View GitHub Profile
View router.js
import Vue from 'vue'
import Router from 'vue-router'
import Polls from './views/Polls.vue'
Vue.use(Router)
export default new Router({
mode: 'history',
base: process.env.BASE_URL,
View poll.queries.js
import gql from 'graphql-tag'
export const POLLS = gql`
query Polls {
polls {
id
title
description
options {
id
View main.js
import Vue from 'vue'
import BootstrapVue from 'bootstrap-vue'
import App from './App.vue'
import router from './router'
import { createProvider } from './vue-apollo'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
View Subscription.graphql
type Subscription {
pollCreated: Poll
optionVoted: Option
}
View poll.resolvers.js
// ... imports
export default {
// ... queries
mutations: {
// ... createPoll
async voteOnPoll(parent, args) {
const poll = await pollService.voteOnPoll(args.optionId).catch();
View poll.resolvers.js
// ... imports
export default {
// ... queries
mutations: {
async createPoll(parent, args) {
const poll = await pollService.create(args.poll).catch();
pubsub.publish(POLL_CREATED, {
View events.js
export const POLL_CREATED = 'pollCreated'
View poll.resolvers.js
import { PubSub } from 'apollo-server'
import { POLL_CREATED } from '../events';
import * as pollService from '../services/poll.service'
const pubsub = new PubSub()
export default {
// ... queries and mutations
subscriptions: {
View poll.service.js
import Poll from '../models/poll.model'
export function create(data) {
return Poll.create(data)
}
export function findAll() {
return Poll.find().sort({ createdAt: -1 })
}
You can’t perform that action at this time.