Skip to content

lucasdsalves/graphQL-go

Repository files navigation

About

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

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.

Project technologies

  • Go
  • GraphQL using a library called gqlgen
  • SQLite

Project structure

cmd - main package
graph - all graphql configuration
  | model - model structs
internal
  | database - services responsible to interact with database
db.sqlite - in memory relational database

SQLite commands

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)

GraphQL playground

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

Useful commands

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.

About

GraphQL demonstration using Go

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages