SlideShare a Scribd company logo
How to Build
CRUD
Application
using VueJS,
GraphQL, and
Hasura


https://www.bacancytechnology.com/
Introduction
In this tutorial, we will learn how to build
CRUD application using VueJS, GraphQL, and
Hasura. Don’t be scared of the technical stack;
just stick till the end of the blog, and you’ll be
able to build your basic CRUD app.


Many developers consider GraphQL as a DB
technology, but that’s not true!


GraphQL is a query language – an alternative
to build REST APIs. GraphQL provides an
interface to put-away information that meets
the application’s requirements.


Facebook developed it as an internal
technology for enhancing the app’s versatility
and later released it as open-source. Since then,
the software development community has
utilized it as one of the favorite technology
stacks for developing web services.
Tutorial Goal:
Build CRUD
Application
using VueJS,
GraphQL, and
Hasura
Before moving towards building a basic CRUD
app, watch the below video to understand what
we are building.


Prerequisites


Basic knowledge of VueJS and GraphQL
VS Code or any other IDE
Familiarity with Javascript and HTML
https://youtu.be/GvA7N1uB86g
Below is the Video link
Prerequisites
Basic knowledge of VueJS and GraphQL
VS Code or any other IDE
Familiarity with Javascript and HTML
Database
Set-Up using
Hasura
Firstly you need to sign up to Hasura cloud.
Visit hasura.io to do the same.


Hasura instantly lets your apps query, update,
and receive real-time notifications of your
data with GraphQL. After successful signup,
you have to connect your database. Either you
can use any existing database or create from
Heroku it’s for free.
Once done with creating or connecting your
database, let’s move to the code section.


Build well-performing and cost-effective
VueJS applications with Bacancy.
We have proficient developers with the best
technical insights and problem-solving
skills. Hire VueJS developer from us and
start building applications of your choice!
Initial Set-Up
and
Installation
You can create a new VueJS application or
use an existing application.


Here I am using a fresh vue application by
setting up using vue-cli. So here is the
command to create the application.
vue create vue-graphql-demo
Run the below command to install all
the dependencies.


npm install vue-apollo@3.0.0-beta.28
apollo-cache-inmemory apollo-link-
http apollo-client graphql-tag
graphql --save
Then create one file named apollo.js under
the src/ and register all the packages below.


// apollo.js
import Vue from 'vue'
import VueApollo from 'vue-apollo'
import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-
inmemory'
const httpLink = new HttpLink({
// You should use an absolute URL here
uri: 'https://your-
app.hasura.app/v1/graphql',
headers: {
"x-hasura-admin-secret": "token"
}
})
// Create the apollo client
export const apolloClient = new
ApolloClient({
link: httpLink,
cache: new InMemoryCache(),
connectToDevTools: true
})
const apolloProvider = new VueApollo({
defaultClient: apolloClient
})
// Install the vue plugin
Vue.use(VueApollo)
export default apolloProvider
Get your URL and x-hasura-admin-secret from
the GraphQL/API tab, as shown below.


Now it’s time to update your main.js file.
Import this apollo.js to the main.js.


// main.js
import Vue from 'vue'
import App from './App.vue'
import apolloProvider from './apollo'
Vue.config.productionTip = false
new Vue({
apolloProvider,
render: h => h(App)
}).$mount('#app')
So here we are, done with the initial setup.
Now, it’s time to make a query to get the data,
update it, and delete it.


Here I have created the users table. Create a
component for users, and let’s add the query
for getting the users data.
Implement
CRUD
Operation
Use the following code snippets to
implement the CRUD operations in your
application.


CREATE


const name = this.name;
const email = this.email;
this.$apollo.mutate({
mutation: gql`
mutation addUser($name: String!, $email:
String!) {
insert_users(objects: [{ name: $name,
email: $email }]) {
returning {
user_id
}
}
}
`,
var
variables: {
name,
Email,
},
refetchQueries: ["getUsers"],
});
Same as we have inserted the data, we need to
update a particular user’s data and delete it too.


