99designs / 99designs/gqlgen

Support include's in graphql files.

Open
#4,205 4 comments 1 reaction 0 assignees View on GitHub
help wanted proposal
Dominant language
Go
Stars
10.8k
Forks
1.3k
Avg merge
2d 36m
Merged PRs (30d)
26

Description

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
````

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.