Skip to content

Generate SDK as standalone Go module with go.mod #2

Description

@khanakia

Summary

Add the ability to generate the SDK as a standalone Go module by automatically creating a go.mod file in the output directory. This would make the generated SDK self-contained and immediately importable without requiring it to live inside an existing Go module.

Current behavior

The generated SDK is a set of Go packages that must live inside an existing Go module. Users need a go.mod in their project root, and the --package flag must match the module path + output dir. The generator already has a commented-out WriteGoMod call in clientgen.go but it was never wired up.

Proposed behavior

Add a --module flag (or repurpose the existing unused one) that, when provided:

  1. Generates a go.mod file in the output directory with the given module path
  2. Uses that module path as the root import path for all generated files
  3. Makes the SDK directory a fully independent Go module

Example

gqlkit generate \
  --schema schema.graphql \
  --output ./my-sdk \
  --module github.com/yourorg/myapi-sdk

This would generate:

my-sdk/
├── go.mod                 # module github.com/yourorg/myapi-sdk
├── builder/
├── graphqlclient/
├── enums/
├── fields/
├── inputs/
├── mutations/
├── queries/
├── scalars/
└── types/

The generated go.mod would contain the module declaration and any required dependencies (currently none — the SDK is stdlib-only).

Usage after generation

Other projects could then import it directly:

go get github.com/yourorg/myapi-sdk
import (
    "github.com/yourorg/myapi-sdk/graphqlclient"
    "github.com/yourorg/myapi-sdk/queries"
    "github.com/yourorg/myapi-sdk/fields"
)

Why

  • Allows publishing the generated SDK as its own Go module / repo
  • Removes the coupling between the SDK and the parent project's module
  • Enables sharing the SDK across multiple projects without replace directives
  • The scaffolding (WriteGoMod, --module flag) already partially exists

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions