Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
Renaming Entity in gqlgen to avoid type name conflict
Browse files Browse the repository at this point in the history
Addresses 99designs#1256
  • Loading branch information
AndrewRayCode committed Jun 30, 2021
1 parent 5ad012e commit a3a7ffe
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 73 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Grand Rounds Fork of GQLgen

This fork was created by:

1. Forking the repository
2. Resetting master of the fork to the tagged commit of the last stable release
of gqlgen. At the time of writing this, it's tag v0.13.0 and commit 07c1f93.
3. Pushing -f to reset master of this fork the above commit.
3. Opening a pull request of the patch we've applied, to this fork, and merging
the patch into the master branch of this fork.s

Note that means the master branch of this fork diverges from the official
repository. To update this fork to the latest version of gqlgen:

1. Merge the latest version tagged commit of upstream into master of this fork.
**Don't** merge in the master branch of the main repository, just the commit
of the next tagged version.

# gqlgen [![Continuous Integration](https://github.com/99designs/gqlgen/workflows/Continuous%20Integration/badge.svg)](https://github.com/99designs/gqlgen/actions) [![Read the Docs](https://badgen.net/badge/docs/available/green)](http://gqlgen.com/) [![GoDoc](https://godoc.org/github.com/99designs/gqlgen?status.svg)](https://godoc.org/github.com/99designs/gqlgen)

![gqlgen](https://user-images.githubusercontent.com/46195831/89802919-0bb8ef00-db2a-11ea-8ba4-88e7a58b2fd2.png)
Expand Down
15 changes: 15 additions & 0 deletions codegen/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,25 @@ func Call(p *types.Func) string {
return pkg + p.Name()
}

// Federated graphs have the types _Entity and _Service. With default Go struct
// name generation, those become `Service`, which can conflict with users
// of this library who have their own `type Service`. Special case handle the
// federated entity names
var internalNames = map[string]string{
"_Entity": "GqlgenEntity",
"_Service": "GqlgenService",
}

func ToGo(name string) string {
if name == "_" {
return "_"
}

internalName, hasInternalName := internalNames[name]
if hasInternalName {
return internalName
}

runes := make([]rune, 0, len(name))

wordWalker(name, func(info *wordInfo) {
Expand Down
5 changes: 5 additions & 0 deletions codegen/templates/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func TestToGo(t *testing.T) {
require.Equal(t, "RelatedUrls", ToGo("RelatedUrls"))
require.Equal(t, "ITicket", ToGo("ITicket"))
require.Equal(t, "FooTicket", ToGo("fooTicket"))

require.Equal(t, "GqlgenEntity", ToGo("_Entity"))
require.Equal(t, "GqlgenService", ToGo("_Service"))
require.Equal(t, "Entity", ToGo("Entity"))
require.Equal(t, "Service", ToGo("Service"))
}

func TestToGoPrivate(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions example/federation/accounts/graph/generated/federation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions example/federation/accounts/graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/federation/accounts/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions example/federation/products/graph/generated/federation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions example/federation/products/graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/federation/products/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions example/federation/reviews/graph/generated/federation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a3a7ffe

Please sign in to comment.