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

What's hot (20)

Clean architectures with fast api pycones
Clean architectures with fast api pycones
Alvaro Del Castillo
 
Apigee Demo: API Platform Overview
Apigee Demo: API Platform Overview
Apigee | Google Cloud
 
Building Mobile Apps on Salesforce Platform with Mobile SDK
Building Mobile Apps on Salesforce Platform with Mobile SDK
Salesforce Developers
 
Salesforce Streaming event - PushTopic and Generic Events
Salesforce Streaming event - PushTopic and Generic Events
Dhanik Sahni
 
Building APIs with Mule and Spring Boot
Building APIs with Mule and Spring Boot
Guilherme Pereira Silva
 
Managing the Role Hierarchy at Enterprise Scale
Managing the Role Hierarchy at Enterprise Scale
Salesforce Developers
 
Introduction to REST - API
Introduction to REST - API
Chetan Gadodia
 
Introduction to docker
Introduction to docker
Wei-Ting Kuo
 
Data engineering zoomcamp introduction
Data engineering zoomcamp introduction
Alexey Grigorev
 
Best Practices for API Management
Best Practices for API Management
WSO2
 
Integrating with salesforce using platform events
Integrating with salesforce using platform events
Amit Chaudhary
 
Introduction to web development
Introduction to web development
Mohammed Safwat
 
API 101 - Understanding APIs
API 101 - Understanding APIs
3scale
 
Intro to Salesforce Lightning Web Components (LWC)
Intro to Salesforce Lightning Web Components (LWC)
Roy Gilad
 
Seamless End-to-End Production Machine Learning with Seldon and MLflow
Seamless End-to-End Production Machine Learning with Seldon and MLflow
Databricks
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An Introduction
Salesforce Developers
 
Introduction to kubernetes
Introduction to kubernetes
Rishabh Indoria
 
認証プロバイダによるソーシャルサインオンWebinar
認証プロバイダによるソーシャルサインオンWebinar
Salesforce Developers Japan
 
The Role of E-E-A-T in Ecommerce
The Role of E-E-A-T in Ecommerce
Lily Ray
 
Complete Guide To Salesforce Einstein Analytics
Complete Guide To Salesforce Einstein Analytics
Cloud Analogy
 
Clean architectures with fast api pycones
Clean architectures with fast api pycones
Alvaro Del Castillo
 
Building Mobile Apps on Salesforce Platform with Mobile SDK
Building Mobile Apps on Salesforce Platform with Mobile SDK
Salesforce Developers
 
Salesforce Streaming event - PushTopic and Generic Events
Salesforce Streaming event - PushTopic and Generic Events
Dhanik Sahni
 
Managing the Role Hierarchy at Enterprise Scale
Managing the Role Hierarchy at Enterprise Scale
Salesforce Developers
 
Introduction to REST - API
Introduction to REST - API
Chetan Gadodia
 
Introduction to docker
Introduction to docker
Wei-Ting Kuo
 
Data engineering zoomcamp introduction
Data engineering zoomcamp introduction
Alexey Grigorev
 
Best Practices for API Management
Best Practices for API Management
WSO2
 
Integrating with salesforce using platform events
Integrating with salesforce using platform events
Amit Chaudhary
 
Introduction to web development
Introduction to web development
Mohammed Safwat
 
API 101 - Understanding APIs
API 101 - Understanding APIs
3scale
 
Intro to Salesforce Lightning Web Components (LWC)
Intro to Salesforce Lightning Web Components (LWC)
Roy Gilad
 
Seamless End-to-End Production Machine Learning with Seldon and MLflow
Seamless End-to-End Production Machine Learning with Seldon and MLflow
Databricks
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An Introduction
Salesforce Developers
 
Introduction to kubernetes
Introduction to kubernetes
Rishabh Indoria
 
認証プロバイダによるソーシャルサインオンWebinar
認証プロバイダによるソーシャルサインオンWebinar
Salesforce Developers Japan
 
