lighthouse

command module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

README ΒΆ

🚒 Lighthouse GraphQL Framework

English | δΈ­ζ–‡

CI codecov Go Report Card License

Lighthouse is a feature-rich self-developed GraphQL framework designed to simplify GraphQL service development based on microservice architecture. The framework integrates a logging system (using zeroLog), supports Elasticsearch, file logging mode and Redis caching, while featuring a flexible directive system and powerful custom configuration capabilities. The framework currently has built-in support for gorm and will expand to more ORM options in the future.

Features

  • Microservice Architecture Support: Adopts independent microservice mode, doesn't support GraphQL Federation but manages microservices through a custom service registry.
  • Custom Directives: Supports rich custom directives for dynamic queries, filtering, relationships, and more.
  • Extensibility: Supports various GraphQL file structures through configuration files to flexibly meet different project needs.
  • ORM Integration: Currently supports gorm, with plans to add support for more ORM libraries.
  • Logging and Cache Integration: Integrates zeroLog logging system, supports Elasticsearch, file logging, and Redis caching.

Quick Start

Installation
  1. Install using go install

    go install github.com/light-speak/lighthouse@latest
    
  2. Create a new project

    lighthouse generate:init
    
Configuration File (lighthouse.yml)

lighthouse.yml is the core configuration file for lighthouse, used to specify GraphQL Schema paths, file extensions, ORM settings, etc. Here's an example configuration:

# lighthouse.yml

schema:
  ext:
    - graphql       # Supported file extensions
    - graphqls
  path:
    - schema        # Path to GraphQL Schema files
  model:
    orm: gorm       # ORM configuration, currently supports gorm
  • schema.ext: Specifies Schema file extensions, can be .graphql or .graphqls.
  • schema.path: Defines the path to Schema files, framework will automatically load all files in this path.
  • model.orm: Currently supports gorm as the ORM library.
Directory Structure

The example project structure is as follows:

.
β”œβ”€β”€ cmd                     # CLI related code
β”‚   β”œβ”€β”€ cmd.go              # Main command entry
β”‚   β”œβ”€β”€ migrate
β”‚   β”‚   └── migrate.go      # Database migration logic
β”‚   └── start
β”‚       └── start.go        # Service start entry
β”œβ”€β”€ models                  # Data model definitions
β”‚   β”œβ”€β”€ enum.go             # Enum type definitions
β”‚   β”œβ”€β”€ input.go            # Input type definitions
β”‚   β”œβ”€β”€ interface.go        # Interface definitions
β”‚   β”œβ”€β”€ model.go            # Model structures
β”‚   └── response.go         # Response data structures
β”œβ”€β”€ repo                    # Database operation encapsulation
β”‚   └── repo.go
β”œβ”€β”€ resolver                # GraphQL resolvers
β”‚   β”œβ”€β”€ mutation.go         # Mutation resolver
β”‚   β”œβ”€β”€ query.go            # Query resolver
β”‚   └── resolver.go         # Resolver main entry
β”œβ”€β”€ schema                  # GraphQL Schema files
β”‚   └── user.graphql        # Example Schema file
└── service                 # Service logic
    └── service.go
Next Steps

Add your custom schema files in the schema directory, then run the following command to generate corresponding code:

lighthouse generate:schema
Using Directives

In lighthouse, you can use the following directives in your GraphQL Schema:

  • @skip / @include: Conditional query directives for dynamically controlling field inclusion in responses.
  • @enum: For defining enum type fields, currently only supports int8 type.
  • @paginate / @find / @first: For pagination, finding, and getting first result queries.
  • @in / @eq / @neq / @gt / @gte / @lt / @lte / @like / @notIn: Parameter filtering directives supporting various comparison operators.
  • @belongsTo / @hasMany / @hasOne / @morphTo / @morphToMany: Relationship mapping directives for defining model relationships.
  • @index / @unique: Create index or add unique constraint for fields.
  • @defaultString / @defaultInt: Set default values for fields.
  • @tag: For marking additional field attributes.
  • @model: Mark type as database model.
  • @softDeleteModel: Mark type as database model with soft delete support.
  • @order: For sorting query results.
  • @cache: For caching query results to improve response speed.
Example Code

Here's an example query using the @paginate directive for user data pagination:

type Query {
  users: [User] @paginate(scopes: ["active"])
}

type User @model(name: "UserModel") {
  id: ID!
  name: String!
  age: Int
  posts: [Post] @hasMany(relation: "Post", foreignKey: "user_id")
}

Extension and Customization

lighthouse provides flexible extension interfaces, you can:

  • Add Custom Directives: Write your own directives to extend framework functionality.
  • Support Other ORMs: Add support for other ORM libraries by referencing the gorm integration approach.

Development Plan

πŸš€ Feature Category ✨ Feature Description πŸ“… Status
πŸ› οΈ Custom Directives Add support for custom directives βœ… Completed
πŸ“Š Query Directives Add @find and @first annotations for query support βœ… Completed
πŸ” Query & Filtering Add date range filtering directives βœ… Completed
Add string matching directives βœ… Completed
Add dynamic sorting directives βœ… Completed
πŸ“Š Pagination Add @paginate annotation for pagination support βœ… Completed
πŸ“œ Conditional Query Add @skip and @include conditional query directives 🚧 In Progress
πŸ“š Relationship Mapping Add @morphTo, @morphToMany, @hasOne, @manyToMany 🚧 In Progress
πŸ”§ Microservice Management Add microservice registry ⏳ Planned
πŸ’Ύ Cache Integration Integrate Redis as cache support βœ… Completed
πŸ“ Logging System Integrate zeroLog system, support Elasticsearch and file logging βœ… Completed
πŸ”„ Cache Directive Add @cache directive to support query result caching 🚧 In Progress
πŸ”€ Sorting Directive Add @order directive to support query result sorting 🚧 In Progress
πŸ—„οΈ ORM Support Extend support for other ORMs like ent, sqlc ⏳ Planned
πŸ“‘ Doc Generation Auto-generate GraphQL Schema documentation ⏳ Planned
πŸ“¦ Plugin Support Provide plugin system for community contributions ⏳ Planned
🌐 Frontend Tools Develop Apollo Studio-like frontend for query testing ⏳ Planned
πŸ“Š Performance Tracking Support performance tracking for fields and services ⏳ Planned

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Directories ΒΆ

Path Synopsis
cli
cli/generate/initialize
Code generated by github.com/light-speak/lighthouse, YOU CAN FUCKING EDIT BY YOURSELF.
Code generated by github.com/light-speak/lighthouse, YOU CAN FUCKING EDIT BY YOURSELF.
cli/generate/schema
Code generated by github.com/light-speak/lighthouse, YOU CAN FUCKING EDIT BY YOURSELF.
Code generated by github.com/light-speak/lighthouse, YOU CAN FUCKING EDIT BY YOURSELF.
cli/version
Code generated by github.com/light-speak/lighthouse, YOU CAN FUCKING EDIT BY YOURSELF.
Code generated by github.com/light-speak/lighthouse, YOU CAN FUCKING EDIT BY YOURSELF.
ast
net
plugins

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL