Go-Graphql-Template is a template with minimum code to get CRUD and subscriptions working with grapqhl in Golang. The template uses a mongodb database that is run through docker.
- Docker
- VSCode (To use debugger/launch task)
- Golang
- Start mongoDB database specified in docker-compose.yml
docker-compose up
- Start the server by going to "Run and Debug" and use the "Launch Server" option.
- Navigate to "http://localhost:8081/" to experiment with the grapqhl UI. See "Queries And Mutations" on how to use it.
mutation createExample($createInput: GQCreateExample!) {
createExample(input: $createInput)
}
mutation updateExample($updateInput: GQUpdateExample!) {
updateExample(input: $updateInput) {
id
variable1
variable2
}
}
mutation deleteExample($id: String!) {
deleteExample(id: $id)
}
query getByID($id: String!) {
getByID(id: $id) {
id
variable1
variable2
}
}
query getAll {
getAll {
id
variable1
variable2
}
}
{
"createInput": {
"variable1": "hejsan",
"variable2": 10
},
"updateInput": {
"id": "622a4da65a80406a0b6d8f9e",
"variable1": "new value",
"variable2": 22
},
"id": "622a4da65a80406a0b6d8f9e"
}
subscription exampleSubscription {
exampleSubscription {
id
variable1
variable2
}
}
To generate new files from the specified "schema.graphqls" in the "graph" folder, use the task "Generate Graphql".
- Press F1
- Select Run task
- Select and run "Generate Graphql"
Rickard Andersson https://github.com/RickardA/go-graphql-template