graphql-go / graphql-go/graphql

Create a type registry for bindFields

Open
#418 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
10.1k
Forks
845
PR merge metrics
No merged PRs in 30d

Description

Currently, `BindFields` creates new types for each field it finds that is also a struct. This can lead to issues if these fields have the same tag, because it'll lead to 2 types with the same name, causing an error.

What if, instead of the current behavior, it uses the struct's type name, falling back to the tag only when the type is not defined (as in `struct{int, bool}{5, true}`. We can then create a registry of GraphQL types based on Go types, where we map from a Go type's `type.PkgPath() + type.Name()` to the `graphql.Object` type. So when BindFields is given a type that is in the registry, it can just look that up in the registry.

There could also be a `RegisterObjectForType` function to register a GraphQL object for a certain type. This could also solve #415 by registering a predefined type for `time.Time`.

I'm willing to submit a PR for this. The only thing I'm not sure about is backwards compatibility.

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.