Skip to content

Instantly share code, notes, and snippets.

@malgamves
Created October 17, 2018 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malgamves/3069fd512f93e5503d33f898117b3191 to your computer and use it in GitHub Desktop.
Save malgamves/3069fd512f93e5503d33f898117b3191 to your computer and use it in GitHub Desktop.
Files to add a GraphQL to a Vue App
<template>
<div>{{book.name}} by {{book.author}}</div>
</template>
<script>
export default {
name: 'BookItem',
props: ['book']
}
</script>
<template>
<div>
<!-- 1 -->
<h4 v-if="loading">Loading...</h4>
<book-item
v-for="book in books"
:key="book.id"
:book="book">
</book-item>
</div>
</template>
<script>
// 2
import { ALL_BOOKS_QUERY } from '../constants/graphql'
import BookItem from './BookItem'
export default {
name: 'BookList',
data () {
return {
// 3
books: [],
loading: 0
}
},
components: {
BookItem
},
// 4
apollo: {
books: {
query: ALL_BOOKS_QUERY
}
}
}
</script>
// 1
import gql from 'graphql-tag'
// 2
export const ALL_BOOKS_QUERY = gql`
query books {
books {
id
author
name
}
}
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment