Compgen
Compgen is a gqlgen plugin designed to simplify the generation of ComplexityRoot for gqlgen.
Install / Use
/learn @Warashi/CompgenREADME
Compgen
Compgen is a gqlgen plugin designed to simplify the generation of ComplexityRoot for gqlgen. The generated ComplexityRoot calculates complexity using the @complexity(x: number, mul: [String!]) directive, and a configurable default fallback.
Usage
- Create a main.go file to use this plugin with gqlgen. Here's an example:
package main
import (
"fmt"
"os"
"github.com/99designs/gqlgen/api"
"github.com/99designs/gqlgen/codegen/config"
"github.com/Warashi/compgen"
)
func main() {
cfg, err := config.LoadConfigFromDefaultLocations()
if err != nil {
fmt.Fprintln(os.Stderr, "failed to load config", err.Error())
os.Exit(2)
}
if err := api.Generate(cfg, api.AddPlugin(compgen.New(compgen.WithDefaultComplexity(1)))); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(3)
}
}
- Use the generated ComplexityFunc as ComplexityRoot. For example:
cfg := gql.Config{
Resolvers: resolvers,
Complexity: gql.ComplexityFuncs,
}
srv := handler.NewDefaultServer(gql.NewExecutableSchema(cfg))
srv.Use(extension.FixedComplexityLimit(1000))
Calculation Example
Schema
type Query {
foo(
after: String,
first: Int,
before: String,
last: Int,
): FooConnection! @complexity(x: 2, mul: ["first", "last"])
fooIds(ids: [String!]): [Foo!] @complexity(x: 5, mul: ["ids"])
}
type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
}
type FooConnection {
edges: [FooEdge!]!
pageInfo: PageInfo!
}
type FooEdge {
cursor: String!
node: Foo!
}
type Foo {
bar: String! @complexity(x: 3)
}
-
Execute the following query:
query { foo(first: 5) { edges { node { bar } } } }The complexity will be calculated as (3 + default + default + 2) * 5.
-
Execute the follow query:
query { fooIds(ids: ["a","b","c"]) { edges { node { bar } } } }The complexity will be calculated as (3 + default + default + 5) * 3.
Additional tools
A linter relaycompmul is useful when using compgen with the relay cursor connections specification.
This linter will output errors when fields that follow the relay cursor connections specification and do not have a @complexity directive or are missing mul arguments of @complexity.
Related Skills
clearshot
Structured screenshot analysis for UI implementation and critique. Analyzes every UI screenshot with a 5×5 spatial grid, full element inventory, and design system extraction — facts and taste together, every time. Escalates to full implementation blueprint when building. Trigger on any digital interface image file (png, jpg, gif, webp — websites, apps, dashboards, mockups, wireframes) or commands like 'analyse this screenshot,' 'rebuild this,' 'match this design,' 'clone this.' Skip for non-UI images (photos, memes, charts) unless the user explicitly wants to build a UI from them. Does NOT trigger on HTML source code, CSS, SVGs, or any code pasted as text.
openpencil
2.2kThe world's first open-source AI-native vector design tool and the first to feature concurrent Agent Teams. Design-as-Code. Turn prompts into UI directly on the live canvas. A modern alternative to Pencil.
HappyColorBlend
HappyColorBlendVibe Project Guidelines Project Overview HappyColorBlendVibe is a Figma plugin for color palette generation with advanced tint/shade blending capabilities. It allows designers to
Flyaro-waffle-app
Waffle Delight - Full Stack MERN Application Rules & Documentation Project Overview A comprehensive waffle delivery application built with MERN stack featuring premium UI/UX, admin management, a