The Role of E-E-A-T in Ecommerce
The Role of E-E-A-T in Ecommerce
Lily Ray
 
Complete Guide To Salesforce Einstein Analytics
Complete Guide To Salesforce Einstein Analytics
Cloud Analogy
 

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

Introduction to GraphQL for beginners
Introduction to GraphQL for beginners
Martin Pham
 
Introduction to Graph QL
Introduction to Graph QL
Deepak More
 
Getting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQL
Morgan Dedmon
 
Graphql presentation
Graphql presentation
Vibhor Grover
 
GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018
Sashko Stubailo
 
Why UI developers love GraphQL
Why UI developers love GraphQL
Sashko Stubailo
 
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Jon Wong
 
Shift Remote: WEB - GraphQL and React – Quick Start - Dubravko Bogovic (Infobip)
Shift Remote: WEB - GraphQL and React – Quick Start - Dubravko Bogovic (Infobip)
Shift Conference
 
Graphql usage
Graphql usage
Valentin Buryakov
 
Fly me to the moon
Fly me to the moon
Fatos Hoti
 
Create GraphQL server with apolloJS
Create GraphQL server with apolloJS
Jonathan Jalouzot
 
React Flux to GraphQL
React Flux to GraphQL
Turadg Aleahmad
 
Create flexible react applications using GraphQL API's
Create flexible react applications using GraphQL API's
Maurice De Beijer [MVP]
 
Create flexible React applications using GraphQL APIs - Maurice de Beijer - C...
Create flexible React applications using GraphQL APIs - Maurice de Beijer - C...
Codemotion
 
Apollo ecosystem
Apollo ecosystem
James Akwuh
 
GraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer tools
Sashko Stubailo
 
GraphQL vs. (the) REST
GraphQL vs. (the) REST
coliquio GmbH
 
Introduction to Testing GraphQL Presentation
Introduction to Testing GraphQL Presentation
Knoldus Inc.
 
Testing Graph QL Presentation (Test Automation)
Testing Graph QL Presentation (Test Automation)
Knoldus Inc.
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdf
Knoldus Inc.
 
Introduction to GraphQL for beginners
Introduction to GraphQL for beginners
Martin Pham
 
Introduction to Graph QL
Introduction to Graph QL
Deepak More
 
Getting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQL
Morgan Dedmon
 
Graphql presentation
Graphql presentation
Vibhor Grover
 
GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018
Sashko Stubailo
 
Why UI developers love GraphQL
Why UI developers love GraphQL
Sashko Stubailo
 
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Jon Wong
 
Shift Remote: WEB - GraphQL and React – Quick Start - Dubravko Bogovic (Infobip)
Shift Remote: WEB - GraphQL and React – Quick Start - Dubravko Bogovic (Infobip)
Shift Conference
 
Fly me to the moon
Fly me to the moon
Fatos Hoti
 
Create GraphQL server with apolloJS
Create GraphQL server with apolloJS
Jonathan Jalouzot
 
Create flexible react applications using GraphQL API's
Create flexible react applications using GraphQL API's
Maurice De Beijer [MVP]
 
Create flexible React applications using GraphQL APIs - Maurice de Beijer - C...
Create flexible React applications using GraphQL APIs - Maurice de Beijer - C...
Codemotion
 
Apollo ecosystem
Apollo ecosystem
James Akwuh
 
GraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer tools
Sashko Stubailo
 
GraphQL vs. (the) REST
GraphQL vs. (the) REST
coliquio GmbH
 
Introduction to Testing GraphQL Presentation
Introduction to Testing GraphQL Presentation
Knoldus Inc.
 
Testing Graph QL Presentation (Test Automation)
Testing Graph QL Presentation (Test Automation)
Knoldus Inc.
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdf
Knoldus Inc.
 
Ad

More from Katy Slemon (20)

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

Recently uploaded (20)

FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 

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 [email protected] 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.