Skip to content

Instantly share code, notes, and snippets.

View SurbhiKatariya's full-sized avatar

SurbhiKatariya

View GitHub Profile
@SurbhiKatariya
SurbhiKatariya / Users.vue
Last active April 9, 2020 08:12
Fetch users list from mock API using vue-apollo
<template lang="pug">
.container
div(v-if="isLoading") Loading......
.user-table(v-if="!isLoading")
.table-row.table-header
div User Id
div User Name
div User Email
.table-row.table-data(:key="index" v-for="(user, index) in userList")
div {{user.id}}
@SurbhiKatariya
SurbhiKatariya / main.js
Created April 4, 2020 13:49
Import files
import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { ApolloLink } from 'apollo-link'
import VueApollo from 'vue-apollo'
Vue.use(VueApollo)
@SurbhiKatariya
SurbhiKatariya / main.js
Last active April 9, 2020 08:07
Create custom link
const httpLink = new HttpLink({
uri: 'https://api.graph.cool/simple/v1/ciyz901en4j590185wkmexyex'
})
// set authorization header to authenticate the request using apollo link, it is optional.
/*
const authMiddleware = new ApolloLink((operation, forward) => {
const token = 'cllHNFlaZkpXbg64Qzh0Z3VJT2FOdz09'
operation.setContext({
headers: {
@SurbhiKatariya
SurbhiKatariya / main.js
Last active April 4, 2020 14:19
Add apolloProvider in vue instance
// Create the apollo client
const apolloClient = new ApolloClient({
link,
cache: new InMemoryCache(),
connectToDevTools: true
})
const apolloProvider = new VueApollo({
defaultClient: apolloClient
})
@SurbhiKatariya
SurbhiKatariya / Users.vue
Last active April 4, 2020 16:00
Make graphql query
<script>
import gql from 'graphql-tag'
const GET_USER_DETAILS = gql`
query getUsers($character: String!) {
allUsers(orderBy: name_ASC, filter: {email_contains: $character}) {
id,
name,
email
}
@SurbhiKatariya
SurbhiKatariya / Users.vue
Last active April 4, 2020 15:58
Fetch data with query
<script>
export default {
data () {
return {
userList: [],
isLoading: false
}
},
created () {
const vm = this
@SurbhiKatariya
SurbhiKatariya / Users.vue
Created April 4, 2020 15:57
Template code
<template lang="pug">
.container
div(v-if="isLoading") Loading......
.user-table(v-if="!isLoading")
.table-row.table-header
div User Id
div User Name
div User Email
.table-row.table-data(:key="index" v-for="(user, index) in userList")
div {{user.id}}