READ
apollo: {
userList: {
query: gql`
query getUsers {
users {
user_id
name
email
}
}
`,
update: (data) => {
return data.users;
},
},
},
In the userList variable, you will get an
object of users, so let’s add it into the table
element. Now, it’s time to add users, so
make one form and add two fields, name
and email.
UPDATE
const name = this.editUser.name;
const email = this.editUser.email;
const user_id = this.editUser.user_id;
this.$apollo.mutate({
mutation: gql`
mutation updateUsers($user_id: Int,
$name: String!, $email: String!) {
update_users(
where: { user_id: { _eq: $user_id } }
_set: { email: $email, name: $name }
) {
returning {
user_id
}
}
}
`,
variables: {
user_id,
name,
email,
},
refetchQueries: ["getUsers"],
});
DELETE
let user_id = id;
this.$apollo.mutate({
mutation: gql`
mutation deleteUser($user_id: Int) {
delete_users(where:
{ user_id: { _eq: $user_id } }) {
returning {
user_id
}
}
}
`,
variables: {
user_id,
},
refetchQueries: ["getUsers"],
});
Github Repository:
Build CRUD
Application using
VueJS, GraphQL,
and Hasura
Here’s the source code for building the
CRUD app with Vue, GraphQL, and Hasura
– vue-graphql-demo. Feel free to clone and
explore more about the codebase.
Conclusion
Now, you’re ready to build CRUD
application using VueJs, GaphQL, and
Hasura! Follow the entire step-by-step
guideline to create your app. Our team
extensively reviews and finds the best
relevant topics so that enthusiasts like you
can learn and explore every day! Visit the
VueJs tutorials page where you can find
similar topics with the github repository to
play around with the code. Feel free to
contact us for any suggestions or feedback.
We’ll be happy to hear from you.
Thank you
https://www.bacancytechnology.com/

More Related Content

PDF
스프링 부트와 로깅
PPTX
Introduction to React JS
PDF
Go1.18 Genericsを試す
PDF
NestJS
PDF
JUnit & Mockito, first steps
PDF
elasticsearchソースコードを読みはじめてみた
PPTX
Introduction to React JS for beginners
PPTX
Mongoose and MongoDB 101
스프링 부트와 로깅
Introduction to React JS
Go1.18 Genericsを試す
NestJS
JUnit & Mockito, first steps
elasticsearchソースコードを読みはじめてみた
Introduction to React JS for beginners
Mongoose and MongoDB 101

What's hot (20)

PPTX
Server side rendering review
PPTX
Implementing DDD Concepts in PHP
PDF
Spring Boot & Containers - Do's & Don'ts
PDF
いまさら聞けないパスワードの取り扱い方
PPTX
Spring boot - an introduction
PPTX
Clean Code
PDF
Developing RESTful Web APIs with Python, Flask and MongoDB
PDF
Lets make a better react form
PDF
Introduction to Redux
PDF
Pre-Con Education: Shift-Left Performance Testing for Shift-Forward Quality
PDF
코딩 테스트 및 알고리즘 문제해결 공부 방법 (고려대학교 KUCC, 2022년 4월)
PPTX
React + Redux Introduction
PDF
Continuous Integration
PPTX
Clean architecture
PPT
Html JavaScript and CSS
PDF
Complete Java Course
PDF
Crawling - Coleta de dados na Web com PHP
PDF
An introduction to React.js
PDF
[야생의 땅: 듀랑고] 서버 아키텍처 - SPOF 없는 분산 MMORPG 서버
Server side rendering review
Implementing DDD Concepts in PHP
Spring Boot & Containers - Do's & Don'ts
いまさら聞けないパスワードの取り扱い方
Spring boot - an introduction
Clean Code
Developing RESTful Web APIs with Python, Flask and MongoDB
Lets make a better react form
Introduction to Redux
Pre-Con Education: Shift-Left Performance Testing for Shift-Forward Quality
코딩 테스트 및 알고리즘 문제해결 공부 방법 (고려대학교 KUCC, 2022년 4월)
React + Redux Introduction
Continuous Integration
Clean architecture
Html JavaScript and CSS
Complete Java Course
Crawling - Coleta de dados na Web com PHP
An introduction to React.js
[야생의 땅: 듀랑고] 서버 아키텍처 - SPOF 없는 분산 MMORPG 서버
Ad

Similar to How to build crud application using vue js, graphql, and hasura (20)

