From f97f63dbfa7b51e6dcfaebef9be87d18d3e5349a Mon Sep 17 00:00:00 2001 From: Adnan Maolood Date: Tue, 18 Jan 2022 20:34:15 -0500 Subject: [PATCH] api/graph: Remove repository query Remove the repository query since it can be used to enumerate unlisted repositories by ID. --- api/graph/api/generated.go | 110 ---------------------------------- api/graph/schema.graphqls | 3 - api/graph/schema.resolvers.go | 4 -- 3 files changed, 117 deletions(-) diff --git a/api/graph/api/generated.go b/api/graph/api/generated.go index fab27d7..b1f302d 100644 --- a/api/graph/api/generated.go +++ b/api/graph/api/generated.go @@ -134,7 +134,6 @@ type ComplexityRoot struct { Query struct { Me func(childComplexity int) int Repositories func(childComplexity int, cursor *model1.Cursor, filter *model1.Filter) int - Repository func(childComplexity int, id int) int RepositoryByName func(childComplexity int, name string) int RepositoryByOwner func(childComplexity int, owner string, repo string) int User func(childComplexity int, username string) int @@ -317,7 +316,6 @@ type QueryResolver interface { Me(ctx context.Context) (*model.User, error) User(ctx context.Context, username string) (*model.User, error) Repositories(ctx context.Context, cursor *model1.Cursor, filter *model1.Filter) (*model.RepositoryCursor, error) - Repository(ctx context.Context, id int) (*model.Repository, error) RepositoryByName(ctx context.Context, name string) (*model.Repository, error) RepositoryByOwner(ctx context.Context, owner string, repo string) (*model.Repository, error) UserWebhooks(ctx context.Context, cursor *model1.Cursor) (*model.WebhookSubscriptionCursor, error) @@ -733,18 +731,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Repositories(childComplexity, args["cursor"].(*model1.Cursor), args["filter"].(*model1.Filter)), true - case "Query.repository": - if e.complexity.Query.Repository == nil { - break - } - - args, err := ec.field_Query_repository_args(context.TODO(), rawArgs) - if err != nil { - return 0, false - } - - return e.complexity.Query.Repository(childComplexity, args["id"].(int)), true - case "Query.repositoryByName": if e.complexity.Query.RepositoryByName == nil { break @@ -2060,9 +2046,6 @@ type Query { """ repositories(cursor: Cursor, filter: Filter): RepositoryCursor @access(scope: REPOSITORIES, kind: RO) - "Returns a specific repository by ID." - repository(id: Int!): Repository @access(scope: REPOSITORIES, kind: RO) - "Returns a specific repository, owned by the authenticated user." repositoryByName(name: String!): Repository @access(scope: REPOSITORIES, kind: RO) @@ -2484,21 +2467,6 @@ func (ec *executionContext) field_Query_repositoryByOwner_args(ctx context.Conte return args, nil } -func (ec *executionContext) field_Query_repository_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { - var err error - args := map[string]interface{}{} - var arg0 int - if tmp, ok := rawArgs["id"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id")) - arg0, err = ec.unmarshalNInt2int(ctx, tmp) - if err != nil { - return nil, err - } - } - args["id"] = arg0 - return args, nil -} - func (ec *executionContext) field_Query_userWebhook_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -4783,73 +4751,6 @@ func (ec *executionContext) _Query_repositories(ctx context.Context, field graph return ec.marshalORepositoryCursor2ᚖgitᚗsrᚗhtᚋאsircmpwnᚋgitᚗsrᚗhtᚋapiᚋgraphᚋmodelᚐRepositoryCursor(ctx, field.Selections, res) } -func (ec *executionContext) _Query_repository(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = graphql.Null - } - }() - fc := &graphql.FieldContext{ - Object: "Query", - Field: field, - Args: nil, - IsMethod: true, - IsResolver: true, - } - - ctx = graphql.WithFieldContext(ctx, fc) - rawArgs := field.ArgumentMap(ec.Variables) - args, err := ec.field_Query_repository_args(ctx, rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - fc.Args = args - resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { - directive0 := func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Repository(rctx, args["id"].(int)) - } - directive1 := func(ctx context.Context) (interface{}, error) { - scope, err := ec.unmarshalNAccessScope2gitᚗsrᚗhtᚋאsircmpwnᚋgitᚗsrᚗhtᚋapiᚋgraphᚋmodelᚐAccessScope(ctx, "REPOSITORIES") - if err != nil { - return nil, err - } - kind, err := ec.unmarshalNAccessKind2gitᚗsrᚗhtᚋאsircmpwnᚋgitᚗsrᚗhtᚋapiᚋgraphᚋmodelᚐAccessKind(ctx, "RO") - if err != nil { - return nil, err - } - if ec.directives.Access == nil { - return nil, errors.New("directive access is not implemented") - } - return ec.directives.Access(ctx, nil, directive0, scope, kind) - } - - tmp, err := directive1(rctx) - if err != nil { - return nil, graphql.ErrorOnPath(ctx, err) - } - if tmp == nil { - return nil, nil - } - if data, ok := tmp.(*model.Repository); ok { - return data, nil - } - return nil, fmt.Errorf(`unexpected type %T from directive, should be *git.sr.ht/~sircmpwn/git.sr.ht/api/graph/model.Repository`, tmp) - }) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - if resTmp == nil { - return graphql.Null - } - res := resTmp.(*model.Repository) - fc.Result = res - return ec.marshalORepository2ᚖgitᚗsrᚗhtᚋאsircmpwnᚋgitᚗsrᚗhtᚋapiᚋgraphᚋmodelᚐRepository(ctx, field.Selections, res) -} - func (ec *executionContext) _Query_repositoryByName(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -10510,17 +10411,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr res = ec._Query_repositories(ctx, field) return res }) - case "repository": - field := field - out.Concurrently(i, func() (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._Query_repository(ctx, field) - return res - }) case "repositoryByName": field := field out.Concurrently(i, func() (res graphql.Marshaler) { diff --git a/api/graph/schema.graphqls b/api/graph/schema.graphqls index a75662b..8b08523 100644 --- a/api/graph/schema.graphqls +++ b/api/graph/schema.graphqls @@ -471,9 +471,6 @@ type Query { """ repositories(cursor: Cursor, filter: Filter): RepositoryCursor @access(scope: REPOSITORIES, kind: RO) - "Returns a specific repository by ID." - repository(id: Int!): Repository @access(scope: REPOSITORIES, kind: RO) - "Returns a specific repository, owned by the authenticated user." repositoryByName(name: String!): Repository @access(scope: REPOSITORIES, kind: RO) diff --git a/api/graph/schema.resolvers.go b/api/graph/schema.resolvers.go index b6f8602..5868b5c 100644 --- a/api/graph/schema.resolvers.go +++ b/api/graph/schema.resolvers.go @@ -805,10 +805,6 @@ func (r *queryResolver) Repositories(ctx context.Context, cursor *coremodel.Curs return &model.RepositoryCursor{repos, cursor}, nil } -func (r *queryResolver) Repository(ctx context.Context, id int) (*model.Repository, error) { - return loaders.ForContext(ctx).RepositoriesByID.Load(id) -} - func (r *queryResolver) RepositoryByName(ctx context.Context, name string) (*model.Repository, error) { return loaders.ForContext(ctx).RepositoriesByName.Load(name) } -- 2.38.4