99designs/gqlgen

Support include's in graphql files.

Aperta

#4205 aperta il 5 giu 2026

 (4 commenti) (1 reazione) (0 assegnatari)Go (1250 fork)auto 404
help wantedproposal

Metriche repository

Star
 (10.737 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

We use the schema: directive of gqlgen.yml extensively to load shared types and directives. In fact we've used it so extensively that we now have an entire dependency tree. Example:

shared_directive.graphql:

directive @product(
    name: String!
) on ENUM_VALUE

shared_type.graphql:

enum FeedbackType {
    ANSWER,
    COMMENT @product(name: "myproduct")
}

gqlgen.yml:

schema:
- shared_directive.graphql
- shared_type.graphql
- schema.graphql

We only use @product in shared_type.graphql, not in schema.graphql; we need to remember to add shared_directive.graphql in gqlgen.yml even though gqlgen.yml does not use shared_directive.graphql directly. This is brittle and hard for devs to fiagure out what actually needs to be included in the schema: directive.

The ask: Add support for an #include directive in .graphql files. (Or #gqlgen_include, or whatever name makes sense.) This is a comment to most graphql parsers, but gqlgen reads it specially and uses it as an alternate way of loading a schema, as if it had been suggested in schema.graphql. The include is relative to the directory where the #include is found. Then we could do this:

---  shared_type.graphql:
#include "shared_directive.graphql"   # for @product

enum FeedbackType {
    ANSWER,
    COMMENT @product(name: "myproduct")
}

--- gqlgen.yml:
schema:
- shared_type.graphql
- schema.graphql

Guida contributor