~edwargix/git.sr.ht

f97f63dbfa7b51e6dcfaebef9be87d18d3e5349a — Adnan Maolood 2 years ago 2506b8b
api/graph: Remove repository query

Remove the repository query since it can be used to enumerate unlisted
repositories by ID.
3 files changed, 0 insertions(+), 117 deletions(-)

M api/graph/api/generated.go
M api/graph/schema.graphqls
M api/graph/schema.resolvers.go
M api/graph/api/generated.go => api/graph/api/generated.go +0 -110
@@ 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) {

M api/graph/schema.graphqls => api/graph/schema.graphqls +0 -3
@@ 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)


M api/graph/schema.resolvers.go => api/graph/schema.resolvers.go +0 -4
@@ 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)
}