99designs / 99designs/gqlgen

Omit return values for interface/union options that aren't specified with inline fragments

Open
#2,511 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
10.8k
Forks
1.3k
Avg merge
2d 36m
Merged PRs (30d)
26

Description

### What happened?

When a user queries for specific types of an interface and only wants one type in the response, an empty map is returned for the unspecified fragments/types.

### What did you expect?

The option should be provided for those empty maps to be omitted.

### Minimal graphql.schema and models to reproduce

schema:
```
interface Animal {
id string
}

type Dog implements Animal {
furLength int
id string
}

type Cat implements Animal {
meowPitch int
id string
}

```
and a query for:
```
animals {
... on Dog {
furLength
id
}
}
```
would potentially return two objects in the array, one empty and one expected. The empty ones should be omitted

### versions
- `go run github.com/99designs/gqlgen version`? 0.17.22
- `go version`? 1.19.4

Contributor guide

Open the contributing guide

Research direction

The issue relates to how gqlgen handles inline fragments for interfaces/unions. Look at the code generation for interfaces and unions, likely in the codegen package. Examine how responses are built when only some types are specified in the fragment. The goal is to omit empty maps for unspecified types. Start by understanding the resolver generation and response marshaling logic. Check existing tests for interface/union handling to see the current behavior and add tests for the new feature.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, graphql
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.