Skip to content

Commit

Permalink
add simple gql federation server
Browse files Browse the repository at this point in the history
  • Loading branch information
chedom committed Apr 11, 2021
1 parent 7f28e95 commit eb837a2
Show file tree
Hide file tree
Showing 43 changed files with 10,753 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
.DS_Store
pkg/parser/testdata/lotto.graphql
*node_modules*
/vendor
*vendor*
55 changes: 55 additions & 0 deletions examples/federation/accounts/gqlgen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Where are all the schema files located? globs are supported eg src/**/*.graphqls
schema:
- graph/*.graphqls

# Where should the generated server code go?
exec:
filename: graph/generated/generated.go
package: generated

federation:
filename: graph/generated/federation.go
package: generated

# Where should any generated models go?
model:
filename: graph/model/models_gen.go
package: model

# Where should the resolver implementations go?
resolver:
layout: follow-schema
dir: graph
package: graph

# Optional: turn on use `gqlgen:"fieldName"` tags in your models
# struct_tag: json

# Optional: turn on to use []Thing instead of []*Thing
# omit_slice_element_pointers: false

# Optional: set to speed up generation time by not performing a final validation pass.
# skip_validation: true

# gqlgen will search for any type names in the schema in these go packages
# if they match it will use them, otherwise it will generate them.
autobind:
- "github.com/99designs/gqlgen/example/federation/accounts/graph/model"

# This section declares type mapping between the GraphQL and go type systems
#
# The first line in each type will be used as defaults for resolver arguments and
# modelgen, the others will be allowed when binding to fields. Configure them to
# your liking
models:
ID:
model:
- github.com/99designs/gqlgen/graphql.ID
- github.com/99designs/gqlgen/graphql.Int
- github.com/99designs/gqlgen/graphql.Int64
- github.com/99designs/gqlgen/graphql.Int32
Int:
model:
- github.com/99designs/gqlgen/graphql.Int
- github.com/99designs/gqlgen/graphql.Int64
- github.com/99designs/gqlgen/graphql.Int32
28 changes: 28 additions & 0 deletions examples/federation/accounts/graph/entity.resolvers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package graph

// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.

import (
"context"
generated1 "federation/accounts/graph/generated"

"github.com/99designs/gqlgen/example/federation/accounts/graph/model"
)

func (r *entityResolver) FindUserByID(ctx context.Context, id string) (*model.User, error) {
name := "User " + id
if id == "1234" {
name = "Me"
}

return &model.User{
ID: id,
Username: name,
}, nil
}

// Entity returns generated1.EntityResolver implementation.
func (r *Resolver) Entity() generated1.EntityResolver { return &entityResolver{r} }

type entityResolver struct{ *Resolver }
61 changes: 61 additions & 0 deletions examples/federation/accounts/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 eb837a2

Please sign in to comment.