Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kristiankjerstad/cooking-recipes-backend


https://github.com/kristiankjerstad/cooking-recipes-backend

Last synced: 8 days ago
JSON representation

Awesome Lists containing this project

README

        

# Get started
* Make sure you have installed [air](https://github.com/air-verse/air) and [Go](https://go.dev/)

To start the app:
1. Start the mongo db server using docker-compose: in the terminal run `docker-compose up --build`
2. go to the terminal and enter `air`.
(Alternatively the app can be started using `go run server.go`)

A GraphQL playground will now start at `localhost:8060`.

## Example Graph QL queries
```GraphQL
mutation AddDog {
createDog(input: {name: "x", isGoodBoi: true}) {
_id
name
isGoodBoi
}
}

query AllDogs {
dogs {
name
_id
isGoodBoi

}
}

query getDog {
dog(_id:"6672e1fc003309c534c5ff34") {
name
_id
isGoodBoi
}
}

mutation CreateRecipe{
createRecipe(input:{
name: "vodka redbull",
description:"a drink",
category:DRINK,
steps: ["get ingredients", "make"],
ingredients:[{name:"vodka", quantity:20, unit:"ml"},{name:"redbull", quantity:20, unit:"ml"}]
}) {
_id
}
}

query GetRecipe{
recipe(_id:"6673ec1c3f75e1774098f227"){
name
description
ingredients{name quantity unit}
steps
category
}
}

query AllRecipes{
recipes{
name
description
ingredients{name quantity unit}
steps
category
}
}

mutation delete{
deleteRecipe(_id:"ObjectID('6673ec373f75e1774098f229')")
}

mutation updateRecipe{
updateRecipe(input:
{
_id: "6673ec393f75e1774098f232"
name:"sdf"
description:"asdf"
category:DRINK
steps:["123", "2434"]
ingredients:[{_id:"123", name:"x", quantity:22, unit:"ml"}]
}
){
name
}
}
```

## Modify the code

The Go code related to Graph QL is autogenerated. After making changes to the GraphQL schema in graph/schema.graphqls, open the terminal and run the command `go run github.com/99designs/gqlgen generate`.

The setup is based on [this guide](https://www.howtographql.com/graphql-go/1-getting-started/).