This is a simple example project showcasing the use of GraphQL in Go, specifically utilizing the gqlgen package. In this example, we focus on creating and managing courses and categories while establishing relationships between them.
- GraphQL Implementation: Utilizes gqlgen for efficient GraphQL implementation in Go.
- Course Creation: Allows for the creation of courses with relevant details.
- Category Management: Enables the creation of categories to organize courses effectively.
- Relationships: Establishes relationships between courses and their respective categories.
Before you begin, ensure you have the following dependencies installed:
- Go: Install Go
- gqlgen: Install gqlgen
-
Clone the repository:
git clone https://github.com/kameikay/graphql-example.git cd graphql-example
-
Install dependencies:
go mod tidy
-
Run the GraphQL server:
go run cmd/server/server.go
-
Open the GraphQL Playground:
Navigate to http://localhost:8080 in your web browser to access the GraphQL Playground.
mutation {
createCourse(course: {
name: "Introduction to Go Programming"
description: "Learn the basics of Go programming language."
categoryId: "<category-id>"
}) {
id
name
description
category {
id
name
}
}
}
mutation {
createCategory(category: {
name: "Programming"
description: "Learn how to program."
}) {
id
name
description
}
}
query {
courses {
id
name
description
category {
id
name
description
}
}
}
query {
categories {
id
name
description
courses {
id
name
description
}
}
}
Note: Make sure to replace <category-id>
with the actual ID of the category when creating a course.