A graphql server project using golang and gqlgen (https://gqlgen.com/getting-started/).
- For generate the graphql skeleton:
go run github.com/99designs/gqlgen init
- For running application:
go run cmd/server/server.go
- Create dabase using the sqlite3:
sqlite3 data.db
create table categories (id string, name string, description string);
-
After the create table, access the playground using the url: http://localhost:8080/
-
In input of web page, put the value, and after click in play button:
mutation createCategory {
createCategory(input: {name: "tech", description: "courses"}){
id,
name,
description
}
}
mutation createCourse {
createCourse(input: {name: "Java", description: "learning fundamentals of java", categoryId: "352f4af6-c317-4cff-bb01-c1b68799b0aa"}) {
id
name
}
}
query queryCategories {
categories {
id
name
description
}
}
query queryCategoriesWithCourses {
categories {
id
name
courses {
id
name
}
}
}
query queryCouses {
courses {
id
name
}
}
query queryCousesWithCategory {
courses {
id
name
description
category {
id
name
description
}
}
}
- create table of courses:
sqlite3 data.db
create table courses (id string, name string, description string, category_id string);
- For generate the of model and types:
go run github.com/99designs/gqlgen generate