PDF
How to Build ToDo App with Vue 3 + TypeScript
PDF
Angular 7 Firebase5 CRUD Operations with Reactive Forms
PDF
Creating web api and consuming- part 1
PDF
Volley lab btc_bbit
PPTX
Cloud Endpoints _Polymer_ Material design by Martin Görner
PDF
Adding User Management to Node.js
PPTX
Grails Advanced
PPTX
ColdBox APIs + VueJS - powering Mobile, Desktop and Web Apps with 1 VueJS cod...
PDF
Reactive.architecture.with.Angular
PDF
ITB2019 ColdBox APIs + VueJS - powering Mobile, Desktop and Web Apps with 1 V...
DOCX
Implementing a file manager in ASP.NET Core 8.0
PPTX
An introduction to Vue.js
PDF
How to implement multiple authentication guards in laravel 8
PDF
Angular Interview Questions-PDF.pdf
PDF
How to Webpack your Django!
PPTX
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
PDF
Love at first Vue
PDF
Aspnet mvc tutorial_01_cs
PPTX
Getting started with hot towel spa
PPTX
Nodejs.meetup
How to Build ToDo App with Vue 3 + TypeScript
Angular 7 Firebase5 CRUD Operations with Reactive Forms
Creating web api and consuming- part 1
Volley lab btc_bbit
Cloud Endpoints _Polymer_ Material design by Martin Görner
Adding User Management to Node.js
Grails Advanced
ColdBox APIs + VueJS - powering Mobile, Desktop and Web Apps with 1 VueJS cod...
Reactive.architecture.with.Angular
ITB2019 ColdBox APIs + VueJS - powering Mobile, Desktop and Web Apps with 1 V...
Implementing a file manager in ASP.NET Core 8.0
An introduction to Vue.js
How to implement multiple authentication guards in laravel 8
Angular Interview Questions-PDF.pdf
How to Webpack your Django!
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Love at first Vue
Aspnet mvc tutorial_01_cs
Getting started with hot towel spa
Nodejs.meetup
Ad

More from Katy Slemon (20)

PDF
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
PDF
Data Science Use Cases in Retail & Healthcare Industries.pdf
PDF
How Much Does It Cost To Hire Golang Developer.pdf
PDF
What’s New in Flutter 3.pdf
PDF
Why Use Ruby On Rails.pdf
PDF
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
PDF
How to Implement Middleware Pipeline in VueJS.pdf
PDF
How to Build Laravel Package Using Composer.pdf
PDF
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
PDF
How to Develop Slack Bot Using Golang.pdf
PDF
IoT Based Battery Management System in Electric Vehicles.pdf
PDF
Understanding Flexbox Layout in React Native.pdf
PDF
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
PDF
New Features in iOS 15 and Swift 5.5.pdf
PDF
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
PDF
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
PDF
Flutter Performance Tuning Best Practices From the Pros.pdf
PDF
Angular Universal How to Build Angular SEO Friendly App.pdf
PDF
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
PDF
Ruby On Rails Performance Tuning Guide.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdf
How Much Does It Cost To Hire Golang Developer.pdf
What’s New in Flutter 3.pdf
Why Use Ruby On Rails.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How to Implement Middleware Pipeline in VueJS.pdf
How to Build Laravel Package Using Composer.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
How to Develop Slack Bot Using Golang.pdf
IoT Based Battery Management System in Electric Vehicles.pdf
Understanding Flexbox Layout in React Native.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
New Features in iOS 15 and Swift 5.5.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Flutter Performance Tuning Best Practices From the Pros.pdf
Angular Universal How to Build Angular SEO Friendly App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
Ruby On Rails Performance Tuning Guide.pdf

Recently uploaded (20)

PPT
What is a Computer? Input Devices /output devices
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
Architecture types and enterprise applications.pdf
PPTX
1. Introduction to Computer Programming.pptx
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
DP Operators-handbook-extract for the Mautical Institute
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PPTX
Tartificialntelligence_presentation.pptx
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
Modernising the Digital Integration Hub
What is a Computer? Input Devices /output devices
observCloud-Native Containerability and monitoring.pptx
Architecture types and enterprise applications.pdf
1. Introduction to Computer Programming.pptx
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
DP Operators-handbook-extract for the Mautical Institute
O2C Customer Invoices to Receipt V15A.pptx
Tartificialntelligence_presentation.pptx
A comparative study of natural language inference in Swahili using monolingua...
Zenith AI: Advanced Artificial Intelligence
Hindi spoken digit analysis for native and non-native speakers
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
NewMind AI Weekly Chronicles - August'25-Week II
A contest of sentiment analysis: k-nearest neighbor versus neural network
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
Modernising the Digital Integration Hub

How to build crud application using vue js, graphql, and hasura

  • 1. How to Build CRUD Application using VueJS, GraphQL, and Hasura https://www.bacancytechnology.com/
  • 3. In this tutorial, we will learn how to build CRUD application using VueJS, GraphQL, and Hasura. Don’t be scared of the technical stack; just stick till the end of the blog, and you’ll be able to build your basic CRUD app. Many developers consider GraphQL as a DB technology, but that’s not true! GraphQL is a query language – an alternative to build REST APIs. GraphQL provides an interface to put-away information that meets the application’s requirements. Facebook developed it as an internal technology for enhancing the app’s versatility and later released it as open-source. Since then, the software development community has utilized it as one of the favorite technology stacks for developing web services.
  • 4. Tutorial Goal: Build CRUD Application using VueJS, GraphQL, and Hasura
  • 5. Before moving towards building a basic CRUD app, watch the below video to understand what we are building. Prerequisites Basic knowledge of VueJS and GraphQL VS Code or any other IDE Familiarity with Javascript and HTML https://youtu.be/GvA7N1uB86g Below is the Video link
  • 7. Basic knowledge of VueJS and GraphQL VS Code or any other IDE Familiarity with Javascript and HTML
  • 9. Firstly you need to sign up to Hasura cloud. Visit hasura.io to do the same. Hasura instantly lets your apps query, update, and receive real-time notifications of your data with GraphQL. After successful signup, you have to connect your database. Either you can use any existing database or create from Heroku it’s for free.
  • 10. Once done with creating or connecting your database, let’s move to the code section. Build well-performing and cost-effective VueJS applications with Bacancy. We have proficient developers with the best technical insights and problem-solving skills. Hire VueJS developer from us and start building applications of your choice!
  • 12. You can create a new VueJS application or use an existing application. Here I am using a fresh vue application by setting up using vue-cli. So here is the command to create the application. vue create vue-graphql-demo Run the below command to install all the dependencies. npm install vue-apollo@3.0.0-beta.28 apollo-cache-inmemory apollo-link- http apollo-client graphql-tag graphql --save
  • 13. Then create one file named apollo.js under the src/ and register all the packages below. // apollo.js import Vue from 'vue' import VueApollo from 'vue-apollo' import { ApolloClient } from 'apollo-client' import { HttpLink } from 'apollo-link-http' import { InMemoryCache } from 'apollo-cache- inmemory' const httpLink = new HttpLink({ // You should use an absolute URL here uri: 'https://your- app.hasura.app/v1/graphql', headers: { "x-hasura-admin-secret": "token" } })
  • 14. // Create the apollo client export const apolloClient = new ApolloClient({ link: httpLink, cache: new InMemoryCache(), connectToDevTools: true }) const apolloProvider = new VueApollo({ defaultClient: apolloClient }) // Install the vue plugin Vue.use(VueApollo) export default apolloProvider
  • 15. Get your URL and x-hasura-admin-secret from the GraphQL/API tab, as shown below. Now it’s time to update your main.js file. Import this apollo.js to the main.js. // main.js import Vue from 'vue' import App from './App.vue' import apolloProvider from './apollo' Vue.config.productionTip = false new Vue({ apolloProvider, render: h => h(App) }).$mount('#app')
  • 16. So here we are, done with the initial setup. Now, it’s time to make a query to get the data, update it, and delete it. Here I have created the users table. Create a component for users, and let’s add the query for getting the users data.
  • 18. Use the following code snippets to implement the CRUD operations in your application. CREATE const name = this.name; const email = this.email; this.$apollo.mutate({ mutation: gql` mutation addUser($name: String!, $email: String!) { insert_users(objects: [{ name: $name, email: $email }]) { returning { user_id } } } `, var
  • 19. variables: { name, Email, }, refetchQueries: ["getUsers"], }); Same as we have inserted the data, we need to update a particular user’s data and delete it too. READ apollo: { userList: { query: gql` query getUsers { users { user_id name email
  • 20. } } `, update: (data) => { return data.users; }, }, }, In the userList variable, you will get an object of users, so let’s add it into the table element. Now, it’s time to add users, so make one form and add two fields, name and email.
  • 21. UPDATE const name = this.editUser.name; const email = this.editUser.email; const user_id = this.editUser.user_id; this.$apollo.mutate({ mutation: gql` mutation updateUsers($user_id: Int, $name: String!, $email: String!) { update_users( where: { user_id: { _eq: $user_id } } _set: { email: $email, name: $name } ) { returning { user_id } }
  • 22. } `, variables: { user_id, name, email, }, refetchQueries: ["getUsers"], }); DELETE let user_id = id; this.$apollo.mutate({ mutation: gql` mutation deleteUser($user_id: Int) { delete_users(where:
  • 23. { user_id: { _eq: $user_id } }) { returning { user_id } } } `, variables: { user_id, }, refetchQueries: ["getUsers"], });
  • 24. Github Repository: Build CRUD Application using VueJS, GraphQL, and Hasura
  • 25. Here’s the source code for building the CRUD app with Vue, GraphQL, and Hasura – vue-graphql-demo. Feel free to clone and explore more about the codebase.
  • 27. Now, you’re ready to build CRUD application using VueJs, GaphQL, and Hasura! Follow the entire step-by-step guideline to create your app. Our team extensively reviews and finds the best relevant topics so that enthusiasts like you can learn and explore every day! Visit the VueJs tutorials page where you can find similar topics with the github repository to play around with the code. Feel free to contact us for any suggestions or feedback. We’ll be happy to hear from you.