Skip to content

Instantly share code, notes, and snippets.

@Grantimus9
Created January 5, 2018 17:16
Show Gist options
  • Save Grantimus9/da14f9e02e41ec5b1436637269e6cb12 to your computer and use it in GitHub Desktop.
Save Grantimus9/da14f9e02e41ec5b1436637269e6cb12 to your computer and use it in GitHub Desktop.
App.Vue with GraphQL querying example.
<template>
<div id="app">
<h1>{{ msg }}</h1>
<h2>The following was loaded over Graphql:</h2>
<h1>User: {{ user.name }}</h1>
</div>
</template>
<script>
import gql from 'graphql-tag'
export default {
name: 'app',
data () {
return {
msg: 'Welcome to Your Vue.js & Phoenix & GraphQL App',
user: "" // Apollo will assign the result of its "user" query here!
}
},
apollo: {
// Apollo specific options
// Here, we use gql to describe the data we want: a user with ID 1, and
// Apollo will assign the result of that query to the 'user' key in data.
user: gql`{
user(id: "1"){
name // we want the name attribute of the user returned.
}
}`,
}
}
</script>
<style lang="scss">
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
h1, h2 {
font-weight: normal;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment