Conversation
Closed
759d2e7 to
821cc20
Compare
1c45783 to
7c96479
Compare
6821f68 to
3749703
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gqlgenc v1 is rewriting based on gqlgenc v0.0.2. If there are any missing features, please let me know.
Schedule
GraphQL Client
application/graphql-response+json;charset=utf-8Gennerate Client and Query Go code
gqlgendistinguishes whether the received input isundefinedornull.gqlgencdistinguishes whether the input sent, using the type generated bygqlgen'smodel_gen, isundefinedornull.gqlgento returnundefinedin responses. From Go 1.24, usingomitempty+IsZeromethod.Sample
Refactoring
@gofieldtypeNot supported
Squense
sequenceDiagram actor User participant Main as main.go participant Run as run.go participant Config as config participant Client as client participant Introspection as introspection participant QueryParser as queryparser participant CodeGen as codegen participant ModelGen as modelgen participant QueryGen as querygen participant ClientGen as clientgen User->>Main: Execute gqlgenc command Main->>Run: run() Note over Run,Config: Configuration Loading (TestLoadConfig) Run->>Config: FindConfigFile(".gqlgenc.yml") Config-->>Run: config file path Run->>Config: LoadConfig(cfgFile) Note right of Config: [TestLoadConfig]<br/>Read config file<br/>Parse YAML with env expansion alt Config validation error Config->>Config: Check schema/endpoint Note right of Config: Error if both specified<br/>Error if neither specified Config-->>Run: Error else Config validation success Config->>Config: Validate model config Config->>Config: Set schema filenames (glob) Config->>Config: Set default gqlgen fields Note right of Config: Directives, Exec, Resolver,<br/>Federation configs Config-->>Run: Config end Note over Run,Introspection: Schema Loading & Initialization (TestLoadSchema) Run->>Config: LoadSchema(ctx) alt Local Schema Config->>Config: GQLGenConfig.LoadSchema() Note right of Config: [TestLoadSchema]<br/>Load from local files Config-->>Config: GraphQL AST else Remote Schema (Endpoint) Config->>Client: Use endpoint.Client or http.DefaultClient Client-->>Config: HTTP Client Config->>Introspection: introspectionSchema(ctx, client, URL, headers) Introspection->>Client: Post(introspectionQuery) alt HTTP Error Client-->>Introspection: Error (500, 404, etc) Introspection-->>Config: Error Config-->>Run: Error else Success Client-->>Introspection: Schema Response Introspection->>Introspection: Parse introspection response alt Invalid Schema Introspection->>Introspection: Validate schema Introspection-->>Config: Validation Error Config-->>Run: Error else Valid Schema alt Query type is null Introspection->>Introspection: Initialize default Query type end Introspection-->>Config: GraphQL AST Config->>Config: Set GQLGenConfig.Schema end end end Config->>Config: Delete existing generated files Note right of Config: Unlink model, query,<br/>client gen files Config->>Config: Initialize Models & StructTag Note right of Config: Set default Models map<br/>Set default StructTag="json" Config->>Config: GQLGenConfig.Init() Config->>Config: Sort Schema.Implements Note right of Config: [TestLoadSchema]<br/>Sort interface implementations<br/>for deterministic output Config-->>Run: Initialized Config Note over Run,QueryParser: Query File Parsing (TestLoadQuery) Run->>Config: GQLGencConfig.LoadQuery(schema) Config->>QueryParser: LoadQuerySources(query files) alt Query file not found or syntax error QueryParser-->>Config: Error Config-->>Run: Error else Query files loaded QueryParser-->>Config: Query Sources Config->>QueryParser: QueryDocument(schema, sources) Note right of QueryParser: [TestLoadQuery]<br/>Parse & validate<br/>GraphQL queries alt Query validation error QueryParser-->>Config: Error (unknown field, etc) Config-->>Run: Error else Valid queries QueryParser-->>Config: Query Document Config->>QueryParser: OperationQueryDocuments() Note right of QueryParser: [TestLoadQuery]<br/>Split by operation<br/>(query/mutation/subscription) QueryParser-->>Config: Operation Documents Config->>Config: Set QueryDocument & OperationQueryDocuments Config-->>Run: Success end end Note over Run,ClientGen: Code Generation Run->>Run: plugins.GenerateCode(cfg) Note over Run,ModelGen: Model Generation (gqlgen based) Run->>ModelGen: New(cfg, operationDocs) Run->>ModelGen: MutateConfig() ModelGen->>ModelGen: Generate models/enums/scalars Note right of ModelGen: Generate Go types<br/>for GraphQL types ModelGen-->>Run: models_gen.go Note over Run,CodeGen: Go Type Analysis Run->>CodeGen: CreateOperations(queryDoc, opDocs) Note right of CodeGen: Create operation structs<br/>with args & variables CodeGen-->>Run: Operations Run->>CodeGen: CreateGoTypes(operations) Note right of CodeGen: Convert GraphQL types<br/>to Go types CodeGen-->>Run: Go Types Note over Run,QueryGen: Query Code Generation Run->>QueryGen: New(cfg, operations, goTypes) Run->>QueryGen: MutateConfig() QueryGen->>QueryGen: RenderTemplate(template.tmpl) Note right of QueryGen: Generate response types<br/>& unmarshal code QueryGen-->>Run: query code with types Note over Run,ClientGen: Client Code Generation Run->>ClientGen: New(cfg, operations) Run->>ClientGen: MutateConfig() ClientGen->>ClientGen: RenderTemplate(template.tmpl) Note right of ClientGen: Generate client methods<br/>for each operation ClientGen-->>Run: client.go with methods Run-->>Main: Success Main-->>User: Generated code files