99designs/gqlgen

Support include's in graphql files.

开放

#4,205 创建于 2026年6月5日

 (4 条评论) (1 个反应) (0 位负责人)Go (1,250 个派生)auto 404
help wantedproposal

仓库指标

星标
 (10,737 个星标)
PR 合并指标
 (平均合并 11天) (30 天内合并 20 个 PR)

描述

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

贡献者指南