diff --git a/docs/content/getting-started.md b/docs/content/getting-started.md index 985c16e0315..ba3c442406b 100644 --- a/docs/content/getting-started.md +++ b/docs/content/getting-started.md @@ -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) @@ -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) diff --git a/plugin/federation/federation.go b/plugin/federation/federation.go index 9df9b8a23f7..99a1d312b01 100644 --- a/plugin/federation/federation.go +++ b/plugin/federation/federation.go @@ -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 { @@ -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 @@ -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 @@ -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 @@ -135,6 +147,7 @@ func (f *federation) InjectSourceEarly() *ast.Source { | UNION scalar _Any scalar FieldSet + scalar federation__Scope ` } return &ast.Source{