This project is a GraphQL demonstration using Go.
It shows the interaction between two entities, Course and Category, where there's a nested relationship in which a category has many courses.
GraphQL is a query language for APIs created by Facebook (Meta), allowing clients to request precisely what they need to obtain as a response.
It can be very useful in multiple cenarios, including integrating with BFF (backend for frontend) solutions.
- Go
- GraphQL using a library called gqlgen
- SQLite
cmd - main package
graph - all graphql configuration
| model - model structs
internal
| database - services responsible to interact with database
db.sqlite - in memory relational database
A table Categories and a table Courses must be created:
create table categories (id string, name string, description string);
create table courses (id string, name string, description string, category_id string)
After running the project using command below, GraphQL playground will open usually on port http://localhost:8080/
go run .\cmd\server\server.go
Example of GraphQL playground use
Query: All query we need
Mutation: All intention types of change
- queryCategories
- queryCategories without description
To initiate a project
go mod init projectName
To run the project
go run .\cmd\server\server.go
Command that synchronizes the go mod file with the actual dependencies used in the codebase
go mod tidy
Initialize gqlgen lib
go run github.com/99designs/gqlgen init
To generate a new schema
go run github.com/99designs/gqlgen generate
Running SQLIte (it depends on SQLite is installed and configured on your OS). I used command below on Windows.
C:\sqlite\sqlite3.exe db.sqlite
This project was built and inspired during course on the Fullcycle platform.