# README
GoLang GraphQL MongoDB CRUD Project
This project is a comprehensive example of building a GraphQL API in GoLang for performing CRUD (Create, Read, Update, Delete) operations with a MongoDB database. It serves as a practical reference for developers looking to create efficient and scalable GraphQL-based applications.
- Create a new folder for the Project
mkdir graphql
- Mod init your project, give it whatever name you like
go mod init github.com/athunlal/graphql
- Get gql gen for your project
go get github.com/99designs/gqlgen
- Add gqlgen to tools.go
printf '// +build tools\npackage tools\nimport _ "github.com/99designs/gqlgen"' | gofmt > tools.go
- Get all the dependencies
go mod tidy
- Initialize your project
go run github.com/99designs/gqlgen init
- After you've written the graphql schema, run this -
go run github.com/99designs/gqlgen generate
- After you've built the project, these are the queries to interact with the API -
Running the application
- Install the dependencies
go mod tidy
- Run the application
go run server.go
- Copy and paste into the browser.
http://localhost:8080/
Get All Jobs
query GetAllJobs{
jobs{
_id title description company url
}
}
Create Job
mutation CreateJobListing($input: CreateJobListingInput!){
createJobListing(input:$input){
_id title description company url
}
}
Input
{
"input": {
"title": "Software Development Engineer - I",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",
"company": "Google",
"url": "www.google.com/"
}
}
Get Job By Id
query GetJob($id: ID!){
job(id:$id){
_id title description url company
}
}
Input
{ "id": "638051d7acc418c13197fdf7" }
Update Job By Id
mutation UpdateJob($id: ID!,$input: UpdateJobListingInput!) {
updateJobListing(id:$id,input:$input){
title description _id company url
}
}
Input
{
"id": "638051d3acc418c13197fdf6",
"input": {
"title":
"Software Development Engineer - III"
}
}
Delete Job By Id
mutation DeleteQuery($id: ID!) {
deleteJobListing(id:$id){
deletedJobId
}
}
Input
{ "id": "638051d3acc418c13197fdf6" }