Skip to content

Commit

Permalink
Merge branch '99designs:master' into codegen/configurable-executableS…
Browse files Browse the repository at this point in the history
…chema
  • Loading branch information
gitxiongpan authored Sep 28, 2023
2 parents c270df5 + 4e8d8c7 commit 7bc43de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/content/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ Returning to `graph/schema.resolvers.go`, let's implement the bodies of those au

```go
func (r *mutationResolver) CreateTodo(ctx context.Context, input model.NewTodo) (*model.Todo, error) {
rand, _ := rand.Int(rand.Reader, big.NewInt(100))
randNumber, _ := rand.Int(rand.Reader, big.NewInt(100))
todo := &model.Todo{
Text: input.Text,
ID: fmt.Sprintf("T%d", rand),
ID: fmt.Sprintf("T%d", randNumber),
User: &model.User{ID: input.UserID, Name: "user " + input.UserID},
}
r.todos = append(r.todos, todo)
Expand Down Expand Up @@ -250,10 +250,10 @@ And run `go run github.com/99designs/gqlgen generate`.
Now if we look in `graph/schema.resolvers.go` we can see a new resolver, lets implement it and fix `CreateTodo`.
```go
func (r *mutationResolver) CreateTodo(ctx context.Context, input model.NewTodo) (*model.Todo, error) {
randNumber, _ := rand.Int(rand.Reader, big.NewInt(100))
todo := &model.Todo{
Text: input.Text,
ID: fmt.Sprintf("T%d", rand.Int()),
User: &model.User{ID: input.UserID, Name: "user " + input.UserID},
ID: fmt.Sprintf("T%d", randNumber),
UserID: input.UserID,
}
r.todos = append(r.todos, todo)
Expand Down
13 changes: 13 additions & 0 deletions plugin/federation/federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func (f *federation) MutateConfig(cfg *config.Config) error {
"_Any": {
Model: config.StringList{"github.com/99designs/gqlgen/graphql.Map"},
},
"federation__Scope": {
Model: config.StringList{"github.com/99designs/gqlgen/graphql.String"},
},
}

for typeName, entry := range builtins {
Expand All @@ -80,6 +83,8 @@ func (f *federation) MutateConfig(cfg *config.Config) error {
cfg.Directives["tag"] = config.DirectiveConfig{SkipRuntime: true}
cfg.Directives["override"] = config.DirectiveConfig{SkipRuntime: true}
cfg.Directives["inaccessible"] = config.DirectiveConfig{SkipRuntime: true}
cfg.Directives["authenticated"] = config.DirectiveConfig{SkipRuntime: true}
cfg.Directives["requiresScopes"] = config.DirectiveConfig{SkipRuntime: true}
}

return nil
Expand All @@ -101,6 +106,7 @@ func (f *federation) InjectSourceEarly() *ast.Source {
`
} else if f.Version == 2 {
input += `
directive @authenticated on FIELD_DEFINITION | OBJECT | INTERFACE | SCALAR | ENUM
directive @composeDirective(name: String!) repeatable on SCHEMA
directive @extends on OBJECT | INTERFACE
directive @external on OBJECT | FIELD_DEFINITION
Expand All @@ -121,6 +127,12 @@ func (f *federation) InjectSourceEarly() *ast.Source {
directive @override(from: String!) on FIELD_DEFINITION
directive @provides(fields: FieldSet!) on FIELD_DEFINITION
directive @requires(fields: FieldSet!) on FIELD_DEFINITION
directive @requiresScopes(scopes: [[federation__Scope!]!]!) on
| FIELD_DEFINITION
| OBJECT
| INTERFACE
| SCALAR
| ENUM
directive @shareable repeatable on FIELD_DEFINITION | OBJECT
directive @tag(name: String!) repeatable on
| ARGUMENT_DEFINITION
Expand All @@ -135,6 +147,7 @@ func (f *federation) InjectSourceEarly() *ast.Source {
| UNION
scalar _Any
scalar FieldSet
scalar federation__Scope
`
}
return &ast.Source{
Expand Down

0 comments on commit 7bc43de

Please sign in to comment.