Skip to content

Harsh971/Golang_GraphQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang GraphQL Project

This project is for building GraphQL APIs in Go (Golang) using gqlgen.
It demonstrates how to structure a GraphQL server, define schemas, resolvers, and manage data using an in-memory store.

This repository is ideal for learning:

  • GraphQL fundamentals in Go
  • gqlgen project structure
  • Resolver patterns
  • Basic API routing with net/http

🚀 Features

  • GraphQL API built with gqlgen
  • Strongly typed schema-first development
  • In-memory data store (no database required)
  • Clean separation of schema, resolvers, and storage
  • Ready-to-extend project structure

📁 Project Structure

golang-graphql-starter/
├── server.go                    # Application entry point
├── tools/
│   └── tools.go                 # gqlgen tool dependency
│
├── graph/
│   ├── resolver.go              # Root resolver definitions
│   ├── schema.resolvers.go      # Query & Mutation resolvers
│   ├── generated/
│   │   └── generated.go         # Auto-generated GraphQL code
│   ├── model/
│   │   └── models_gen.go        # Auto-generated models
│   └── store/
│       └── store.go             # In-memory data store

🧠 How the Project Works

  1. server.go

    • Initializes the GraphQL server
    • Registers HTTP routes
    • Starts the application
  2. GraphQL Schema

    • Defined using gqlgen (schema-first)
    • Auto-generates Go models and resolvers
  3. Resolvers

    • Handle incoming GraphQL queries and mutations
    • Interact with the in-memory store
  4. Store

    • Simple in-memory data storage
    • Simulates database operations

🛣️ API Routes

GET /

Description:
Serves the GraphQL Playground UI.

Use this endpoint to:

  • Explore the schema
  • Execute queries and mutations
  • Test the API

POST /query

Description:
Main GraphQL endpoint.

All GraphQL queries and mutations are sent here.

Content-Type:

application/json

📊 Example GraphQL Operations

Query Example

query {
  users {
    id
    name
  }
}

Mutation Example

mutation {
  createUser(name: "John") {
    id
    name
  }
}

🧩 Core Files Explained

server.go

  • Sets up HTTP server
  • Configures gqlgen handler
  • Enables GraphQL Playground

resolver.go

  • Root resolver struct
  • Injects dependencies like the store

schema.resolvers.go

  • Implements:
    • Query resolvers
    • Mutation resolvers
  • Contains business logic

store/store.go

  • In-memory slice-based storage
  • Functions to:
    • Add records
    • Fetch records

generated/*

⚠️ Auto-generated by gqlgen
Do not edit manually


🛠️ How to Run the Project

Prerequisites

  • Go 1.18+
  • gqlgen installed

Installation

go mod tidy
go run server.go

Access the Playground

http://localhost:8080

📦 Dependencies

  • github.com/99designs/gqlgen
  • net/http

About

This project is for building GraphQL APIs in Go (Golang) using gqlgen. It demonstrates how to structure a GraphQL server, define schemas, resolvers, and manage data using an in-memory store.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors