From 55cdb4961c9d41b503c39e5289496de0457d93ea Mon Sep 17 00:00:00 2001 From: Erik Seliger Date: Thu, 8 Aug 2024 14:18:37 +0200 Subject: [PATCH] graphqlbackend: Move utils to internal/ (#64117) The utils are currently used outside of cmd/frontend, so to break the internal -> cmd import I'm moving and merging the utils package with internal/gqlutil. Test plan: Just moved around and renamed a package, the go compiler doesn't complain. --- cmd/frontend/graphqlbackend/BUILD.bazel | 2 - .../graphqlbackend/access_requests.go | 9 ++--- .../graphqlbackend/access_requests_test.go | 4 +- cmd/frontend/graphqlbackend/access_tokens.go | 10 ++--- .../graphqlbackend/affiliated_namespaces.go | 6 +-- cmd/frontend/graphqlbackend/auth_providers.go | 6 +-- cmd/frontend/graphqlbackend/authz.go | 12 +++--- .../graphqlbackend/background_jobs.go | 8 ++-- cmd/frontend/graphqlbackend/batches.go | 25 ++++++------- cmd/frontend/graphqlbackend/code_hosts.go | 8 ++-- cmd/frontend/graphqlbackend/code_monitors.go | 11 +++--- cmd/frontend/graphqlbackend/dotcom.go | 11 +++--- cmd/frontend/graphqlbackend/embeddings.go | 5 +-- cmd/frontend/graphqlbackend/event_logs.go | 8 ++-- .../graphqlbackend/executor_connection.go | 8 ++-- .../graphqlbackend/executor_secret.go | 3 +- .../executor_secret_access_logs_connection.go | 8 ++-- .../executor_secret_connection.go | 8 ++-- .../graphqlbackend/executor_secrets.go | 4 +- cmd/frontend/graphqlbackend/executors.go | 6 +-- .../graphqlbackend/external_accounts.go | 10 ++--- .../graphqlbackend/external_service.go | 5 +-- .../graphqlbackend/external_services.go | 22 +++++------ .../graphqlbackend/external_services_test.go | 28 +++++++------- cmd/frontend/graphqlbackend/git_commit.go | 4 +- cmd/frontend/graphqlbackend/git_commits.go | 10 ++--- cmd/frontend/graphqlbackend/git_tree.go | 4 +- .../graphqlbackend/git_tree_history.go | 6 +-- cmd/frontend/graphqlbackend/git_tree_test.go | 12 +++--- cmd/frontend/graphqlbackend/githubapps.go | 3 +- cmd/frontend/graphqlbackend/gitserver.go | 6 +-- .../graphqlbackend/graphqlutil/BUILD.bazel | 37 ------------------- .../graphqlbackend/graphqlutil/doc.go | 2 - cmd/frontend/graphqlbackend/guardrails.go | 6 +-- cmd/frontend/graphqlbackend/insights.go | 9 ++--- cmd/frontend/graphqlbackend/namespaces.go | 6 +-- cmd/frontend/graphqlbackend/notebooks.go | 5 +-- cmd/frontend/graphqlbackend/org.go | 7 ++-- cmd/frontend/graphqlbackend/org_members.go | 5 +-- cmd/frontend/graphqlbackend/org_test.go | 4 +- cmd/frontend/graphqlbackend/orgs.go | 8 ++-- .../graphqlbackend/outbound_requests.go | 7 ++-- .../graphqlbackend/outbound_webhook_logs.go | 9 ++--- .../graphqlbackend/outbound_webhooks.go | 10 ++--- cmd/frontend/graphqlbackend/own.go | 5 +-- .../graphqlbackend/package_repo_filters.go | 4 +- cmd/frontend/graphqlbackend/package_repos.go | 16 ++++---- cmd/frontend/graphqlbackend/permissions.go | 8 ++-- .../graphqlbackend/permissions_sync_jobs.go | 4 +- cmd/frontend/graphqlbackend/prompts.go | 5 +-- cmd/frontend/graphqlbackend/rbac.go | 7 ++-- .../graphqlbackend/recorded_commands.go | 9 ++--- cmd/frontend/graphqlbackend/repositories.go | 12 +++--- cmd/frontend/graphqlbackend/repository.go | 3 +- .../graphqlbackend/repository_comparison.go | 12 +++--- .../graphqlbackend/repository_contributors.go | 10 ++--- .../graphqlbackend/repository_external.go | 4 +- .../graphqlbackend/repository_git_refs.go | 8 ++-- .../graphqlbackend/repository_metadata.go | 18 ++++----- cmd/frontend/graphqlbackend/role.go | 7 ++-- cmd/frontend/graphqlbackend/roles.go | 8 ++-- cmd/frontend/graphqlbackend/saved_searches.go | 5 +-- cmd/frontend/graphqlbackend/search.go | 6 +-- .../graphqlbackend/search_contexts.go | 3 +- cmd/frontend/graphqlbackend/search_jobs.go | 7 ++-- cmd/frontend/graphqlbackend/site.go | 5 +-- .../graphqlbackend/site_config_change_test.go | 8 ++-- cmd/frontend/graphqlbackend/site_test.go | 32 ++++++++-------- .../graphqlbackend/slow_requests_tracer.go | 7 ++-- .../graphqlbackend/survey_responses.go | 4 +- cmd/frontend/graphqlbackend/symbols.go | 8 ++-- cmd/frontend/graphqlbackend/teams.go | 22 +++++------ cmd/frontend/graphqlbackend/telemetry.go | 3 +- cmd/frontend/graphqlbackend/user.go | 23 +++++------- cmd/frontend/graphqlbackend/users.go | 15 ++++---- cmd/frontend/graphqlbackend/viewer.go | 4 +- cmd/frontend/graphqlbackend/webhook_logs.go | 9 ++--- .../graphqlbackend/webhook_logs_test.go | 10 ++--- cmd/frontend/graphqlbackend/webhooks.go | 6 +-- .../internal/authz/resolvers/BUILD.bazel | 3 +- .../authz/resolvers/permissions_info.go | 18 ++++----- .../authz/resolvers/permissions_sync_jobs.go | 5 +-- .../resolvers/permissions_sync_jobs_test.go | 4 +- .../internal/authz/resolvers/repositories.go | 14 +++---- .../internal/authz/resolvers/resolver.go | 4 +- .../internal/authz/resolvers/users.go | 14 +++---- .../internal/batches/resolvers/BUILD.bazel | 1 - .../resolvers/batch_change_connection.go | 8 ++-- .../resolvers/batch_spec_connection.go | 8 ++-- .../batch_spec_workspace_connection.go | 8 ++-- .../batch_spec_workspace_file_connection.go | 8 ++-- .../resolvers/batch_spec_workspace_step.go | 7 ++-- .../resolvers/bulk_operation_connection.go | 8 ++-- .../changeset_apply_preview_connection.go | 10 ++--- .../batches/resolvers/changeset_connection.go | 8 ++-- .../resolvers/changeset_event_connection.go | 8 ++-- .../resolvers/changeset_spec_connection.go | 8 ++-- .../batches/resolvers/code_host_connection.go | 12 +++--- .../internal/batches/resolvers/resolver.go | 7 ++-- .../codemonitors/resolvers/BUILD.bazel | 1 - .../codemonitors/resolvers/resolvers.go | 31 ++++++++-------- .../dotcom/productsubscription/BUILD.bazel | 1 - .../productsubscription/licenses_graphql.go | 5 +-- .../subscriptions_graphql.go | 7 ++-- .../internal/embeddings/resolvers/BUILD.bazel | 1 - .../resolvers/repo_embedding_jobs.go | 7 ++-- .../resolvers/repo_embedding_jobs_test.go | 2 +- .../embeddings/resolvers/resolvers.go | 4 +- .../internal/guardrails/resolvers/BUILD.bazel | 2 +- .../internal/guardrails/resolvers/resolver.go | 6 +-- .../internal/insights/resolvers/BUILD.bazel | 1 - .../insights/resolvers/admin_resolver.go | 7 ++-- .../insights/resolvers/dashboard_resolvers.go | 12 +++--- .../insights/resolvers/disabled_resolver.go | 4 +- .../resolvers/insight_view_resolvers.go | 8 ++-- .../internal/notebooks/resolvers/BUILD.bazel | 1 - .../internal/notebooks/resolvers/resolvers.go | 7 ++-- .../notebooks/resolvers/stars_resolvers.go | 7 ++-- .../internal/own/resolvers/BUILD.bazel | 1 - .../own/resolvers/codeowners_resolvers.go | 11 +++--- .../internal/own/resolvers/resolvers.go | 7 ++-- .../internal/prompts/resolvers/BUILD.bazel | 3 +- .../prompts/resolvers/connection_test.go | 14 +++---- .../internal/prompts/resolvers/resolvers.go | 5 +-- .../repos/webhooks/resolvers/BUILD.bazel | 1 - .../repos/webhooks/resolvers/resolver.go | 7 ++-- .../savedsearches/resolvers/BUILD.bazel | 3 +- .../resolvers/connection_test.go | 14 +++---- .../savedsearches/resolvers/resolvers.go | 5 +-- .../internal/search/resolvers/BUILD.bazel | 1 - .../internal/search/resolvers/resolver.go | 10 ++--- .../searchcontexts/resolvers/BUILD.bazel | 1 - .../searchcontexts/resolvers/resolvers.go | 7 ++-- .../internal/telemetry/resolvers/BUILD.bazel | 1 - .../resolvers/exportedevents_resolvers.go | 13 +++---- .../codenav/transport/graphql/BUILD.bazel | 2 +- .../graphql/root_resolver_code_graph.go | 16 ++++---- internal/codeintel/resolvers/BUILD.bazel | 1 - internal/codeintel/resolvers/codenav.go | 4 +- internal/gqlutil/BUILD.bazel | 30 +++++++++++++-- .../gqlutil}/connection.go | 2 +- .../gqlutil}/connection_resolver.go | 2 +- .../gqlutil}/connection_resolver_test.go | 2 +- .../gqlutil}/cursors.go | 2 +- internal/gqlutil/doc.go | 2 + .../gqlutil}/offset.go | 2 +- .../gqlutil}/page_info.go | 2 +- .../gqlutil}/slice_connection_resolver.go | 2 +- .../slice_connection_resolver_test.go | 2 +- 149 files changed, 535 insertions(+), 621 deletions(-) delete mode 100644 cmd/frontend/graphqlbackend/graphqlutil/BUILD.bazel delete mode 100644 cmd/frontend/graphqlbackend/graphqlutil/doc.go rename {cmd/frontend/graphqlbackend/graphqlutil => internal/gqlutil}/connection.go (97%) rename {cmd/frontend/graphqlbackend/graphqlutil => internal/gqlutil}/connection_resolver.go (99%) rename {cmd/frontend/graphqlbackend/graphqlutil => internal/gqlutil}/connection_resolver_test.go (99%) rename {cmd/frontend/graphqlbackend/graphqlutil => internal/gqlutil}/cursors.go (98%) create mode 100644 internal/gqlutil/doc.go rename {cmd/frontend/graphqlbackend/graphqlutil => internal/gqlutil}/offset.go (94%) rename {cmd/frontend/graphqlbackend/graphqlutil => internal/gqlutil}/page_info.go (96%) rename {cmd/frontend/graphqlbackend/graphqlutil => internal/gqlutil}/slice_connection_resolver.go (98%) rename {cmd/frontend/graphqlbackend/graphqlutil => internal/gqlutil}/slice_connection_resolver_test.go (98%) diff --git a/cmd/frontend/graphqlbackend/BUILD.bazel b/cmd/frontend/graphqlbackend/BUILD.bazel index 2c31295afb9..c867ddb4bb8 100644 --- a/cmd/frontend/graphqlbackend/BUILD.bazel +++ b/cmd/frontend/graphqlbackend/BUILD.bazel @@ -237,7 +237,6 @@ go_library( "//cmd/frontend/auth", "//cmd/frontend/envvar", "//cmd/frontend/graphqlbackend/externallink", - "//cmd/frontend/graphqlbackend/graphqlutil", "//cmd/frontend/hubspot", "//cmd/frontend/hubspot/hubspotutil", "//cmd/frontend/internal/auth/providers", @@ -479,7 +478,6 @@ go_test( "//cmd/frontend/enterprise", "//cmd/frontend/graphqlbackend/apitest", "//cmd/frontend/graphqlbackend/externallink", - "//cmd/frontend/graphqlbackend/graphqlutil", "//cmd/frontend/internal/auth/providers", "//cmd/frontend/internal/auth/userpasswd", "//cmd/frontend/internal/backend", diff --git a/cmd/frontend/graphqlbackend/access_requests.go b/cmd/frontend/graphqlbackend/access_requests.go index 90665b03a38..004aa9d3304 100644 --- a/cmd/frontend/graphqlbackend/access_requests.go +++ b/cmd/frontend/graphqlbackend/access_requests.go @@ -6,7 +6,6 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/graph-gophers/graphql-go/relay" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gqlutil" @@ -16,10 +15,10 @@ import ( type AccessRequestsArgs struct { database.AccessRequestsFilterArgs - graphqlutil.ConnectionResolverArgs + gqlutil.ConnectionResolverArgs } -func (r *schemaResolver) AccessRequests(ctx context.Context, args *AccessRequestsArgs) (*graphqlutil.ConnectionResolver[*accessRequestResolver], error) { +func (r *schemaResolver) AccessRequests(ctx context.Context, args *AccessRequestsArgs) (*gqlutil.ConnectionResolver[*accessRequestResolver], error) { // 🚨 SECURITY: Only site admins can see access requests. if err := auth.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil { return nil, err @@ -31,12 +30,12 @@ func (r *schemaResolver) AccessRequests(ctx context.Context, args *AccessRequest } reverse := false - connectionOptions := graphqlutil.ConnectionResolverOptions{ + connectionOptions := gqlutil.ConnectionResolverOptions{ Reverse: &reverse, OrderBy: database.OrderBy{{Field: string(database.AccessRequestListID)}}, Ascending: false, } - return graphqlutil.NewConnectionResolver[*accessRequestResolver](connectionStore, &args.ConnectionResolverArgs, &connectionOptions) + return gqlutil.NewConnectionResolver[*accessRequestResolver](connectionStore, &args.ConnectionResolverArgs, &connectionOptions) } type accessRequestConnectionStore struct { diff --git a/cmd/frontend/graphqlbackend/access_requests_test.go b/cmd/frontend/graphqlbackend/access_requests_test.go index 0d43c4bdfee..5c33f711288 100644 --- a/cmd/frontend/graphqlbackend/access_requests_test.go +++ b/cmd/frontend/graphqlbackend/access_requests_test.go @@ -13,12 +13,12 @@ import ( "github.com/sourcegraph/log/logtest" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/database/dbmocks" "github.com/sourcegraph/sourcegraph/internal/database/dbtest" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" ) @@ -300,5 +300,5 @@ func TestAccessRequestConnectionStore(t *testing.T) { db: db, } - graphqlutil.TestConnectionResolverStoreSuite(t, connectionStore, nil) + gqlutil.TestConnectionResolverStoreSuite(t, connectionStore, nil) } diff --git a/cmd/frontend/graphqlbackend/access_tokens.go b/cmd/frontend/graphqlbackend/access_tokens.go index 5d1abdaff46..20b94dcdbe5 100644 --- a/cmd/frontend/graphqlbackend/access_tokens.go +++ b/cmd/frontend/graphqlbackend/access_tokens.go @@ -11,7 +11,6 @@ import ( "github.com/sourcegraph/log" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/backend" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/auth" @@ -19,6 +18,7 @@ import ( "github.com/sourcegraph/sourcegraph/internal/conf" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/dotcom" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -265,7 +265,7 @@ func (r *schemaResolver) DeleteAccessToken(ctx context.Context, args *deleteAcce } func (r *siteResolver) AccessTokens(ctx context.Context, args *struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs }) (*accessTokenConnectionResolver, error) { // 🚨 SECURITY: Only site admins can list all access tokens. This is safe as the // token values themselves are not stored in our database. @@ -279,7 +279,7 @@ func (r *siteResolver) AccessTokens(ctx context.Context, args *struct { } func (r *UserResolver) AccessTokens(ctx context.Context, args *struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs }) (*accessTokenConnectionResolver, error) { // 🚨 SECURITY: Only site admins and the user can list a user's access tokens. if err := auth.CheckSiteAdminOrSameUser(ctx, r.db, r.user.ID); err != nil { @@ -340,12 +340,12 @@ func (r *accessTokenConnectionResolver) TotalCount(ctx context.Context) (int32, return int32(count), err } -func (r *accessTokenConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *accessTokenConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { accessTokens, err := r.compute(ctx) if err != nil { return nil, err } - return graphqlutil.HasNextPage(r.opt.LimitOffset != nil && len(accessTokens) > r.opt.Limit), nil + return gqlutil.HasNextPage(r.opt.LimitOffset != nil && len(accessTokens) > r.opt.Limit), nil } func getMaxExpiryDuration(allowedOptionsInDays []int) (int32, error) { diff --git a/cmd/frontend/graphqlbackend/affiliated_namespaces.go b/cmd/frontend/graphqlbackend/affiliated_namespaces.go index d3d41948b99..dc03b32fb5c 100644 --- a/cmd/frontend/graphqlbackend/affiliated_namespaces.go +++ b/cmd/frontend/graphqlbackend/affiliated_namespaces.go @@ -3,11 +3,11 @@ package graphqlbackend import ( "context" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) -func (r *UserResolver) AffiliatedNamespaces(ctx context.Context) (graphqlutil.SliceConnectionResolver[*NamespaceResolver], error) { +func (r *UserResolver) AffiliatedNamespaces(ctx context.Context) (gqlutil.SliceConnectionResolver[*NamespaceResolver], error) { // Start with the user's own account (which is a namespace they are always affiliated with). namespaces := []*NamespaceResolver{ {Namespace: r}, @@ -30,6 +30,6 @@ func (r *UserResolver) AffiliatedNamespaces(ctx context.Context) (graphqlutil.Sl return newNamespaceConnection(namespaces), nil } -func (visitorResolver) AffiliatedNamespaces(context.Context) (graphqlutil.SliceConnectionResolver[*NamespaceResolver], error) { +func (visitorResolver) AffiliatedNamespaces(context.Context) (gqlutil.SliceConnectionResolver[*NamespaceResolver], error) { return newNamespaceConnection(nil), nil } diff --git a/cmd/frontend/graphqlbackend/auth_providers.go b/cmd/frontend/graphqlbackend/auth_providers.go index 096a843c910..f0d035f520c 100644 --- a/cmd/frontend/graphqlbackend/auth_providers.go +++ b/cmd/frontend/graphqlbackend/auth_providers.go @@ -3,8 +3,8 @@ package graphqlbackend import ( "context" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/auth/providers" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) func (r *siteResolver) AuthProviders(ctx context.Context) (*authProviderConnectionResolver, error) { @@ -30,6 +30,6 @@ func (r *authProviderConnectionResolver) Nodes(ctx context.Context) ([]*authProv } func (r *authProviderConnectionResolver) TotalCount() int32 { return int32(len(r.authProviders)) } -func (r *authProviderConnectionResolver) PageInfo() *graphqlutil.PageInfo { - return graphqlutil.HasNextPage(false) +func (r *authProviderConnectionResolver) PageInfo() *gqlutil.PageInfo { + return gqlutil.HasNextPage(false) } diff --git a/cmd/frontend/graphqlbackend/authz.go b/cmd/frontend/graphqlbackend/authz.go index 87eb6ab1b86..09078ab0a45 100644 --- a/cmd/frontend/graphqlbackend/authz.go +++ b/cmd/frontend/graphqlbackend/authz.go @@ -5,8 +5,6 @@ import ( "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" - "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" ) @@ -26,7 +24,7 @@ type AuthzResolver interface { UsersWithPendingPermissions(ctx context.Context) ([]string, error) AuthorizedUsers(ctx context.Context, args *RepoAuthorizedUserArgs) (UserConnectionResolver, error) BitbucketProjectPermissionJobs(ctx context.Context, args *BitbucketProjectPermissionJobsArgs) (BitbucketProjectsPermissionJobsResolver, error) - PermissionsSyncJobs(ctx context.Context, args ListPermissionsSyncJobsArgs) (*graphqlutil.ConnectionResolver[PermissionsSyncJobResolver], error) + PermissionsSyncJobs(ctx context.Context, args ListPermissionsSyncJobsArgs) (*gqlutil.ConnectionResolver[PermissionsSyncJobResolver], error) PermissionsSyncingStats(ctx context.Context) (PermissionsSyncingStatsResolver, error) // RepositoryPermissionsInfo and UserPermissionsInfo are helpers functions. @@ -126,8 +124,8 @@ type PermissionsInfoResolver interface { UpdatedAt() *gqlutil.DateTime Source() *string Unrestricted(ctx context.Context) bool - Repositories(ctx context.Context, args PermissionsInfoRepositoriesArgs) (*graphqlutil.ConnectionResolver[PermissionsInfoRepositoryResolver], error) - Users(ctx context.Context, args PermissionsInfoUsersArgs) (*graphqlutil.ConnectionResolver[PermissionsInfoUserResolver], error) + Repositories(ctx context.Context, args PermissionsInfoRepositoriesArgs) (*gqlutil.ConnectionResolver[PermissionsInfoRepositoryResolver], error) + Users(ctx context.Context, args PermissionsInfoUsersArgs) (*gqlutil.ConnectionResolver[PermissionsInfoUserResolver], error) } type PermissionsInfoRepositoryResolver interface { @@ -138,7 +136,7 @@ type PermissionsInfoRepositoryResolver interface { } type PermissionsInfoRepositoriesArgs struct { - graphqlutil.ConnectionResolverArgs + gqlutil.ConnectionResolverArgs Query *string } @@ -150,7 +148,7 @@ type PermissionsInfoUserResolver interface { } type PermissionsInfoUsersArgs struct { - graphqlutil.ConnectionResolverArgs + gqlutil.ConnectionResolverArgs Query *string } diff --git a/cmd/frontend/graphqlbackend/background_jobs.go b/cmd/frontend/graphqlbackend/background_jobs.go index 9f3e23857f8..2bece51248f 100644 --- a/cmd/frontend/graphqlbackend/background_jobs.go +++ b/cmd/frontend/graphqlbackend/background_jobs.go @@ -6,7 +6,7 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/graph-gophers/graphql-go/relay" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" + "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/goroutine/recorder" "github.com/sourcegraph/sourcegraph/internal/gqlutil" @@ -120,16 +120,16 @@ func (r *backgroundJobConnectionResolver) TotalCount(context.Context) (int32, er return int32(len(resolvers)), nil } -func (r *backgroundJobConnectionResolver) PageInfo(context.Context) (*graphqlutil.PageInfo, error) { +func (r *backgroundJobConnectionResolver) PageInfo(context.Context) (*gqlutil.PageInfo, error) { resolvers, err := r.compute() if err != nil { return nil, err } if r.first != nil && *r.first > -1 && len(resolvers) > int(*r.first) { - return graphqlutil.NextPageCursor(string(resolvers[*r.first-1].ID())), nil + return gqlutil.NextPageCursor(string(resolvers[*r.first-1].ID())), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } func (r *backgroundJobConnectionResolver) compute() ([]*BackgroundJobResolver, error) { diff --git a/cmd/frontend/graphqlbackend/batches.go b/cmd/frontend/graphqlbackend/batches.go index 8702ed479f1..489e5a2d7be 100644 --- a/cmd/frontend/graphqlbackend/batches.go +++ b/cmd/frontend/graphqlbackend/batches.go @@ -8,7 +8,6 @@ import ( "github.com/sourcegraph/sourcegraph/lib/batches" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/externallink" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) @@ -304,14 +303,14 @@ type BatchChangesResolver interface { MaxUnlicensedChangesets(ctx context.Context) int32 - GetChangesetsByIDs(ctx context.Context, args *GetChangesetsByIDsArgs) (graphqlutil.SliceConnectionResolver[ChangesetResolver], error) + GetChangesetsByIDs(ctx context.Context, args *GetChangesetsByIDsArgs) (gqlutil.SliceConnectionResolver[ChangesetResolver], error) NodeResolvers() map[string]NodeByIDFunc } type BulkOperationConnectionResolver interface { TotalCount(ctx context.Context) (int32, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) Nodes(ctx context.Context) ([]BulkOperationResolver, error) } @@ -459,14 +458,14 @@ type ChangesetApplyPreviewConnectionStatsResolver interface { type ChangesetApplyPreviewConnectionResolver interface { TotalCount(ctx context.Context) (int32, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) Nodes(ctx context.Context) ([]ChangesetApplyPreviewResolver, error) Stats(ctx context.Context) (ChangesetApplyPreviewConnectionStatsResolver, error) } type ChangesetSpecConnectionResolver interface { TotalCount(ctx context.Context) (int32, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) Nodes(ctx context.Context) ([]ChangesetSpecResolver, error) } @@ -548,7 +547,7 @@ type ForkTargetInterface interface { type BatchChangesCodeHostConnectionResolver interface { Nodes(ctx context.Context) ([]BatchChangesCodeHostResolver, error) TotalCount(ctx context.Context) (int32, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) } type BatchChangesCodeHostResolver interface { @@ -681,18 +680,18 @@ type BatchChangeResolver interface { type BatchChangesConnectionResolver interface { Nodes(ctx context.Context) ([]BatchChangeResolver, error) TotalCount(ctx context.Context) (int32, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) } type BatchSpecConnectionResolver interface { Nodes(ctx context.Context) ([]BatchSpecResolver, error) TotalCount(ctx context.Context) (int32, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) } type BatchSpecWorkspaceFileConnectionResolver interface { TotalCount(ctx context.Context) (int32, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) Nodes(ctx context.Context) ([]BatchWorkspaceFileResolver, error) } @@ -754,7 +753,7 @@ type ChangesetsStatsResolver interface { type ChangesetsConnectionResolver interface { Nodes(ctx context.Context) ([]ChangesetResolver, error) TotalCount(ctx context.Context) (int32, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) } type ChangesetLabelResolver interface { @@ -842,7 +841,7 @@ type GitHubCommitVerificationResolver interface { type ChangesetEventsConnectionResolver interface { Nodes(ctx context.Context) ([]ChangesetEventResolver, error) TotalCount(ctx context.Context) (int32, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) } type ChangesetEventResolver interface { @@ -878,7 +877,7 @@ type BatchSpecWorkspaceResolutionResolver interface { type BatchSpecWorkspaceConnectionResolver interface { Nodes(ctx context.Context) ([]BatchSpecWorkspaceResolver, error) TotalCount(ctx context.Context) (int32, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) Stats(ctx context.Context) (BatchSpecWorkspacesStatsResolver, error) } @@ -948,7 +947,7 @@ type BatchSpecWorkspaceStagesResolver interface { type BatchSpecWorkspaceStepOutputLineConnectionResolver interface { TotalCount() (int32, error) - PageInfo() (*graphqlutil.PageInfo, error) + PageInfo() (*gqlutil.PageInfo, error) Nodes() ([]string, error) } diff --git a/cmd/frontend/graphqlbackend/code_hosts.go b/cmd/frontend/graphqlbackend/code_hosts.go index ec251047c37..02c2ed01d39 100644 --- a/cmd/frontend/graphqlbackend/code_hosts.go +++ b/cmd/frontend/graphqlbackend/code_hosts.go @@ -7,10 +7,10 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/graph-gophers/graphql-go/relay" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/errcode" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/oobmigration" "github.com/sourcegraph/sourcegraph/internal/types" ) @@ -90,15 +90,15 @@ func (r *codeHostConnectionResolver) TotalCount(ctx context.Context) (int32, err return r.db.CodeHosts().Count(ctx, opt) } -func (r *codeHostConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *codeHostConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { _, next, err := r.compute(ctx) if err != nil { return nil, err } if next != 0 { - return graphqlutil.NextPageCursor(string(MarshalCodeHostID(next))), nil + return gqlutil.NextPageCursor(string(MarshalCodeHostID(next))), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } diff --git a/cmd/frontend/graphqlbackend/code_monitors.go b/cmd/frontend/graphqlbackend/code_monitors.go index 0615a2074d7..114841c4515 100644 --- a/cmd/frontend/graphqlbackend/code_monitors.go +++ b/cmd/frontend/graphqlbackend/code_monitors.go @@ -5,7 +5,6 @@ import ( "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) @@ -39,7 +38,7 @@ type CodeMonitorsResolver interface { type MonitorConnectionResolver interface { Nodes() []MonitorResolver TotalCount() int32 - PageInfo() *graphqlutil.PageInfo + PageInfo() *gqlutil.PageInfo } type MonitorResolver interface { @@ -66,7 +65,7 @@ type MonitorQueryResolver interface { type MonitorTriggerEventConnectionResolver interface { Nodes() []MonitorTriggerEventResolver TotalCount() int32 - PageInfo() *graphqlutil.PageInfo + PageInfo() *gqlutil.PageInfo } type MonitorTriggerEventResolver interface { @@ -82,7 +81,7 @@ type MonitorTriggerEventResolver interface { type MonitorActionConnectionResolver interface { Nodes() []MonitorAction TotalCount() int32 - PageInfo() *graphqlutil.PageInfo + PageInfo() *gqlutil.PageInfo } type MonitorAction interface { @@ -125,13 +124,13 @@ type MonitorEmailRecipient interface { type MonitorActionEmailRecipientsConnectionResolver interface { Nodes() []NamespaceResolver TotalCount() int32 - PageInfo() *graphqlutil.PageInfo + PageInfo() *gqlutil.PageInfo } type MonitorActionEventConnectionResolver interface { Nodes() []MonitorActionEventResolver TotalCount() int32 - PageInfo() *graphqlutil.PageInfo + PageInfo() *gqlutil.PageInfo } type MonitorActionEventResolver interface { diff --git a/cmd/frontend/graphqlbackend/dotcom.go b/cmd/frontend/graphqlbackend/dotcom.go index 2b230f71827..7eea1fa46df 100644 --- a/cmd/frontend/graphqlbackend/dotcom.go +++ b/cmd/frontend/graphqlbackend/dotcom.go @@ -5,7 +5,6 @@ import ( "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) @@ -42,7 +41,7 @@ type ProductSubscription interface { Name() string Account(context.Context) (*UserResolver, error) ActiveLicense(context.Context) (ProductLicense, error) - ProductLicenses(context.Context, *graphqlutil.ConnectionArgs) (ProductLicenseConnection, error) + ProductLicenses(context.Context, *gqlutil.ConnectionArgs) (ProductLicenseConnection, error) CodyGatewayAccess() CodyGatewayAccess CreatedAt() gqlutil.DateTime IsArchived() bool @@ -77,7 +76,7 @@ type ProductSubscriptionArgs struct { } type ProductSubscriptionsArgs struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs Account *graphql.ID Query *string } @@ -87,7 +86,7 @@ type ProductSubscriptionsArgs struct { type ProductSubscriptionConnection interface { Nodes(context.Context) ([]ProductSubscription, error) TotalCount(context.Context) (int32, error) - PageInfo(context.Context) (*graphqlutil.PageInfo, error) + PageInfo(context.Context) (*gqlutil.PageInfo, error) } // ProductLicense is the interface for the GraphQL type ProductLicense. @@ -113,7 +112,7 @@ type ProductLicenseInput struct { } type ProductLicensesArgs struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs LicenseKeySubstring *string ProductSubscriptionID *graphql.ID } @@ -122,7 +121,7 @@ type ProductLicensesArgs struct { type ProductLicenseConnection interface { Nodes(context.Context) ([]ProductLicense, error) TotalCount(context.Context) (int32, error) - PageInfo(context.Context) (*graphqlutil.PageInfo, error) + PageInfo(context.Context) (*gqlutil.PageInfo, error) } type ProductSubscriptionByAccessTokenArgs struct { diff --git a/cmd/frontend/graphqlbackend/embeddings.go b/cmd/frontend/graphqlbackend/embeddings.go index 2e21f12152a..3efab8961eb 100644 --- a/cmd/frontend/graphqlbackend/embeddings.go +++ b/cmd/frontend/graphqlbackend/embeddings.go @@ -5,7 +5,6 @@ import ( "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) @@ -13,7 +12,7 @@ type EmbeddingsResolver interface { EmbeddingsSearch(ctx context.Context, args EmbeddingsSearchInputArgs) (EmbeddingsSearchResultsResolver, error) EmbeddingsMultiSearch(ctx context.Context, args EmbeddingsMultiSearchInputArgs) (EmbeddingsSearchResultsResolver, error) IsContextRequiredForChatQuery(ctx context.Context, args IsContextRequiredForChatQueryInputArgs) (bool, error) - RepoEmbeddingJobs(ctx context.Context, args ListRepoEmbeddingJobsArgs) (*graphqlutil.ConnectionResolver[RepoEmbeddingJobResolver], error) + RepoEmbeddingJobs(ctx context.Context, args ListRepoEmbeddingJobsArgs) (*gqlutil.ConnectionResolver[RepoEmbeddingJobResolver], error) ScheduleRepositoriesForEmbedding(ctx context.Context, args ScheduleRepositoriesForEmbeddingArgs) (*EmptyResponse, error) CancelRepoEmbeddingJob(ctx context.Context, args CancelRepoEmbeddingJobArgs) (*EmptyResponse, error) @@ -57,7 +56,7 @@ type EmbeddingsSearchResultResolver interface { } type ListRepoEmbeddingJobsArgs struct { - graphqlutil.ConnectionResolverArgs + gqlutil.ConnectionResolverArgs Query *string State *string Repo *graphql.ID diff --git a/cmd/frontend/graphqlbackend/event_logs.go b/cmd/frontend/graphqlbackend/event_logs.go index c866f5960a3..b40c4d1534b 100644 --- a/cmd/frontend/graphqlbackend/event_logs.go +++ b/cmd/frontend/graphqlbackend/event_logs.go @@ -3,13 +3,13 @@ package graphqlbackend import ( "context" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) type eventLogsArgs struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs EventName *string // return only event logs matching the event name } @@ -59,7 +59,7 @@ func (r *userEventLogsConnectionResolver) TotalCount(ctx context.Context) (int32 return int32(count), err } -func (r *userEventLogsConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *userEventLogsConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { var count int var err error @@ -72,5 +72,5 @@ func (r *userEventLogsConnectionResolver) PageInfo(ctx context.Context) (*graphq if err != nil { return nil, err } - return graphqlutil.HasNextPage(r.opt.LimitOffset != nil && count > r.opt.Limit), nil + return gqlutil.HasNextPage(r.opt.LimitOffset != nil && count > r.opt.Limit), nil } diff --git a/cmd/frontend/graphqlbackend/executor_connection.go b/cmd/frontend/graphqlbackend/executor_connection.go index 22b37e6d22c..b3347918cfd 100644 --- a/cmd/frontend/graphqlbackend/executor_connection.go +++ b/cmd/frontend/graphqlbackend/executor_connection.go @@ -3,7 +3,7 @@ package graphqlbackend import ( "context" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) type executorConnectionResolver struct { @@ -20,9 +20,9 @@ func (r *executorConnectionResolver) TotalCount(ctx context.Context) int32 { return int32(r.totalCount) } -func (r *executorConnectionResolver) PageInfo(ctx context.Context) *graphqlutil.PageInfo { +func (r *executorConnectionResolver) PageInfo(ctx context.Context) *gqlutil.PageInfo { if r.nextOffset == nil { - return graphqlutil.HasNextPage(false) + return gqlutil.HasNextPage(false) } - return graphqlutil.EncodeIntCursor(r.nextOffset) + return gqlutil.EncodeIntCursor(r.nextOffset) } diff --git a/cmd/frontend/graphqlbackend/executor_secret.go b/cmd/frontend/graphqlbackend/executor_secret.go index ecad818d0fd..d7fb54a9e4f 100644 --- a/cmd/frontend/graphqlbackend/executor_secret.go +++ b/cmd/frontend/graphqlbackend/executor_secret.go @@ -9,7 +9,6 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/graph-gophers/graphql-go/relay" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/encryption/keyring" "github.com/sourcegraph/sourcegraph/internal/errcode" @@ -123,7 +122,7 @@ func (r *executorSecretResolver) AccessLogs(args ExecutorSecretAccessLogListArgs // so access to the access logs is acceptable as well. limit := &database.LimitOffset{Limit: int(args.First)} if args.After != nil { - offset, err := graphqlutil.DecodeIntCursor(args.After) + offset, err := gqlutil.DecodeIntCursor(args.After) if err != nil { return nil, err } diff --git a/cmd/frontend/graphqlbackend/executor_secret_access_logs_connection.go b/cmd/frontend/graphqlbackend/executor_secret_access_logs_connection.go index 132709d8f01..3fdd1bf8b9c 100644 --- a/cmd/frontend/graphqlbackend/executor_secret_access_logs_connection.go +++ b/cmd/frontend/graphqlbackend/executor_secret_access_logs_connection.go @@ -4,8 +4,8 @@ import ( "context" "sync" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" ) @@ -54,7 +54,7 @@ func (r *executorSecretAccessLogConnectionResolver) TotalCount(ctx context.Conte return int32(totalCount), err } -func (r *executorSecretAccessLogConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *executorSecretAccessLogConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { _, _, next, err := r.compute(ctx) if err != nil { return nil, err @@ -62,9 +62,9 @@ func (r *executorSecretAccessLogConnectionResolver) PageInfo(ctx context.Context if next != 0 { n := int32(next) - return graphqlutil.EncodeIntCursor(&n), nil + return gqlutil.EncodeIntCursor(&n), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } func (r *executorSecretAccessLogConnectionResolver) compute(ctx context.Context) (_ []*database.ExecutorSecretAccessLog, _ []*types.User, next int, err error) { diff --git a/cmd/frontend/graphqlbackend/executor_secret_connection.go b/cmd/frontend/graphqlbackend/executor_secret_connection.go index 61afd7d687c..c79ee4ee9a6 100644 --- a/cmd/frontend/graphqlbackend/executor_secret_connection.go +++ b/cmd/frontend/graphqlbackend/executor_secret_connection.go @@ -4,9 +4,9 @@ import ( "context" "sync" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/encryption/keyring" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) type executorSecretConnectionResolver struct { @@ -40,7 +40,7 @@ func (r *executorSecretConnectionResolver) TotalCount(ctx context.Context) (int3 return int32(totalCount), err } -func (r *executorSecretConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *executorSecretConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { _, next, err := r.compute(ctx) if err != nil { return nil, err @@ -48,9 +48,9 @@ func (r *executorSecretConnectionResolver) PageInfo(ctx context.Context) (*graph if next != 0 { n := int32(next) - return graphqlutil.EncodeIntCursor(&n), nil + return gqlutil.EncodeIntCursor(&n), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } func (r *executorSecretConnectionResolver) compute(ctx context.Context) ([]*database.ExecutorSecret, int, error) { diff --git a/cmd/frontend/graphqlbackend/executor_secrets.go b/cmd/frontend/graphqlbackend/executor_secrets.go index 2d1bfecb44b..2c0c3d4cdc0 100644 --- a/cmd/frontend/graphqlbackend/executor_secrets.go +++ b/cmd/frontend/graphqlbackend/executor_secrets.go @@ -9,11 +9,11 @@ import ( "github.com/grafana/regexp" "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/encryption/keyring" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -203,7 +203,7 @@ type ExecutorSecretsListArgs struct { func (o ExecutorSecretsListArgs) LimitOffset() (*database.LimitOffset, error) { limit := &database.LimitOffset{Limit: int(o.First)} if o.After != nil { - offset, err := graphqlutil.DecodeIntCursor(o.After) + offset, err := gqlutil.DecodeIntCursor(o.After) if err != nil { return nil, err } diff --git a/cmd/frontend/graphqlbackend/executors.go b/cmd/frontend/graphqlbackend/executors.go index 402089630b2..78ecb3c31fd 100644 --- a/cmd/frontend/graphqlbackend/executors.go +++ b/cmd/frontend/graphqlbackend/executors.go @@ -6,10 +6,10 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/graph-gophers/graphql-go/relay" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/conf" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) func unmarshalExecutorID(id graphql.ID) (executorID int64, err error) { @@ -30,7 +30,7 @@ func (r *schemaResolver) Executors(ctx context.Context, args ExecutorsListArgs) return nil, err } - offset, err := graphqlutil.DecodeIntCursor(args.After) + offset, err := gqlutil.DecodeIntCursor(args.After) if err != nil { return nil, err } @@ -61,7 +61,7 @@ func (r *schemaResolver) Executors(ctx context.Context, args ExecutorsListArgs) resolvers = append(resolvers, &ExecutorResolver{executor: executor}) } - nextOffset := graphqlutil.NextOffset(offset, len(execs), totalCount) + nextOffset := gqlutil.NextOffset(offset, len(execs), totalCount) executorConnection = &executorConnectionResolver{ resolvers: resolvers, diff --git a/cmd/frontend/graphqlbackend/external_accounts.go b/cmd/frontend/graphqlbackend/external_accounts.go index cd57cc542b5..8ae251e7f4f 100644 --- a/cmd/frontend/graphqlbackend/external_accounts.go +++ b/cmd/frontend/graphqlbackend/external_accounts.go @@ -6,7 +6,6 @@ import ( "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/auth/sourcegraphoperator" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/auth" @@ -15,11 +14,12 @@ import ( "github.com/sourcegraph/sourcegraph/internal/extsvc" gext "github.com/sourcegraph/sourcegraph/internal/extsvc/gerrit/externalaccount" "github.com/sourcegraph/sourcegraph/internal/featureflag" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/lib/errors" ) func (r *siteResolver) ExternalAccounts(ctx context.Context, args *struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs User *graphql.ID ServiceType *string ServiceID *string @@ -53,7 +53,7 @@ func (r *siteResolver) ExternalAccounts(ctx context.Context, args *struct { } func (r *UserResolver) ExternalAccounts(ctx context.Context, args *struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs }, ) (*externalAccountConnectionResolver, error) { // 🚨 SECURITY: Only site admins and the user can list a user's external accounts. @@ -114,12 +114,12 @@ func (r *externalAccountConnectionResolver) TotalCount(ctx context.Context) (int return int32(count), err } -func (r *externalAccountConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *externalAccountConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { externalAccounts, err := r.compute(ctx) if err != nil { return nil, err } - return graphqlutil.HasNextPage(r.opt.LimitOffset != nil && len(externalAccounts) > r.opt.Limit), nil + return gqlutil.HasNextPage(r.opt.LimitOffset != nil && len(externalAccounts) > r.opt.Limit), nil } func (r *schemaResolver) DeleteExternalAccount(ctx context.Context, args *struct { diff --git a/cmd/frontend/graphqlbackend/external_service.go b/cmd/frontend/graphqlbackend/external_service.go index e9a723129dd..d4d61a8d8eb 100644 --- a/cmd/frontend/graphqlbackend/external_service.go +++ b/cmd/frontend/graphqlbackend/external_service.go @@ -12,7 +12,6 @@ import ( "github.com/sourcegraph/log" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/conf" "github.com/sourcegraph/sourcegraph/internal/database" @@ -419,12 +418,12 @@ func (r *externalServiceSyncJobConnectionResolver) TotalCount(ctx context.Contex return int32(totalCount), err } -func (r *externalServiceSyncJobConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *externalServiceSyncJobConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { jobs, totalCount, err := r.compute(ctx) if err != nil { return nil, err } - return graphqlutil.HasNextPage(len(jobs) != int(totalCount)), nil + return gqlutil.HasNextPage(len(jobs) != int(totalCount)), nil } func (r *externalServiceSyncJobConnectionResolver) compute(ctx context.Context) ([]*types.ExternalServiceSyncJob, int64, error) { diff --git a/cmd/frontend/graphqlbackend/external_services.go b/cmd/frontend/graphqlbackend/external_services.go index 2cdda7baecd..4db6d34f8eb 100644 --- a/cmd/frontend/graphqlbackend/external_services.go +++ b/cmd/frontend/graphqlbackend/external_services.go @@ -16,7 +16,6 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/envvar" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/backend" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/auth" @@ -24,6 +23,7 @@ import ( "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/extsvc" "github.com/sourcegraph/sourcegraph/internal/featureflag" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/repos" "github.com/sourcegraph/sourcegraph/internal/repoupdater" "github.com/sourcegraph/sourcegraph/internal/trace" @@ -361,7 +361,7 @@ func (r *schemaResolver) DeleteExternalService(ctx context.Context, args *delete } type ExternalServicesArgs struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs After *string Namespace *graphql.ID Repo *graphql.ID @@ -434,7 +434,7 @@ func (r *externalServiceConnectionResolver) TotalCount(ctx context.Context) (int return int32(count), err } -func (r *externalServiceConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *externalServiceConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { externalServices, err := r.compute(ctx) if err != nil { return nil, err @@ -442,12 +442,12 @@ func (r *externalServiceConnectionResolver) PageInfo(ctx context.Context) (*grap // We would have had all results when no limit set if r.opt.LimitOffset == nil { - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } // We got less results than limit, means we've had all results if len(externalServices) < r.opt.Limit { - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } // In case the number of results happens to be the same as the limit, @@ -460,18 +460,18 @@ func (r *externalServiceConnectionResolver) PageInfo(ctx context.Context) (*grap if count > len(externalServices) { endCursorID := externalServices[len(externalServices)-1].ID - return graphqlutil.NextPageCursor(string(MarshalExternalServiceID(endCursorID))), nil + return gqlutil.NextPageCursor(string(MarshalExternalServiceID(endCursorID))), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } type ComputedExternalServiceConnectionResolver struct { - args graphqlutil.ConnectionArgs + args gqlutil.ConnectionArgs externalServices []*types.ExternalService db database.DB } -func NewComputedExternalServiceConnectionResolver(db database.DB, externalServices []*types.ExternalService, args graphqlutil.ConnectionArgs) *ComputedExternalServiceConnectionResolver { +func NewComputedExternalServiceConnectionResolver(db database.DB, externalServices []*types.ExternalService, args gqlutil.ConnectionArgs) *ComputedExternalServiceConnectionResolver { return &ComputedExternalServiceConnectionResolver{ db: db, externalServices: externalServices, @@ -495,8 +495,8 @@ func (r *ComputedExternalServiceConnectionResolver) TotalCount(_ context.Context return int32(len(r.externalServices)) } -func (r *ComputedExternalServiceConnectionResolver) PageInfo(_ context.Context) *graphqlutil.PageInfo { - return graphqlutil.HasNextPage(r.args.First != nil && len(r.externalServices) >= int(*r.args.First)) +func (r *ComputedExternalServiceConnectionResolver) PageInfo(_ context.Context) *gqlutil.PageInfo { + return gqlutil.HasNextPage(r.args.First != nil && len(r.externalServices) >= int(*r.args.First)) } type ExternalServiceMutationType int diff --git a/cmd/frontend/graphqlbackend/external_services_test.go b/cmd/frontend/graphqlbackend/external_services_test.go index 5a597dd64ff..cfe239ac5a5 100644 --- a/cmd/frontend/graphqlbackend/external_services_test.go +++ b/cmd/frontend/graphqlbackend/external_services_test.go @@ -11,27 +11,25 @@ import ( "github.com/graph-gophers/graphql-go" gqlerrors "github.com/graph-gophers/graphql-go/errors" "github.com/graph-gophers/graphql-go/relay" - "github.com/stretchr/testify/assert" - "github.com/sourcegraph/sourcegraph/internal/api" - "github.com/sourcegraph/sourcegraph/internal/database/basestore" - "github.com/sourcegraph/sourcegraph/internal/database/dbmocks" - "github.com/sourcegraph/sourcegraph/internal/extsvc/github" - "github.com/sourcegraph/sourcegraph/internal/ratelimit" - "github.com/sourcegraph/sourcegraph/lib/errors" - "github.com/sourcegraph/log/logtest" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/backend" "github.com/sourcegraph/sourcegraph/internal/actor" + "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/database/basestore" + "github.com/sourcegraph/sourcegraph/internal/database/dbmocks" "github.com/sourcegraph/sourcegraph/internal/extsvc" + "github.com/sourcegraph/sourcegraph/internal/extsvc/github" "github.com/sourcegraph/sourcegraph/internal/gitserver" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" + "github.com/sourcegraph/sourcegraph/internal/ratelimit" "github.com/sourcegraph/sourcegraph/internal/timeutil" "github.com/sourcegraph/sourcegraph/internal/types" + "github.com/sourcegraph/sourcegraph/lib/errors" "github.com/sourcegraph/sourcegraph/schema" ) @@ -1021,20 +1019,20 @@ func TestExternalServices(t *testing.T) { } func TestExternalServices_PageInfo(t *testing.T) { - cmpOpts := cmp.AllowUnexported(graphqlutil.PageInfo{}) + cmpOpts := cmp.AllowUnexported(gqlutil.PageInfo{}) tests := []struct { name string opt database.ExternalServicesListOptions mockList func(ctx context.Context, opt database.ExternalServicesListOptions) ([]*types.ExternalService, error) mockCount func(ctx context.Context, opt database.ExternalServicesListOptions) (int, error) - wantPageInfo *graphqlutil.PageInfo + wantPageInfo *gqlutil.PageInfo }{ { name: "no limit set", mockList: func(_ context.Context, opt database.ExternalServicesListOptions) ([]*types.ExternalService, error) { return []*types.ExternalService{{ID: 1, Config: extsvc.NewEmptyConfig()}}, nil }, - wantPageInfo: graphqlutil.HasNextPage(false), + wantPageInfo: gqlutil.HasNextPage(false), }, { name: "less results than the limit", @@ -1046,7 +1044,7 @@ func TestExternalServices_PageInfo(t *testing.T) { mockList: func(_ context.Context, opt database.ExternalServicesListOptions) ([]*types.ExternalService, error) { return []*types.ExternalService{{ID: 1, Config: extsvc.NewEmptyConfig()}}, nil }, - wantPageInfo: graphqlutil.HasNextPage(false), + wantPageInfo: gqlutil.HasNextPage(false), }, { name: "same number of results as the limit, and no more", @@ -1061,7 +1059,7 @@ func TestExternalServices_PageInfo(t *testing.T) { mockCount: func(ctx context.Context, opt database.ExternalServicesListOptions) (int, error) { return 1, nil }, - wantPageInfo: graphqlutil.HasNextPage(false), + wantPageInfo: gqlutil.HasNextPage(false), }, { name: "same number of results as the limit, and has more", @@ -1076,7 +1074,7 @@ func TestExternalServices_PageInfo(t *testing.T) { mockCount: func(ctx context.Context, opt database.ExternalServicesListOptions) (int, error) { return 2, nil }, - wantPageInfo: graphqlutil.NextPageCursor(string(MarshalExternalServiceID(1))), + wantPageInfo: gqlutil.NextPageCursor(string(MarshalExternalServiceID(1))), }, } for _, test := range tests { diff --git a/cmd/frontend/graphqlbackend/git_commit.go b/cmd/frontend/graphqlbackend/git_commit.go index 0af67761d65..9f51513e742 100644 --- a/cmd/frontend/graphqlbackend/git_commit.go +++ b/cmd/frontend/graphqlbackend/git_commit.go @@ -16,12 +16,12 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/externallink" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/backend" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gitserver" "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/trace" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -375,7 +375,7 @@ func (r *GitCommitResolver) LanguageStatistics(ctx context.Context) ([]*language } type AncestorsArgs struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs Query *string Path *string Follow bool diff --git a/cmd/frontend/graphqlbackend/git_commits.go b/cmd/frontend/graphqlbackend/git_commits.go index 845396b648d..35de2c7beaf 100644 --- a/cmd/frontend/graphqlbackend/git_commits.go +++ b/cmd/frontend/graphqlbackend/git_commits.go @@ -7,10 +7,10 @@ import ( "sync" "time" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gitserver" "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/lib/errors" "github.com/sourcegraph/sourcegraph/lib/pointers" ) @@ -158,7 +158,7 @@ func (r *gitCommitConnectionResolver) TotalCount(ctx context.Context) (*int32, e return &n, nil } -func (r *gitCommitConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *gitCommitConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { commits, err := r.compute(ctx) if err != nil { return nil, err @@ -167,7 +167,7 @@ func (r *gitCommitConnectionResolver) PageInfo(ctx context.Context) (*graphqluti totalCommits := len(commits) // If no limit is set, we have retrieved all the commits and there is no next page. if r.first == nil { - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } limit := int(*r.first) @@ -200,8 +200,8 @@ func (r *gitCommitConnectionResolver) PageInfo(ctx context.Context) (*graphqluti } endCursor := limit + after - return graphqlutil.NextPageCursor(strconv.Itoa(endCursor)), nil + return gqlutil.NextPageCursor(strconv.Itoa(endCursor)), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } diff --git a/cmd/frontend/graphqlbackend/git_tree.go b/cmd/frontend/graphqlbackend/git_tree.go index e7371e118c8..50f6dcfb905 100644 --- a/cmd/frontend/graphqlbackend/git_tree.go +++ b/cmd/frontend/graphqlbackend/git_tree.go @@ -9,8 +9,8 @@ import ( "sort" "strings" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/api" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/trace" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -21,7 +21,7 @@ func (r *GitTreeEntryResolver) IsRoot() bool { } type gitTreeEntryConnectionArgs struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs Recursive bool // If Ancestors is true and the tree is loaded from a subdirectory, we will // return a flat list of all entries in all parent directories. diff --git a/cmd/frontend/graphqlbackend/git_tree_history.go b/cmd/frontend/graphqlbackend/git_tree_history.go index 63477fe4c12..8b1051c12c6 100644 --- a/cmd/frontend/graphqlbackend/git_tree_history.go +++ b/cmd/frontend/graphqlbackend/git_tree_history.go @@ -4,12 +4,12 @@ import ( "context" "io/fs" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/lib/pointers" ) type HistoryArgs struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs After *string // TODO(@camdencheek): implement follow. Right now, we wouldn't have @@ -52,6 +52,6 @@ func (r *treeEntryHistoryConnection) TotalCount(ctx context.Context) (*int32, er return r.commits.TotalCount(ctx) } -func (r *treeEntryHistoryConnection) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *treeEntryHistoryConnection) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { return r.commits.PageInfo(ctx) } diff --git a/cmd/frontend/graphqlbackend/git_tree_test.go b/cmd/frontend/graphqlbackend/git_tree_test.go index 0a6e094dc92..e18a86d0dee 100644 --- a/cmd/frontend/graphqlbackend/git_tree_test.go +++ b/cmd/frontend/graphqlbackend/git_tree_test.go @@ -9,13 +9,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/backend" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/database/dbmocks" "github.com/sourcegraph/sourcegraph/internal/fileutil" "github.com/sourcegraph/sourcegraph/internal/gitserver" "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" "github.com/sourcegraph/sourcegraph/lib/errors" "github.com/sourcegraph/sourcegraph/lib/pointers" @@ -257,28 +257,28 @@ func TestGitTree_Entries(t *testing.T) { }) t.Run("Pagination", func(t *testing.T) { - entries, err := gitTree.Entries(context.Background(), &gitTreeEntryConnectionArgs{ConnectionArgs: graphqlutil.ConnectionArgs{First: pointers.Ptr(int32(1))}}) + entries, err := gitTree.Entries(context.Background(), &gitTreeEntryConnectionArgs{ConnectionArgs: gqlutil.ConnectionArgs{First: pointers.Ptr(int32(1))}}) require.NoError(t, err) assertEntries(t, []fs.FileInfo{ CreateFileInfo(".aspect/", true), }, entries) - entries, err = gitTree.Files(context.Background(), &gitTreeEntryConnectionArgs{ConnectionArgs: graphqlutil.ConnectionArgs{First: pointers.Ptr(int32(1))}}) + entries, err = gitTree.Files(context.Background(), &gitTreeEntryConnectionArgs{ConnectionArgs: gqlutil.ConnectionArgs{First: pointers.Ptr(int32(1))}}) require.NoError(t, err) assertEntries(t, []fs.FileInfo{ CreateFileInfo("file", false), }, entries) - entries, err = gitTree.Directories(context.Background(), &gitTreeEntryConnectionArgs{ConnectionArgs: graphqlutil.ConnectionArgs{First: pointers.Ptr(int32(1))}}) + entries, err = gitTree.Directories(context.Background(), &gitTreeEntryConnectionArgs{ConnectionArgs: gqlutil.ConnectionArgs{First: pointers.Ptr(int32(1))}}) require.NoError(t, err) assertEntries(t, []fs.FileInfo{ CreateFileInfo(".aspect/", true), }, entries) // Invalid first. - _, err = gitTree.Entries(context.Background(), &gitTreeEntryConnectionArgs{ConnectionArgs: graphqlutil.ConnectionArgs{First: pointers.Ptr(int32(-1))}}) + _, err = gitTree.Entries(context.Background(), &gitTreeEntryConnectionArgs{ConnectionArgs: gqlutil.ConnectionArgs{First: pointers.Ptr(int32(-1))}}) require.Error(t, err) // First is bigger than the number of entries. - entries, err = gitTree.Entries(context.Background(), &gitTreeEntryConnectionArgs{ConnectionArgs: graphqlutil.ConnectionArgs{First: pointers.Ptr(int32(100))}}) + entries, err = gitTree.Entries(context.Background(), &gitTreeEntryConnectionArgs{ConnectionArgs: gqlutil.ConnectionArgs{First: pointers.Ptr(int32(100))}}) require.NoError(t, err) assertEntries(t, []fs.FileInfo{ CreateFileInfo(".aspect/", true), diff --git a/cmd/frontend/graphqlbackend/githubapps.go b/cmd/frontend/graphqlbackend/githubapps.go index 9ff218cbf09..4213bf3263a 100644 --- a/cmd/frontend/graphqlbackend/githubapps.go +++ b/cmd/frontend/graphqlbackend/githubapps.go @@ -5,7 +5,6 @@ import ( "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" @@ -119,6 +118,6 @@ func (ghai GitHubAppInstallation) Account() GitHubAppInstallationAccount { return ghai.InstallAccount } -func (ghai GitHubAppInstallation) ExternalServices(args *struct{ graphqlutil.ConnectionArgs }) *ComputedExternalServiceConnectionResolver { +func (ghai GitHubAppInstallation) ExternalServices(args *struct{ gqlutil.ConnectionArgs }) *ComputedExternalServiceConnectionResolver { return NewComputedExternalServiceConnectionResolver(ghai.DB, ghai.InstallExternalServices, args.ConnectionArgs) } diff --git a/cmd/frontend/graphqlbackend/gitserver.go b/cmd/frontend/graphqlbackend/gitserver.go index 5e7c0097584..60fed78d57c 100644 --- a/cmd/frontend/graphqlbackend/gitserver.go +++ b/cmd/frontend/graphqlbackend/gitserver.go @@ -6,8 +6,8 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/graph-gophers/graphql-go/relay" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) const gitserverIDKind = "GitserverInstance" @@ -42,7 +42,7 @@ func (r *schemaResolver) gitserverByID(ctx context.Context, id graphql.ID) (*git }, nil } -func (r *schemaResolver) Gitservers(ctx context.Context) (graphqlutil.SliceConnectionResolver[*gitserverResolver], error) { +func (r *schemaResolver) Gitservers(ctx context.Context) (gqlutil.SliceConnectionResolver[*gitserverResolver], error) { // 🚨 SECURITY: Only site admins can query gitserver information. if err := auth.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil { return nil, err @@ -62,7 +62,7 @@ func (r *schemaResolver) Gitservers(ctx context.Context) (graphqlutil.SliceConne }) } noOfResolvers := len(resolvers) - return graphqlutil.NewSliceConnectionResolver(resolvers, noOfResolvers, noOfResolvers), nil + return gqlutil.NewSliceConnectionResolver(resolvers, noOfResolvers, noOfResolvers), nil } type gitserverResolver struct { diff --git a/cmd/frontend/graphqlbackend/graphqlutil/BUILD.bazel b/cmd/frontend/graphqlbackend/graphqlutil/BUILD.bazel deleted file mode 100644 index 8f28c013940..00000000000 --- a/cmd/frontend/graphqlbackend/graphqlutil/BUILD.bazel +++ /dev/null @@ -1,37 +0,0 @@ -load("//dev:go_defs.bzl", "go_test") -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "graphqlutil", - srcs = [ - "connection.go", - "connection_resolver.go", - "cursors.go", - "doc.go", - "offset.go", - "page_info.go", - "slice_connection_resolver.go", - ], - importpath = "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil", - visibility = ["//visibility:public"], - deps = [ - "//internal/database", - "//lib/errors", - "//lib/pointers", - ], -) - -go_test( - name = "graphqlutil_test", - timeout = "short", - srcs = [ - "connection_resolver_test.go", - "slice_connection_resolver_test.go", - ], - embed = [":graphqlutil"], - deps = [ - "//internal/database", - "@com_github_google_go_cmp//cmp", - "@com_github_graph_gophers_graphql_go//:graphql-go", - ], -) diff --git a/cmd/frontend/graphqlbackend/graphqlutil/doc.go b/cmd/frontend/graphqlbackend/graphqlutil/doc.go deleted file mode 100644 index 3bb3dbc7260..00000000000 --- a/cmd/frontend/graphqlbackend/graphqlutil/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package graphqlutil contains utilities for working with GraphQL. -package graphqlutil diff --git a/cmd/frontend/graphqlbackend/guardrails.go b/cmd/frontend/graphqlbackend/guardrails.go index 5d33a8aacf6..ed153abc423 100644 --- a/cmd/frontend/graphqlbackend/guardrails.go +++ b/cmd/frontend/graphqlbackend/guardrails.go @@ -3,7 +3,7 @@ package graphqlbackend import ( "context" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) type GuardrailsResolver interface { @@ -11,7 +11,7 @@ type GuardrailsResolver interface { } type SnippetAttributionArgs struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs Snippet string } @@ -19,7 +19,7 @@ type SnippetAttributionConnectionResolver interface { TotalCount() int32 LimitHit() bool SnippetThreshold() AttributionSnippetThresholdResolver - PageInfo() *graphqlutil.PageInfo + PageInfo() *gqlutil.PageInfo Nodes() []SnippetAttributionResolver } diff --git a/cmd/frontend/graphqlbackend/insights.go b/cmd/frontend/graphqlbackend/insights.go index e494348ff69..e4cfe2e6015 100644 --- a/cmd/frontend/graphqlbackend/insights.go +++ b/cmd/frontend/graphqlbackend/insights.go @@ -6,7 +6,6 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/graph-gophers/graphql-go/relay" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) @@ -44,7 +43,7 @@ type InsightsResolver interface { // Admin Management InsightSeriesQueryStatus(ctx context.Context) ([]InsightSeriesQueryStatusResolver, error) InsightViewDebug(ctx context.Context, args InsightViewDebugArgs) (InsightViewDebugResolver, error) - InsightAdminBackfillQueue(ctx context.Context, args *AdminBackfillQueueArgs) (*graphqlutil.ConnectionResolver[*BackfillQueueItemResolver], error) + InsightAdminBackfillQueue(ctx context.Context, args *AdminBackfillQueueArgs) (*gqlutil.ConnectionResolver[*BackfillQueueItemResolver], error) // Admin Mutations UpdateInsightSeries(ctx context.Context, args *UpdateInsightSeriesArgs) (InsightSeriesMetadataPayloadResolver, error) RetryInsightSeriesBackfill(ctx context.Context, args *BackfillArgs) (*BackfillQueueItemResolver, error) @@ -139,7 +138,7 @@ type InsightsDashboardsArgs struct { type InsightsDashboardConnectionResolver interface { Nodes(ctx context.Context) ([]InsightsDashboardResolver, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) } type InsightsDashboardResolver interface { @@ -192,7 +191,7 @@ type DeleteInsightsDashboardArgs struct { type InsightViewConnectionResolver interface { Nodes(ctx context.Context) ([]InsightViewResolver, error) TotalCount(ctx context.Context) (*int32, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) } type InsightViewResolver interface { @@ -583,7 +582,7 @@ type BackfillArgs struct { } type AdminBackfillQueueArgs struct { - graphqlutil.ConnectionResolverArgs + gqlutil.ConnectionResolverArgs OrderBy string Descending bool diff --git a/cmd/frontend/graphqlbackend/namespaces.go b/cmd/frontend/graphqlbackend/namespaces.go index 04a23472cb0..0694268375d 100644 --- a/cmd/frontend/graphqlbackend/namespaces.go +++ b/cmd/frontend/graphqlbackend/namespaces.go @@ -7,9 +7,9 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/graph-gophers/graphql-go/relay" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -149,6 +149,6 @@ func (r NamespaceResolver) ToUser() (*UserResolver, bool) { return n, ok } -func newNamespaceConnection(namespaces []*NamespaceResolver) graphqlutil.SliceConnectionResolver[*NamespaceResolver] { - return graphqlutil.NewSliceConnectionResolver(namespaces, len(namespaces), len(namespaces)) +func newNamespaceConnection(namespaces []*NamespaceResolver) gqlutil.SliceConnectionResolver[*NamespaceResolver] { + return gqlutil.NewSliceConnectionResolver(namespaces, len(namespaces), len(namespaces)) } diff --git a/cmd/frontend/graphqlbackend/notebooks.go b/cmd/frontend/graphqlbackend/notebooks.go index 2cfb1d09351..be1a190b7e0 100644 --- a/cmd/frontend/graphqlbackend/notebooks.go +++ b/cmd/frontend/graphqlbackend/notebooks.go @@ -5,7 +5,6 @@ import ( "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) @@ -33,7 +32,7 @@ type NotebooksResolver interface { type NotebookConnectionResolver interface { Nodes(ctx context.Context) []NotebookResolver TotalCount(ctx context.Context) int32 - PageInfo(ctx context.Context) *graphqlutil.PageInfo + PageInfo(ctx context.Context) *gqlutil.PageInfo } type NotebookStarResolver interface { @@ -44,7 +43,7 @@ type NotebookStarResolver interface { type NotebookStarConnectionResolver interface { Nodes() []NotebookStarResolver TotalCount() int32 - PageInfo() *graphqlutil.PageInfo + PageInfo() *gqlutil.PageInfo } type NotebookResolver interface { diff --git a/cmd/frontend/graphqlbackend/org.go b/cmd/frontend/graphqlbackend/org.go index 4bf850c7ba5..7139994a49d 100644 --- a/cmd/frontend/graphqlbackend/org.go +++ b/cmd/frontend/graphqlbackend/org.go @@ -7,7 +7,6 @@ import ( "github.com/graph-gophers/graphql-go/relay" "github.com/sourcegraph/log" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/suspiciousnames" "github.com/sourcegraph/sourcegraph/internal/actor" sgactor "github.com/sourcegraph/sourcegraph/internal/actor" @@ -99,10 +98,10 @@ func (o *OrgResolver) SettingsURL() *string { return strptr(o.URL() + "/settings func (o *OrgResolver) CreatedAt() gqlutil.DateTime { return gqlutil.DateTime{Time: o.org.CreatedAt} } func (o *OrgResolver) Members(ctx context.Context, args struct { - graphqlutil.ConnectionResolverArgs + gqlutil.ConnectionResolverArgs Query *string }, -) (*graphqlutil.ConnectionResolver[*UserResolver], error) { +) (*gqlutil.ConnectionResolver[*UserResolver], error) { // 🚨 SECURITY: On dotcom, only an org's members can list its members. if dotcom.SourcegraphDotComMode() { if err := auth.CheckOrgAccessOrSiteAdmin(ctx, o.db, o.org.ID); err != nil { @@ -116,7 +115,7 @@ func (o *OrgResolver) Members(ctx context.Context, args struct { query: args.Query, } - return graphqlutil.NewConnectionResolver[*UserResolver](connectionStore, &args.ConnectionResolverArgs, &graphqlutil.ConnectionResolverOptions{ + return gqlutil.NewConnectionResolver[*UserResolver](connectionStore, &args.ConnectionResolverArgs, &gqlutil.ConnectionResolverOptions{ AllowNoLimit: true, }) } diff --git a/cmd/frontend/graphqlbackend/org_members.go b/cmd/frontend/graphqlbackend/org_members.go index 9ec34bdaaa0..c9f5eb590f5 100644 --- a/cmd/frontend/graphqlbackend/org_members.go +++ b/cmd/frontend/graphqlbackend/org_members.go @@ -3,7 +3,6 @@ package graphqlbackend import ( "context" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gqlutil" @@ -35,8 +34,8 @@ func (r *organizationMembershipConnectionResolver) Nodes() []*organizationMember return r.nodes } func (r *organizationMembershipConnectionResolver) TotalCount() int32 { return int32(len(r.nodes)) } -func (r *organizationMembershipConnectionResolver) PageInfo() *graphqlutil.PageInfo { - return graphqlutil.HasNextPage(false) +func (r *organizationMembershipConnectionResolver) PageInfo() *gqlutil.PageInfo { + return gqlutil.HasNextPage(false) } type organizationMembershipResolver struct { diff --git a/cmd/frontend/graphqlbackend/org_test.go b/cmd/frontend/graphqlbackend/org_test.go index 00a387e458c..c8f77a1cf6a 100644 --- a/cmd/frontend/graphqlbackend/org_test.go +++ b/cmd/frontend/graphqlbackend/org_test.go @@ -14,7 +14,6 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/log/logtest" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/authz/permssync" "github.com/sourcegraph/sourcegraph/internal/conf" @@ -22,6 +21,7 @@ import ( "github.com/sourcegraph/sourcegraph/internal/database/dbmocks" "github.com/sourcegraph/sourcegraph/internal/database/dbtest" "github.com/sourcegraph/sourcegraph/internal/dotcom" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" "github.com/sourcegraph/sourcegraph/schema" ) @@ -490,5 +490,5 @@ func TestMembersConnectionStore(t *testing.T) { orgID: org.ID, } - graphqlutil.TestConnectionResolverStoreSuite(t, connectionStore, nil) + gqlutil.TestConnectionResolverStoreSuite(t, connectionStore, nil) } diff --git a/cmd/frontend/graphqlbackend/orgs.go b/cmd/frontend/graphqlbackend/orgs.go index a85edb935dc..cde0de69c58 100644 --- a/cmd/frontend/graphqlbackend/orgs.go +++ b/cmd/frontend/graphqlbackend/orgs.go @@ -5,15 +5,15 @@ import ( logger "github.com/sourcegraph/log" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/featureflag" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) func (r *schemaResolver) Organizations(args *struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs Query *string }) *orgConnectionResolver { var opt database.OrgsListOptions @@ -74,6 +74,6 @@ type orgConnectionStaticResolver struct { func (r *orgConnectionStaticResolver) Nodes() []*OrgResolver { return r.nodes } func (r *orgConnectionStaticResolver) TotalCount() int32 { return int32(len(r.nodes)) } -func (r *orgConnectionStaticResolver) PageInfo() *graphqlutil.PageInfo { - return graphqlutil.HasNextPage(false) +func (r *orgConnectionStaticResolver) PageInfo() *gqlutil.PageInfo { + return gqlutil.HasNextPage(false) } diff --git a/cmd/frontend/graphqlbackend/outbound_requests.go b/cmd/frontend/graphqlbackend/outbound_requests.go index e0f718e0f2c..8b2416fd8c0 100644 --- a/cmd/frontend/graphqlbackend/outbound_requests.go +++ b/cmd/frontend/graphqlbackend/outbound_requests.go @@ -10,7 +10,6 @@ import ( "github.com/sourcegraph/log" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" @@ -123,16 +122,16 @@ func (r *outboundRequestConnectionResolver) TotalCount(ctx context.Context) (int return int32(len(resolvers)), nil } -func (r *outboundRequestConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *outboundRequestConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { resolvers, err := r.compute(ctx) if err != nil { return nil, err } if r.first != nil && *r.first > -1 && len(resolvers) > int(*r.first) { - return graphqlutil.NextPageCursor(string(resolvers[*r.first-1].ID())), nil + return gqlutil.NextPageCursor(string(resolvers[*r.first-1].ID())), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } func (r *outboundRequestConnectionResolver) compute(ctx context.Context) ([]*OutboundRequestResolver, error) { diff --git a/cmd/frontend/graphqlbackend/outbound_webhook_logs.go b/cmd/frontend/graphqlbackend/outbound_webhook_logs.go index c6b8bebd9f9..8fe49141dae 100644 --- a/cmd/frontend/graphqlbackend/outbound_webhook_logs.go +++ b/cmd/frontend/graphqlbackend/outbound_webhook_logs.go @@ -8,7 +8,6 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/graph-gophers/graphql-go/relay" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" @@ -27,7 +26,7 @@ type OutboundWebhookLogStatsResolver interface { type OutboundWebhookLogConnectionResolver interface { Nodes() ([]OutboundWebhookLogResolver, error) TotalCount() (int32, error) - PageInfo() (*graphqlutil.PageInfo, error) + PageInfo() (*gqlutil.PageInfo, error) } type OutboundWebhookLogResolver interface { @@ -121,16 +120,16 @@ func (r *outboundWebhookLogConnectionResolver) TotalCount() (int32, error) { return r.totalCount() } -func (r *outboundWebhookLogConnectionResolver) PageInfo() (*graphqlutil.PageInfo, error) { +func (r *outboundWebhookLogConnectionResolver) PageInfo() (*gqlutil.PageInfo, error) { nodes, err := r.nodes() if err != nil { return nil, err } if len(nodes) > r.first { - return graphqlutil.NextPageCursor(strconv.Itoa(r.first + r.offset)), nil + return gqlutil.NextPageCursor(strconv.Itoa(r.first + r.offset)), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } type outboundWebhookLogResolver struct { diff --git a/cmd/frontend/graphqlbackend/outbound_webhooks.go b/cmd/frontend/graphqlbackend/outbound_webhooks.go index 6bbc2a321cd..660a1678dea 100644 --- a/cmd/frontend/graphqlbackend/outbound_webhooks.go +++ b/cmd/frontend/graphqlbackend/outbound_webhooks.go @@ -9,11 +9,11 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/graph-gophers/graphql-go/relay" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/encryption" "github.com/sourcegraph/sourcegraph/internal/encryption/keyring" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" "github.com/sourcegraph/sourcegraph/internal/webhooks/outbound" "github.com/sourcegraph/sourcegraph/lib/errors" @@ -24,7 +24,7 @@ const outboundWebhookIDKind = "OutboundWebhook" type OutboundWebhookConnectionResolver interface { Nodes() ([]OutboundWebhookResolver, error) TotalCount() (int32, error) - PageInfo() (*graphqlutil.PageInfo, error) + PageInfo() (*gqlutil.PageInfo, error) } type OutboundWebhookEventTypeResolver interface { @@ -293,16 +293,16 @@ func (r *outboundWebhookConnectionResolver) TotalCount() (int32, error) { return r.totalCount() } -func (r *outboundWebhookConnectionResolver) PageInfo() (*graphqlutil.PageInfo, error) { +func (r *outboundWebhookConnectionResolver) PageInfo() (*gqlutil.PageInfo, error) { nodes, err := r.nodes() if err != nil { return nil, err } if len(nodes) > r.first { - return graphqlutil.NextPageCursor(strconv.Itoa(r.first + r.offset)), nil + return gqlutil.NextPageCursor(strconv.Itoa(r.first + r.offset)), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } type outboundWebhookEventTypeResolver struct { diff --git a/cmd/frontend/graphqlbackend/own.go b/cmd/frontend/graphqlbackend/own.go index 1a331ff82fc..29f7a082c3d 100644 --- a/cmd/frontend/graphqlbackend/own.go +++ b/cmd/frontend/graphqlbackend/own.go @@ -5,7 +5,6 @@ import ( "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) @@ -77,7 +76,7 @@ type OwnResolver interface { type OwnershipConnectionResolver interface { TotalCount(context.Context) (int32, error) TotalOwners(context.Context) (int32, error) - PageInfo(context.Context) (*graphqlutil.PageInfo, error) + PageInfo(context.Context) (*gqlutil.PageInfo, error) Nodes(context.Context) ([]OwnershipResolver, error) } @@ -192,7 +191,7 @@ type CodeownersIngestedFileResolver interface { type CodeownersIngestedFileConnectionResolver interface { Nodes(ctx context.Context) ([]CodeownersIngestedFileResolver, error) TotalCount(ctx context.Context) (int32, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) } type SignalConfigurationResolver interface { diff --git a/cmd/frontend/graphqlbackend/package_repo_filters.go b/cmd/frontend/graphqlbackend/package_repo_filters.go index 9dfe85a0344..16befd2a830 100644 --- a/cmd/frontend/graphqlbackend/package_repo_filters.go +++ b/cmd/frontend/graphqlbackend/package_repo_filters.go @@ -6,9 +6,9 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/graph-gophers/graphql-go/relay" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/codeintel/dependencies" "github.com/sourcegraph/sourcegraph/internal/codeintel/dependencies/shared" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/observation" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -39,7 +39,7 @@ func (r *filterMatchingResolver) ToPackageRepoReferenceVersionConnection() (*pac func (r *schemaResolver) PackageRepoReferencesMatchingFilter(ctx context.Context, args struct { Kind string Filter inputPackageFilter - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs After *string }, ) (_ *filterMatchingResolver, err error) { diff --git a/cmd/frontend/graphqlbackend/package_repos.go b/cmd/frontend/graphqlbackend/package_repos.go index f028415c280..520861eb648 100644 --- a/cmd/frontend/graphqlbackend/package_repos.go +++ b/cmd/frontend/graphqlbackend/package_repos.go @@ -7,20 +7,20 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/graph-gophers/graphql-go/relay" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/codeintel/dependencies" "github.com/sourcegraph/sourcegraph/internal/conf/reposource" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/extsvc" "github.com/sourcegraph/sourcegraph/internal/gitserver" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/observation" "github.com/sourcegraph/sourcegraph/internal/types" "github.com/sourcegraph/sourcegraph/lib/errors" ) type PackageRepoReferenceConnectionArgs struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs After *string Kind *string Name *string @@ -123,14 +123,14 @@ func (r *packageRepoReferenceConnectionResolver) TotalCount(ctx context.Context) return int32(r.total), nil } -func (r *packageRepoReferenceConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *packageRepoReferenceConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { if len(r.deps) == 0 || !r.hasMore { - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } next := r.deps[len(r.deps)-1].ID cursor := string(relay.MarshalID("PackageRepoReference", next)) - return graphqlutil.NextPageCursor(cursor), nil + return gqlutil.NextPageCursor(cursor), nil } type packageRepoReferenceVersionConnectionResolver struct { @@ -152,14 +152,14 @@ func (r *packageRepoReferenceVersionConnectionResolver) TotalCount(ctx context.C return int32(r.total), nil } -func (r *packageRepoReferenceVersionConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *packageRepoReferenceVersionConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { if len(r.versions) == 0 || !r.hasMore { - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } next := r.versions[len(r.versions)-1].ID cursor := string(relay.MarshalID("PackageRepoReferenceVersion", next)) - return graphqlutil.NextPageCursor(cursor), nil + return gqlutil.NextPageCursor(cursor), nil } type packageRepoReferenceResolver struct { diff --git a/cmd/frontend/graphqlbackend/permissions.go b/cmd/frontend/graphqlbackend/permissions.go index 62dfe3967f5..e25af534a1c 100644 --- a/cmd/frontend/graphqlbackend/permissions.go +++ b/cmd/frontend/graphqlbackend/permissions.go @@ -5,9 +5,9 @@ import ( "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -35,7 +35,7 @@ func (r *schemaResolver) permissionByID(ctx context.Context, id graphql.ID) (Per return &permissionResolver{permission: permission}, nil } -func (r *schemaResolver) Permissions(ctx context.Context, args *ListPermissionArgs) (*graphqlutil.ConnectionResolver[PermissionResolver], error) { +func (r *schemaResolver) Permissions(ctx context.Context, args *ListPermissionArgs) (*gqlutil.ConnectionResolver[PermissionResolver], error) { connectionStore := permissionConnectionStore{ db: r.db, } @@ -73,10 +73,10 @@ func (r *schemaResolver) Permissions(ctx context.Context, args *ListPermissionAr connectionStore.roleID = roleID } - return graphqlutil.NewConnectionResolver[PermissionResolver]( + return gqlutil.NewConnectionResolver[PermissionResolver]( &connectionStore, &args.ConnectionResolverArgs, - &graphqlutil.ConnectionResolverOptions{ + &gqlutil.ConnectionResolverOptions{ OrderBy: database.OrderBy{ {Field: "permissions.id"}, }, diff --git a/cmd/frontend/graphqlbackend/permissions_sync_jobs.go b/cmd/frontend/graphqlbackend/permissions_sync_jobs.go index 4eb2974fa18..794e163674a 100644 --- a/cmd/frontend/graphqlbackend/permissions_sync_jobs.go +++ b/cmd/frontend/graphqlbackend/permissions_sync_jobs.go @@ -4,7 +4,7 @@ import ( "context" "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" + "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) @@ -60,7 +60,7 @@ type PermissionsSyncJobSubject interface { } type ListPermissionsSyncJobsArgs struct { - graphqlutil.ConnectionResolverArgs + gqlutil.ConnectionResolverArgs ReasonGroup *database.PermissionsSyncJobReasonGroup State *database.PermissionsSyncJobState SearchType *database.PermissionsSyncSearchType diff --git a/cmd/frontend/graphqlbackend/prompts.go b/cmd/frontend/graphqlbackend/prompts.go index 6461a6e81a8..ccbe5023007 100644 --- a/cmd/frontend/graphqlbackend/prompts.go +++ b/cmd/frontend/graphqlbackend/prompts.go @@ -5,7 +5,6 @@ import ( "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) @@ -46,7 +45,7 @@ func (v PromptVisibility) IsSecret() bool { return v != PromptVisibilityPublic } -type PromptConnectionResolver = graphqlutil.ConnectionResolver[PromptResolver] +type PromptConnectionResolver = gqlutil.ConnectionResolver[PromptResolver] type PromptResolver interface { ID() graphql.ID @@ -74,7 +73,7 @@ func (r PromptDefinitionResolver) Text() string { } type PromptsArgs struct { - graphqlutil.ConnectionResolverArgs + gqlutil.ConnectionResolverArgs Query *string Owner *graphql.ID ViewerIsAffiliated *bool diff --git a/cmd/frontend/graphqlbackend/rbac.go b/cmd/frontend/graphqlbackend/rbac.go index d73502960b1..85858bc0886 100644 --- a/cmd/frontend/graphqlbackend/rbac.go +++ b/cmd/frontend/graphqlbackend/rbac.go @@ -5,7 +5,6 @@ import ( "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) @@ -14,7 +13,7 @@ type RoleResolver interface { Name() string System() bool CreatedAt() gqlutil.DateTime - Permissions(context.Context, *ListPermissionArgs) (*graphqlutil.ConnectionResolver[PermissionResolver], error) + Permissions(context.Context, *ListPermissionArgs) (*gqlutil.ConnectionResolver[PermissionResolver], error) } type PermissionResolver interface { @@ -43,14 +42,14 @@ type CreateRoleArgs struct { } type ListRoleArgs struct { - graphqlutil.ConnectionResolverArgs + gqlutil.ConnectionResolverArgs System bool User *graphql.ID } type ListPermissionArgs struct { - graphqlutil.ConnectionResolverArgs + gqlutil.ConnectionResolverArgs Role *graphql.ID User *graphql.ID diff --git a/cmd/frontend/graphqlbackend/recorded_commands.go b/cmd/frontend/graphqlbackend/recorded_commands.go index 17c547bd649..fd30acd1e25 100644 --- a/cmd/frontend/graphqlbackend/recorded_commands.go +++ b/cmd/frontend/graphqlbackend/recorded_commands.go @@ -4,7 +4,6 @@ import ( "context" "strings" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/conf" "github.com/sourcegraph/sourcegraph/internal/gqlutil" @@ -32,7 +31,7 @@ type RecordedCommandsArgs struct { Offset int32 } -func (r *RepositoryResolver) RecordedCommands(ctx context.Context, args *RecordedCommandsArgs) (graphqlutil.SliceConnectionResolver[RecordedCommandResolver], error) { +func (r *RepositoryResolver) RecordedCommands(ctx context.Context, args *RecordedCommandsArgs) (gqlutil.SliceConnectionResolver[RecordedCommandResolver], error) { // 🚨 SECURITY: Only site admins are allowed to view recorded commands err := auth.CheckCurrentUserIsSiteAdmin(ctx, r.db) if err != nil { @@ -49,7 +48,7 @@ func (r *RepositoryResolver) RecordedCommands(ctx context.Context, args *Recorde recordingConf := conf.Get().SiteConfig().GitRecorder if recordingConf == nil { - return graphqlutil.NewSliceConnectionResolver([]RecordedCommandResolver{}, 0, currentEnd), nil + return gqlutil.NewSliceConnectionResolver([]RecordedCommandResolver{}, 0, currentEnd), nil } store := rcache.NewFIFOList(redispool.Cache, wrexec.GetFIFOListKey(r.Name()), recordingConf.Size) empty, err := store.IsEmpty() @@ -57,7 +56,7 @@ func (r *RepositoryResolver) RecordedCommands(ctx context.Context, args *Recorde return nil, err } if empty { - return graphqlutil.NewSliceConnectionResolver([]RecordedCommandResolver{}, 0, currentEnd), nil + return gqlutil.NewSliceConnectionResolver([]RecordedCommandResolver{}, 0, currentEnd), nil } // the FIFO list is zero-indexed, so we need to deduct one from the limit @@ -82,7 +81,7 @@ func (r *RepositoryResolver) RecordedCommands(ctx context.Context, args *Recorde resolvers[i] = NewRecordedCommandResolver(command) } - return graphqlutil.NewSliceConnectionResolver(resolvers, size, currentEnd), nil + return gqlutil.NewSliceConnectionResolver(resolvers, size, currentEnd), nil } type RecordedCommandResolver interface { diff --git a/cmd/frontend/graphqlbackend/repositories.go b/cmd/frontend/graphqlbackend/repositories.go index 3bc63509334..cc563a5cf49 100644 --- a/cmd/frontend/graphqlbackend/repositories.go +++ b/cmd/frontend/graphqlbackend/repositories.go @@ -9,12 +9,12 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/sourcegraph/log" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/backend" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/dotcom" "github.com/sourcegraph/sourcegraph/internal/gitserver" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -39,7 +39,7 @@ type repositoryArgs struct { OrderBy string Descending bool - graphqlutil.ConnectionResolverArgs + gqlutil.ConnectionResolverArgs } func (args *repositoryArgs) toReposListOptions() (database.ReposListOptions, error) { @@ -102,7 +102,7 @@ func (args *repositoryArgs) toReposListOptions() (database.ReposListOptions, err return opt, nil } -func (r *schemaResolver) Repositories(ctx context.Context, args *repositoryArgs) (*graphqlutil.ConnectionResolver[*RepositoryResolver], error) { +func (r *schemaResolver) Repositories(ctx context.Context, args *repositoryArgs) (*gqlutil.ConnectionResolver[*RepositoryResolver], error) { opt, err := args.toReposListOptions() if err != nil { return nil, err @@ -123,13 +123,13 @@ func (r *schemaResolver) Repositories(ctx context.Context, args *repositoryArgs) orderBy = args.OrderBy } - connectionOptions := graphqlutil.ConnectionResolverOptions{ + connectionOptions := gqlutil.ConnectionResolverOptions{ MaxPageSize: maxPageSize, OrderBy: database.OrderBy{{Field: string(toDBRepoListColumn(orderBy))}, {Field: "id"}}, Ascending: !args.Descending, } - return graphqlutil.NewConnectionResolver[*RepositoryResolver](connectionStore, &args.ConnectionResolverArgs, &connectionOptions) + return gqlutil.NewConnectionResolver[*RepositoryResolver](connectionStore, &args.ConnectionResolverArgs, &connectionOptions) } type repositoriesConnectionStore struct { @@ -250,7 +250,7 @@ type TotalCountArgs struct { type RepositoryConnectionResolver interface { Nodes(ctx context.Context) ([]*RepositoryResolver, error) TotalCount(ctx context.Context, args *TotalCountArgs) (*int32, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) } func toDBRepoListColumn(ob string) database.RepoListColumn { diff --git a/cmd/frontend/graphqlbackend/repository.go b/cmd/frontend/graphqlbackend/repository.go index c3c59048ffd..1ada16c5da3 100644 --- a/cmd/frontend/graphqlbackend/repository.go +++ b/cmd/frontend/graphqlbackend/repository.go @@ -15,7 +15,6 @@ import ( "go.opentelemetry.io/otel/attribute" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/externallink" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/backend" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/auth" @@ -122,7 +121,7 @@ func (r *RepositoryResolver) EmbeddingExists(ctx context.Context) (bool, error) return r.db.Repos().RepoEmbeddingExists(ctx, r.IDInt32()) } -func (r *RepositoryResolver) EmbeddingJobs(ctx context.Context, args ListRepoEmbeddingJobsArgs) (*graphqlutil.ConnectionResolver[RepoEmbeddingJobResolver], error) { +func (r *RepositoryResolver) EmbeddingJobs(ctx context.Context, args ListRepoEmbeddingJobsArgs) (*gqlutil.ConnectionResolver[RepoEmbeddingJobResolver], error) { // Ensure that we only return jobs for this repository. gqlID := r.ID() args.Repo = &gqlID diff --git a/cmd/frontend/graphqlbackend/repository_comparison.go b/cmd/frontend/graphqlbackend/repository_comparison.go index e880c0e55ee..334ec2c9609 100644 --- a/cmd/frontend/graphqlbackend/repository_comparison.go +++ b/cmd/frontend/graphqlbackend/repository_comparison.go @@ -15,12 +15,12 @@ import ( "github.com/sourcegraph/conc/pool" "github.com/sourcegraph/go-diff/diff" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/highlight" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gitserver" "github.com/sourcegraph/sourcegraph/internal/gosyntect" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/lib/errors" "github.com/sourcegraph/sourcegraph/lib/pointers" ) @@ -48,7 +48,7 @@ type RepositoryComparisonInterface interface { type FileDiffConnection interface { Nodes(ctx context.Context) ([]FileDiff, error) TotalCount(ctx context.Context) (*int32, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) DiffStat(ctx context.Context) (*DiffStat, error) RawDiff(ctx context.Context) (string, error) } @@ -168,7 +168,7 @@ func (r *RepositoryComparisonResolver) Range() *gitRevisionRange { // RepositoryComparisonCommitsArgs is a set of arguments for listing commits on the RepositoryComparisonResolver type RepositoryComparisonCommitsArgs struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs Path *string } @@ -363,19 +363,19 @@ func (r *fileDiffConnectionResolver) TotalCount(ctx context.Context) (*int32, er return nil, nil // total count is not available } -func (r *fileDiffConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *fileDiffConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { _, afterIdx, hasNextPage, err := r.compute(ctx, r.args) if err != nil { return nil, err } if !hasNextPage { - return graphqlutil.HasNextPage(hasNextPage), nil + return gqlutil.HasNextPage(hasNextPage), nil } next := afterIdx if r.args.First != nil { next += *r.args.First } - return graphqlutil.NextPageCursor(strconv.Itoa(int(next))), nil + return gqlutil.NextPageCursor(strconv.Itoa(int(next))), nil } func (r *fileDiffConnectionResolver) DiffStat(ctx context.Context) (*DiffStat, error) { diff --git a/cmd/frontend/graphqlbackend/repository_contributors.go b/cmd/frontend/graphqlbackend/repository_contributors.go index 33e08859661..2820d09524a 100644 --- a/cmd/frontend/graphqlbackend/repository_contributors.go +++ b/cmd/frontend/graphqlbackend/repository_contributors.go @@ -6,10 +6,10 @@ import ( "sync" "time" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gitserver" "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -21,8 +21,8 @@ type repositoryContributorsArgs struct { func (r *RepositoryResolver) Contributors(args *struct { repositoryContributorsArgs - graphqlutil.ConnectionResolverArgs -}) (*graphqlutil.ConnectionResolver[*repositoryContributorResolver], error) { + gqlutil.ConnectionResolverArgs +}) (*gqlutil.ConnectionResolver[*repositoryContributorResolver], error) { var after time.Time if args.AfterDate != nil && *args.AfterDate != "" { var err error @@ -39,10 +39,10 @@ func (r *RepositoryResolver) Contributors(args *struct { repo: r, } reverse := false - connectionOptions := graphqlutil.ConnectionResolverOptions{ + connectionOptions := gqlutil.ConnectionResolverOptions{ Reverse: &reverse, } - return graphqlutil.NewConnectionResolver[*repositoryContributorResolver](connectionStore, &args.ConnectionResolverArgs, &connectionOptions) + return gqlutil.NewConnectionResolver[*repositoryContributorResolver](connectionStore, &args.ConnectionResolverArgs, &connectionOptions) } type repositoryContributorConnectionStore struct { diff --git a/cmd/frontend/graphqlbackend/repository_external.go b/cmd/frontend/graphqlbackend/repository_external.go index f5c27b0711c..7a8f94d39bd 100644 --- a/cmd/frontend/graphqlbackend/repository_external.go +++ b/cmd/frontend/graphqlbackend/repository_external.go @@ -3,9 +3,9 @@ package graphqlbackend import ( "context" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" ) @@ -43,7 +43,7 @@ func (r *externalRepositoryResolver) ServiceID(ctx context.Context) (string, err } func (r *RepositoryResolver) ExternalServices(ctx context.Context, args *struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs }) (*ComputedExternalServiceConnectionResolver, error) { // 🚨 SECURITY: Only site admins may read external services (they have secrets). if err := auth.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil { diff --git a/cmd/frontend/graphqlbackend/repository_git_refs.go b/cmd/frontend/graphqlbackend/repository_git_refs.go index 9869e789f1b..5afafca9503 100644 --- a/cmd/frontend/graphqlbackend/repository_git_refs.go +++ b/cmd/frontend/graphqlbackend/repository_git_refs.go @@ -4,12 +4,12 @@ import ( "context" "strings" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/gitserver" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) type refsArgs struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs Query *string Type *string } @@ -81,6 +81,6 @@ func (r *gitRefConnectionResolver) TotalCount() int32 { return int32(len(r.refs)) } -func (r *gitRefConnectionResolver) PageInfo() *graphqlutil.PageInfo { - return graphqlutil.HasNextPage(r.first != nil && int(*r.first) < len(r.refs)) +func (r *gitRefConnectionResolver) PageInfo() *gqlutil.PageInfo { + return gqlutil.HasNextPage(r.first != nil && int(*r.first) < len(r.refs)) } diff --git a/cmd/frontend/graphqlbackend/repository_metadata.go b/cmd/frontend/graphqlbackend/repository_metadata.go index 5080d242356..cbf4451caf0 100644 --- a/cmd/frontend/graphqlbackend/repository_metadata.go +++ b/cmd/frontend/graphqlbackend/repository_metadata.go @@ -8,11 +8,11 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/graph-gophers/graphql-go/relay" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/deviceid" "github.com/sourcegraph/sourcegraph/internal/featureflag" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/rbac" "github.com/sourcegraph/sourcegraph/internal/usagestats" "github.com/sourcegraph/sourcegraph/lib/errors" @@ -188,10 +188,10 @@ func (r *schemaResolver) RepoMeta(ctx context.Context) (*repoMetaResolver, error type RepoMetadataKeysArgs struct { database.RepoKVPListKeysOptions - graphqlutil.ConnectionResolverArgs + gqlutil.ConnectionResolverArgs } -func (r *repoMetaResolver) Keys(ctx context.Context, args *RepoMetadataKeysArgs) (*graphqlutil.ConnectionResolver[string], error) { +func (r *repoMetaResolver) Keys(ctx context.Context, args *RepoMetadataKeysArgs) (*gqlutil.ConnectionResolver[string], error) { if err := rbac.CheckCurrentUserHasPermission(ctx, r.db, rbac.RepoMetadataWritePermission); err != nil { return nil, err } @@ -207,12 +207,12 @@ func (r *repoMetaResolver) Keys(ctx context.Context, args *RepoMetadataKeysArgs) } reverse := false - connectionOptions := graphqlutil.ConnectionResolverOptions{ + connectionOptions := gqlutil.ConnectionResolverOptions{ Reverse: &reverse, OrderBy: database.OrderBy{{Field: string(database.RepoKVPListKeyColumn)}}, Ascending: true, } - return graphqlutil.NewConnectionResolver[string](connectionStore, &args.ConnectionResolverArgs, &connectionOptions) + return gqlutil.NewConnectionResolver[string](connectionStore, &args.ConnectionResolverArgs, &connectionOptions) } type repoMetaKeysConnectionStore struct { @@ -258,10 +258,10 @@ type repoMetaKeyResolver struct { type RepoMetadataValuesArgs struct { Query *string - graphqlutil.ConnectionResolverArgs + gqlutil.ConnectionResolverArgs } -func (r *repoMetaKeyResolver) Values(ctx context.Context, args *RepoMetadataValuesArgs) (*graphqlutil.ConnectionResolver[string], error) { +func (r *repoMetaKeyResolver) Values(ctx context.Context, args *RepoMetadataValuesArgs) (*gqlutil.ConnectionResolver[string], error) { if err := rbac.CheckCurrentUserHasPermission(ctx, r.db, rbac.RepoMetadataWritePermission); err != nil { return nil, err } @@ -279,12 +279,12 @@ func (r *repoMetaKeyResolver) Values(ctx context.Context, args *RepoMetadataValu } reverse := false - connectionOptions := graphqlutil.ConnectionResolverOptions{ + connectionOptions := gqlutil.ConnectionResolverOptions{ Reverse: &reverse, OrderBy: database.OrderBy{{Field: string(database.RepoKVPListValueColumn)}}, Ascending: true, } - return graphqlutil.NewConnectionResolver[string](connectionStore, &args.ConnectionResolverArgs, &connectionOptions) + return gqlutil.NewConnectionResolver[string](connectionStore, &args.ConnectionResolverArgs, &connectionOptions) } type repoMetaValuesConnectionStore struct { diff --git a/cmd/frontend/graphqlbackend/role.go b/cmd/frontend/graphqlbackend/role.go index 4e38035c97f..351b022f49a 100644 --- a/cmd/frontend/graphqlbackend/role.go +++ b/cmd/frontend/graphqlbackend/role.go @@ -6,7 +6,6 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/graph-gophers/graphql-go/relay" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gqlutil" @@ -45,7 +44,7 @@ func (r *roleResolver) System() bool { return r.role.System } -func (r *roleResolver) Permissions(ctx context.Context, args *ListPermissionArgs) (*graphqlutil.ConnectionResolver[PermissionResolver], error) { +func (r *roleResolver) Permissions(ctx context.Context, args *ListPermissionArgs) (*gqlutil.ConnectionResolver[PermissionResolver], error) { // 🚨 SECURITY: Only viewable by site admins. if err := auth.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil { return nil, err @@ -58,10 +57,10 @@ func (r *roleResolver) Permissions(ctx context.Context, args *ListPermissionArgs db: r.db, roleID: r.role.ID, } - return graphqlutil.NewConnectionResolver[PermissionResolver]( + return gqlutil.NewConnectionResolver[PermissionResolver]( connectionStore, &args.ConnectionResolverArgs, - &graphqlutil.ConnectionResolverOptions{ + &gqlutil.ConnectionResolverOptions{ AllowNoLimit: true, }, ) diff --git a/cmd/frontend/graphqlbackend/roles.go b/cmd/frontend/graphqlbackend/roles.go index a6b798c7bab..0d87c7bbac8 100644 --- a/cmd/frontend/graphqlbackend/roles.go +++ b/cmd/frontend/graphqlbackend/roles.go @@ -5,13 +5,13 @@ import ( "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/lib/errors" ) -func (r *schemaResolver) Roles(ctx context.Context, args *ListRoleArgs) (*graphqlutil.ConnectionResolver[RoleResolver], error) { +func (r *schemaResolver) Roles(ctx context.Context, args *ListRoleArgs) (*gqlutil.ConnectionResolver[RoleResolver], error) { connectionStore := roleConnectionStore{ db: r.db, system: args.System, @@ -37,10 +37,10 @@ func (r *schemaResolver) Roles(ctx context.Context, args *ListRoleArgs) (*graphq return nil, err } - return graphqlutil.NewConnectionResolver[RoleResolver]( + return gqlutil.NewConnectionResolver[RoleResolver]( &connectionStore, &args.ConnectionResolverArgs, - &graphqlutil.ConnectionResolverOptions{ + &gqlutil.ConnectionResolverOptions{ OrderBy: database.OrderBy{ {Field: "roles.system"}, {Field: "roles.created_at"}, diff --git a/cmd/frontend/graphqlbackend/saved_searches.go b/cmd/frontend/graphqlbackend/saved_searches.go index affc06a557e..a7d4fff8207 100644 --- a/cmd/frontend/graphqlbackend/saved_searches.go +++ b/cmd/frontend/graphqlbackend/saved_searches.go @@ -5,7 +5,6 @@ import ( "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) @@ -46,7 +45,7 @@ func (v SavedSearchVisibility) IsSecret() bool { return v != SavedSearchVisibilityPublic } -type SavedSearchConnectionResolver = graphqlutil.ConnectionResolver[SavedSearchResolver] +type SavedSearchConnectionResolver = gqlutil.ConnectionResolver[SavedSearchResolver] type SavedSearchResolver interface { ID() graphql.ID @@ -64,7 +63,7 @@ type SavedSearchResolver interface { } type SavedSearchesArgs struct { - graphqlutil.ConnectionResolverArgs + gqlutil.ConnectionResolverArgs Query *string Owner *graphql.ID ViewerIsAffiliated *bool diff --git a/cmd/frontend/graphqlbackend/search.go b/cmd/frontend/graphqlbackend/search.go index fb802628e4d..9d373b3845c 100644 --- a/cmd/frontend/graphqlbackend/search.go +++ b/cmd/frontend/graphqlbackend/search.go @@ -8,10 +8,10 @@ import ( "github.com/graph-gophers/graphql-go/relay" "github.com/sourcegraph/log" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gitserver" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/search" "github.com/sourcegraph/sourcegraph/internal/search/client" "github.com/sourcegraph/sourcegraph/lib/errors" @@ -106,7 +106,7 @@ func (r *schemaResolver) indexedSearchInstanceByID(ctx context.Context, id graph return &indexedSearchInstance{address: address}, nil } -func (r *schemaResolver) IndexedSearchInstances(ctx context.Context) (graphqlutil.SliceConnectionResolver[*indexedSearchInstance], error) { +func (r *schemaResolver) IndexedSearchInstances(ctx context.Context) (gqlutil.SliceConnectionResolver[*indexedSearchInstance], error) { // 🚨 SECURITY: Site admins only. if err := auth.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil { return nil, err @@ -126,5 +126,5 @@ func (r *schemaResolver) IndexedSearchInstances(ctx context.Context) (graphqluti } n := len(resolvers) - return graphqlutil.NewSliceConnectionResolver(resolvers, n, n), nil + return gqlutil.NewSliceConnectionResolver(resolvers, n, n), nil } diff --git a/cmd/frontend/graphqlbackend/search_contexts.go b/cmd/frontend/graphqlbackend/search_contexts.go index 32deefb5114..0286ac5c1f9 100644 --- a/cmd/frontend/graphqlbackend/search_contexts.go +++ b/cmd/frontend/graphqlbackend/search_contexts.go @@ -5,7 +5,6 @@ import ( "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" ) @@ -56,7 +55,7 @@ type SearchContextResolver interface { type SearchContextConnectionResolver interface { Nodes() []SearchContextResolver TotalCount() int32 - PageInfo() *graphqlutil.PageInfo + PageInfo() *gqlutil.PageInfo } type SearchContextRepositoryRevisionsResolver interface { diff --git a/cmd/frontend/graphqlbackend/search_jobs.go b/cmd/frontend/graphqlbackend/search_jobs.go index bccbe32aa0a..b3d520a392d 100644 --- a/cmd/frontend/graphqlbackend/search_jobs.go +++ b/cmd/frontend/graphqlbackend/search_jobs.go @@ -5,7 +5,6 @@ import ( "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) @@ -16,7 +15,7 @@ type SearchJobsResolver interface { DeleteSearchJob(ctx context.Context, args *DeleteSearchJobArgs) (*EmptyResponse, error) // Queries - SearchJobs(ctx context.Context, args *SearchJobsArgs) (*graphqlutil.ConnectionResolver[SearchJobResolver], error) + SearchJobs(ctx context.Context, args *SearchJobsArgs) (*gqlutil.ConnectionResolver[SearchJobResolver], error) ValidateSearchJob(ctx context.Context, args *CreateSearchJobArgs) (*EmptyResponse, error) NodeResolvers() map[string]NodeByIDFunc @@ -83,7 +82,7 @@ type SearchJobArgs struct { } type SearchJobsArgs struct { - graphqlutil.ConnectionResolverArgs + gqlutil.ConnectionResolverArgs Query *string States *[]string OrderBy string @@ -93,6 +92,6 @@ type SearchJobsArgs struct { type SearchJobsConnectionResolver interface { TotalCount(ctx context.Context) (int32, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) Nodes(ctx context.Context) ([]SearchJobResolver, error) } diff --git a/cmd/frontend/graphqlbackend/site.go b/cmd/frontend/graphqlbackend/site.go index 50e27f63ca7..e91a857d189 100644 --- a/cmd/frontend/graphqlbackend/site.go +++ b/cmd/frontend/graphqlbackend/site.go @@ -15,7 +15,6 @@ import ( "github.com/graph-gophers/graphql-go/relay" "github.com/sourcegraph/log" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cody" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/auth" @@ -276,7 +275,7 @@ func (r *siteConfigurationResolver) ValidationMessages(ctx context.Context) ([]s return conf.ValidateSite(string(contents)) } -func (r *siteConfigurationResolver) History(ctx context.Context, args *graphqlutil.ConnectionResolverArgs) (*graphqlutil.ConnectionResolver[*SiteConfigurationChangeResolver], error) { +func (r *siteConfigurationResolver) History(ctx context.Context, args *gqlutil.ConnectionResolverArgs) (*gqlutil.ConnectionResolver[*SiteConfigurationChangeResolver], error) { // 🚨 SECURITY: The site configuration contains secret tokens and credentials, // so only admins may view the history. if err := auth.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil { @@ -285,7 +284,7 @@ func (r *siteConfigurationResolver) History(ctx context.Context, args *graphqlut connectionStore := SiteConfigurationChangeConnectionStore{db: r.db} - return graphqlutil.NewConnectionResolver[*SiteConfigurationChangeResolver]( + return gqlutil.NewConnectionResolver[*SiteConfigurationChangeResolver]( &connectionStore, args, nil, diff --git a/cmd/frontend/graphqlbackend/site_config_change_test.go b/cmd/frontend/graphqlbackend/site_config_change_test.go index f23647402cf..9d41ca23bce 100644 --- a/cmd/frontend/graphqlbackend/site_config_change_test.go +++ b/cmd/frontend/graphqlbackend/site_config_change_test.go @@ -6,9 +6,9 @@ import ( "github.com/google/go-cmp/cmp" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/gitserver" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/lib/pointers" ) @@ -57,17 +57,17 @@ func TestSiteConfigurationDiff(t *testing.T) { testCases := []struct { name string - args *graphqlutil.ConnectionResolverArgs + args *gqlutil.ConnectionResolverArgs }{ // We have tests for pagination so we can skip that here and just check for the diff for all // the nodes in both the directions. { name: "first: 10", - args: &graphqlutil.ConnectionResolverArgs{First: pointers.Ptr(int32(10))}, + args: &gqlutil.ConnectionResolverArgs{First: pointers.Ptr(int32(10))}, }, { name: "last: 10", - args: &graphqlutil.ConnectionResolverArgs{Last: pointers.Ptr(int32(10))}, + args: &gqlutil.ConnectionResolverArgs{Last: pointers.Ptr(int32(10))}, }, } diff --git a/cmd/frontend/graphqlbackend/site_test.go b/cmd/frontend/graphqlbackend/site_test.go index be247130e51..3fb88bfeffe 100644 --- a/cmd/frontend/graphqlbackend/site_test.go +++ b/cmd/frontend/graphqlbackend/site_test.go @@ -11,12 +11,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/database/dbmocks" "github.com/sourcegraph/sourcegraph/internal/gitserver" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/oobmigration" "github.com/sourcegraph/sourcegraph/internal/types" "github.com/sourcegraph/sourcegraph/lib/errors" @@ -174,42 +174,42 @@ func TestSiteConfigurationHistory(t *testing.T) { testCases := []struct { name string - args *graphqlutil.ConnectionResolverArgs + args *gqlutil.ConnectionResolverArgs expectedSiteConfigIDs []int32 }{ { name: "first: 2", - args: &graphqlutil.ConnectionResolverArgs{First: pointers.Ptr(int32(2))}, + args: &gqlutil.ConnectionResolverArgs{First: pointers.Ptr(int32(2))}, expectedSiteConfigIDs: []int32{6, 4}, }, { name: "first: 6 (exact number of items that exist in the database)", - args: &graphqlutil.ConnectionResolverArgs{First: pointers.Ptr(int32(6))}, + args: &gqlutil.ConnectionResolverArgs{First: pointers.Ptr(int32(6))}, expectedSiteConfigIDs: []int32{6, 4, 3, 2, 1}, }, { name: "first: 20 (more items than what exists in the database)", - args: &graphqlutil.ConnectionResolverArgs{First: pointers.Ptr(int32(20))}, + args: &gqlutil.ConnectionResolverArgs{First: pointers.Ptr(int32(20))}, expectedSiteConfigIDs: []int32{6, 4, 3, 2, 1}, }, { name: "last: 2", - args: &graphqlutil.ConnectionResolverArgs{Last: pointers.Ptr(int32(2))}, + args: &gqlutil.ConnectionResolverArgs{Last: pointers.Ptr(int32(2))}, expectedSiteConfigIDs: []int32{2, 1}, }, { name: "last: 6 (exact number of items that exist in the database)", - args: &graphqlutil.ConnectionResolverArgs{Last: pointers.Ptr(int32(6))}, + args: &gqlutil.ConnectionResolverArgs{Last: pointers.Ptr(int32(6))}, expectedSiteConfigIDs: []int32{6, 4, 3, 2, 1}, }, { name: "last: 20 (more items than what exists in the database)", - args: &graphqlutil.ConnectionResolverArgs{Last: pointers.Ptr(int32(20))}, + args: &gqlutil.ConnectionResolverArgs{Last: pointers.Ptr(int32(20))}, expectedSiteConfigIDs: []int32{6, 4, 3, 2, 1}, }, { name: "first: 2, after: 4", - args: &graphqlutil.ConnectionResolverArgs{ + args: &gqlutil.ConnectionResolverArgs{ First: pointers.Ptr(int32(2)), After: pointers.Ptr(string(marshalSiteConfigurationChangeID(4))), }, @@ -217,7 +217,7 @@ func TestSiteConfigurationHistory(t *testing.T) { }, { name: "first: 10, after: 4 (overflow)", - args: &graphqlutil.ConnectionResolverArgs{ + args: &gqlutil.ConnectionResolverArgs{ First: pointers.Ptr(int32(10)), After: pointers.Ptr(string(marshalSiteConfigurationChangeID(4))), }, @@ -225,7 +225,7 @@ func TestSiteConfigurationHistory(t *testing.T) { }, { name: "first: 10, after: 7 (same as get all items, but latest ID in DB is 6)", - args: &graphqlutil.ConnectionResolverArgs{ + args: &gqlutil.ConnectionResolverArgs{ First: pointers.Ptr(int32(10)), After: pointers.Ptr(string(marshalSiteConfigurationChangeID(7))), }, @@ -233,7 +233,7 @@ func TestSiteConfigurationHistory(t *testing.T) { }, { name: "first: 10, after: 1 (beyond the last cursor in DB which is 1)", - args: &graphqlutil.ConnectionResolverArgs{ + args: &gqlutil.ConnectionResolverArgs{ First: pointers.Ptr(int32(10)), After: pointers.Ptr(string(marshalSiteConfigurationChangeID(1))), }, @@ -241,7 +241,7 @@ func TestSiteConfigurationHistory(t *testing.T) { }, { name: "last: 2, before: 1", - args: &graphqlutil.ConnectionResolverArgs{ + args: &gqlutil.ConnectionResolverArgs{ Last: pointers.Ptr(int32(2)), Before: pointers.Ptr(string(marshalSiteConfigurationChangeID(1))), }, @@ -249,7 +249,7 @@ func TestSiteConfigurationHistory(t *testing.T) { }, { name: "last: 10, before: 1 (overflow)", - args: &graphqlutil.ConnectionResolverArgs{ + args: &gqlutil.ConnectionResolverArgs{ Last: pointers.Ptr(int32(10)), Before: pointers.Ptr(string(marshalSiteConfigurationChangeID(1))), }, @@ -257,7 +257,7 @@ func TestSiteConfigurationHistory(t *testing.T) { }, { name: "last: 10, before: 0 (same as get all items, but oldest ID in DB is 1)", - args: &graphqlutil.ConnectionResolverArgs{ + args: &gqlutil.ConnectionResolverArgs{ Last: pointers.Ptr(int32(10)), Before: pointers.Ptr(string(marshalSiteConfigurationChangeID(0))), }, @@ -265,7 +265,7 @@ func TestSiteConfigurationHistory(t *testing.T) { }, { name: "last: 10, before: 7 (beyond the latest cursor in DB which is 6)", - args: &graphqlutil.ConnectionResolverArgs{ + args: &gqlutil.ConnectionResolverArgs{ Last: pointers.Ptr(int32(10)), Before: pointers.Ptr(string(marshalSiteConfigurationChangeID(7))), }, diff --git a/cmd/frontend/graphqlbackend/slow_requests_tracer.go b/cmd/frontend/graphqlbackend/slow_requests_tracer.go index 92ff4973863..a5be95c6767 100644 --- a/cmd/frontend/graphqlbackend/slow_requests_tracer.go +++ b/cmd/frontend/graphqlbackend/slow_requests_tracer.go @@ -8,7 +8,6 @@ import ( "github.com/sourcegraph/log" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/conf" @@ -144,7 +143,7 @@ func (r *slowRequestConnectionResolver) TotalCount(ctx context.Context) (int32, return r.totalCount, err } -func (r *slowRequestConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *slowRequestConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { reqs, err := r.fetch(ctx) if err != nil { return nil, err @@ -159,9 +158,9 @@ func (r *slowRequestConnectionResolver) PageInfo(ctx context.Context) (*graphqlu return nil, err } if int32(n+r.perPage) >= total { - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } else { - return graphqlutil.NextPageCursor(reqs[len(reqs)-1].Index), nil + return gqlutil.NextPageCursor(reqs[len(reqs)-1].Index), nil } } diff --git a/cmd/frontend/graphqlbackend/survey_responses.go b/cmd/frontend/graphqlbackend/survey_responses.go index 4989904ddc8..8ccfa2ff4ed 100644 --- a/cmd/frontend/graphqlbackend/survey_responses.go +++ b/cmd/frontend/graphqlbackend/survey_responses.go @@ -3,9 +3,9 @@ package graphqlbackend import ( "context" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) type surveyResponseConnectionResolver struct { @@ -14,7 +14,7 @@ type surveyResponseConnectionResolver struct { } func (r *schemaResolver) SurveyResponses(args *struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs }) *surveyResponseConnectionResolver { var opt database.SurveyResponseListOptions args.ConnectionArgs.Set(&opt.LimitOffset) diff --git a/cmd/frontend/graphqlbackend/symbols.go b/cmd/frontend/graphqlbackend/symbols.go index 4fb4039678a..43be4f5932c 100644 --- a/cmd/frontend/graphqlbackend/symbols.go +++ b/cmd/frontend/graphqlbackend/symbols.go @@ -4,17 +4,17 @@ import ( "context" "strings" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gitserver" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/search/result" "github.com/sourcegraph/sourcegraph/internal/search/symbol" "github.com/sourcegraph/sourcegraph/internal/types" ) type symbolsArgs struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs Query *string IncludePatterns *[]string } @@ -111,8 +111,8 @@ func (r *symbolConnectionResolver) Nodes(ctx context.Context) ([]symbolResolver, return symbols, nil } -func (r *symbolConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { - return graphqlutil.HasNextPage(len(r.symbols) > limitOrDefault(r.first)), nil +func (r *symbolConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { + return gqlutil.HasNextPage(len(r.symbols) > limitOrDefault(r.first)), nil } type symbolResolver struct { diff --git a/cmd/frontend/graphqlbackend/teams.go b/cmd/frontend/graphqlbackend/teams.go index 3d3b699788e..ffe79ae2bb7 100644 --- a/cmd/frontend/graphqlbackend/teams.go +++ b/cmd/frontend/graphqlbackend/teams.go @@ -11,12 +11,12 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/graph-gophers/graphql-go/relay" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/dotcom" "github.com/sourcegraph/sourcegraph/internal/errcode" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/own" "github.com/sourcegraph/sourcegraph/internal/types" "github.com/sourcegraph/sourcegraph/lib/errors" @@ -50,7 +50,7 @@ type teamConnectionResolver struct { teams []*types.Team onlyRootTeams bool exceptAncestorID int32 - pageInfo *graphqlutil.PageInfo + pageInfo *gqlutil.PageInfo err error } @@ -58,7 +58,7 @@ type teamConnectionResolver struct { // into `teamConnectionResolver` fields for convenient use in database query. func (r *teamConnectionResolver) applyArgs(args *ListTeamsArgs) error { if args.After != nil { - cursor, err := graphqlutil.DecodeIntCursor(args.After) + cursor, err := gqlutil.DecodeIntCursor(args.After) if err != nil { return err } @@ -100,9 +100,9 @@ func (r *teamConnectionResolver) compute(ctx context.Context) { } r.teams = teams if next > 0 { - r.pageInfo = graphqlutil.EncodeIntCursor(&next) + r.pageInfo = gqlutil.EncodeIntCursor(&next) } else { - r.pageInfo = graphqlutil.HasNextPage(false) + r.pageInfo = gqlutil.HasNextPage(false) } }) } @@ -117,7 +117,7 @@ func (r *teamConnectionResolver) TotalCount(ctx context.Context) (int32, error) return r.db.Teams().CountTeams(ctx, opts) } -func (r *teamConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *teamConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { r.compute(ctx) return r.pageInfo, r.err } @@ -262,7 +262,7 @@ type teamMemberConnection struct { limit int once sync.Once nodes []*types.TeamMember - pageInfo *graphqlutil.PageInfo + pageInfo *gqlutil.PageInfo err error } @@ -275,7 +275,7 @@ type teamMemberListCursor struct { // into `teamMemberConnection` fields for convenient use in database query. func (r *teamMemberConnection) applyArgs(args *ListTeamMembersArgs) error { if args.After != nil && *args.After != "" { - cursorText, err := graphqlutil.DecodeCursor(args.After) + cursorText, err := gqlutil.DecodeCursor(args.After) if err != nil { return err } @@ -326,9 +326,9 @@ func (r *teamMemberConnection) compute(ctx context.Context) { r.err = errors.Wrap(err, "error encoding pageInfo") } cursorString := string(cursorBytes) - r.pageInfo = graphqlutil.EncodeCursor(&cursorString) + r.pageInfo = gqlutil.EncodeCursor(&cursorString) } else { - r.pageInfo = graphqlutil.HasNextPage(false) + r.pageInfo = gqlutil.HasNextPage(false) } }) } @@ -342,7 +342,7 @@ func (r *teamMemberConnection) TotalCount(ctx context.Context) (int32, error) { return r.db.Teams().CountTeamMembers(ctx, opts) } -func (r *teamMemberConnection) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *teamMemberConnection) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { r.compute(ctx) if r.err != nil { return nil, r.err diff --git a/cmd/frontend/graphqlbackend/telemetry.go b/cmd/frontend/graphqlbackend/telemetry.go index ce25d9a02f5..23021decb31 100644 --- a/cmd/frontend/graphqlbackend/telemetry.go +++ b/cmd/frontend/graphqlbackend/telemetry.go @@ -5,7 +5,6 @@ import ( "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) @@ -37,7 +36,7 @@ type ExportedEventResolver interface { type ExportedEventsConnectionResolver interface { Nodes() []ExportedEventResolver TotalCount() (int32, error) - PageInfo() *graphqlutil.PageInfo + PageInfo() *gqlutil.PageInfo } type RecordEventArgs struct{ Event TelemetryEventInput } diff --git a/cmd/frontend/graphqlbackend/user.go b/cmd/frontend/graphqlbackend/user.go index a97c44de37f..2e33a33dd29 100644 --- a/cmd/frontend/graphqlbackend/user.go +++ b/cmd/frontend/graphqlbackend/user.go @@ -7,22 +7,19 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/graph-gophers/graphql-go/relay" - - "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cody" - "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/ssc" - "github.com/sourcegraph/sourcegraph/internal/dotcom" - "github.com/keegancsmith/sqlf" "github.com/sourcegraph/log" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/auth/providers" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/backend" + "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cody" + "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/ssc" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/suspiciousnames" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/conf" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/dotcom" "github.com/sourcegraph/sourcegraph/internal/errcode" "github.com/sourcegraph/sourcegraph/internal/featureflag" "github.com/sourcegraph/sourcegraph/internal/gqlutil" @@ -766,7 +763,7 @@ func (r *UserResolver) BatchChangesCodeHosts(ctx context.Context, args *ListBatc return EnterpriseResolvers.batchChangesResolver.BatchChangesCodeHosts(ctx, args) } -func (r *UserResolver) Roles(ctx context.Context, args *ListRoleArgs) (*graphqlutil.ConnectionResolver[RoleResolver], error) { +func (r *UserResolver) Roles(ctx context.Context, args *ListRoleArgs) (*gqlutil.ConnectionResolver[RoleResolver], error) { // 🚨 SECURITY: In dotcom mode, only allow site admins to check roles. if dotcom.SourcegraphDotComMode() && auth.CheckCurrentUserIsSiteAdmin(ctx, r.db) != nil { return nil, errors.New("unauthorized") @@ -776,16 +773,16 @@ func (r *UserResolver) Roles(ctx context.Context, args *ListRoleArgs) (*graphqlu db: r.db, userID: userID, } - return graphqlutil.NewConnectionResolver[RoleResolver]( + return gqlutil.NewConnectionResolver[RoleResolver]( connectionStore, &args.ConnectionResolverArgs, - &graphqlutil.ConnectionResolverOptions{ + &gqlutil.ConnectionResolverOptions{ AllowNoLimit: true, }, ) } -func (r *UserResolver) Permissions() (*graphqlutil.ConnectionResolver[PermissionResolver], error) { +func (r *UserResolver) Permissions() (*gqlutil.ConnectionResolver[PermissionResolver], error) { userID := r.user.ID if err := auth.CheckSiteAdminOrSameUserFromActor(r.actor, r.db, userID); err != nil { return nil, err @@ -794,10 +791,10 @@ func (r *UserResolver) Permissions() (*graphqlutil.ConnectionResolver[Permission db: r.db, userID: userID, } - return graphqlutil.NewConnectionResolver[PermissionResolver]( + return gqlutil.NewConnectionResolver[PermissionResolver]( connectionStore, - &graphqlutil.ConnectionResolverArgs{}, - &graphqlutil.ConnectionResolverOptions{ + &gqlutil.ConnectionResolverArgs{}, + &gqlutil.ConnectionResolverOptions{ AllowNoLimit: true, }, ) diff --git a/cmd/frontend/graphqlbackend/users.go b/cmd/frontend/graphqlbackend/users.go index e275567588e..6a02a665dba 100644 --- a/cmd/frontend/graphqlbackend/users.go +++ b/cmd/frontend/graphqlbackend/users.go @@ -5,7 +5,6 @@ import ( "strconv" "sync" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/dotcom" @@ -16,7 +15,7 @@ import ( ) type usersArgs struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs After *string Query *string ActivePeriod *string @@ -55,7 +54,7 @@ func (r *schemaResolver) Users(ctx context.Context, args *usersArgs) (*userConne type UserConnectionResolver interface { Nodes(ctx context.Context) ([]*UserResolver, error) TotalCount(ctx context.Context) (int32, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) } var _ UserConnectionResolver = &userConnectionResolver{} @@ -120,7 +119,7 @@ func (r *userConnectionResolver) TotalCount(ctx context.Context) (int32, error) return int32(count), err } -func (r *userConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *userConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { users, totalCount, err := r.compute(ctx) if err != nil { return nil, err @@ -128,18 +127,18 @@ func (r *userConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.Pag // We would have had all results when no limit set if r.opt.LimitOffset == nil { - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } after := r.opt.LimitOffset.Offset + len(users) // We got less results than limit, means we've had all results if after < r.opt.Limit { - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } if totalCount > after { - return graphqlutil.NextPageCursor(strconv.Itoa(after)), nil + return gqlutil.NextPageCursor(strconv.Itoa(after)), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } diff --git a/cmd/frontend/graphqlbackend/viewer.go b/cmd/frontend/graphqlbackend/viewer.go index 69a47138121..6db949d34c5 100644 --- a/cmd/frontend/graphqlbackend/viewer.go +++ b/cmd/frontend/graphqlbackend/viewer.go @@ -3,9 +3,9 @@ package graphqlbackend import ( "context" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) func (r *schemaResolver) Viewer(ctx context.Context) (*viewerResolver, error) { @@ -27,7 +27,7 @@ func (r *schemaResolver) Viewer(ctx context.Context) (*viewerResolver, error) { // viewer is the interface for the GraphQL viewer interface. type viewer interface { - AffiliatedNamespaces(ctx context.Context) (graphqlutil.SliceConnectionResolver[*NamespaceResolver], error) + AffiliatedNamespaces(ctx context.Context) (gqlutil.SliceConnectionResolver[*NamespaceResolver], error) } // viewerResolver resolves the GraphQL Viewer interface to a type. diff --git a/cmd/frontend/graphqlbackend/webhook_logs.go b/cmd/frontend/graphqlbackend/webhook_logs.go index 4bd3489f6a4..aea20f0605b 100644 --- a/cmd/frontend/graphqlbackend/webhook_logs.go +++ b/cmd/frontend/graphqlbackend/webhook_logs.go @@ -12,7 +12,6 @@ import ( "github.com/sourcegraph/log" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/encryption/keyring" @@ -25,7 +24,7 @@ import ( // access to webhook logs: the webhookLogs method on the top level query, and on // the ExternalService type. type WebhookLogsArgs struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs After *string OnlyErrors *bool Since *time.Time @@ -178,16 +177,16 @@ func (r *WebhookLogConnectionResolver) TotalCount(ctx context.Context) (int32, e return int32(count), err } -func (r *WebhookLogConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *WebhookLogConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { _, next, err := r.compute(ctx) if err != nil { return nil, err } if next == 0 { - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } - return graphqlutil.NextPageCursor(fmt.Sprint(next)), nil + return gqlutil.NextPageCursor(fmt.Sprint(next)), nil } func (r *WebhookLogConnectionResolver) compute(ctx context.Context) ([]*types.WebhookLog, int64, error) { diff --git a/cmd/frontend/graphqlbackend/webhook_logs_test.go b/cmd/frontend/graphqlbackend/webhook_logs_test.go index e60a1cd953c..cdf0b2d9da7 100644 --- a/cmd/frontend/graphqlbackend/webhook_logs_test.go +++ b/cmd/frontend/graphqlbackend/webhook_logs_test.go @@ -10,9 +10,9 @@ import ( "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/database/dbmocks" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/lib/pointers" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/types" @@ -54,7 +54,7 @@ func TestWebhookLogsArgs(t *testing.T) { "all arguments": { id: webhookLogsExternalServiceID(1), input: WebhookLogsArgs{ - ConnectionArgs: graphqlutil.ConnectionArgs{ + ConnectionArgs: gqlutil.ConnectionArgs{ First: pointers.Ptr(int32(25)), }, After: pointers.Ptr("40"), @@ -156,7 +156,7 @@ func TestWebhookLogConnectionResolver(t *testing.T) { r := &WebhookLogConnectionResolver{ args: &WebhookLogsArgs{ - ConnectionArgs: graphqlutil.ConnectionArgs{ + ConnectionArgs: gqlutil.ConnectionArgs{ First: pointers.Ptr(int32(20)), }, }, @@ -189,7 +189,7 @@ func TestWebhookLogConnectionResolver(t *testing.T) { r := &WebhookLogConnectionResolver{ args: &WebhookLogsArgs{ - ConnectionArgs: graphqlutil.ConnectionArgs{ + ConnectionArgs: gqlutil.ConnectionArgs{ First: pointers.Ptr(int32(20)), }, }, @@ -225,7 +225,7 @@ func TestWebhookLogConnectionResolver(t *testing.T) { r := &WebhookLogConnectionResolver{ args: &WebhookLogsArgs{ - ConnectionArgs: graphqlutil.ConnectionArgs{ + ConnectionArgs: gqlutil.ConnectionArgs{ First: pointers.Ptr(int32(20)), }, }, diff --git a/cmd/frontend/graphqlbackend/webhooks.go b/cmd/frontend/graphqlbackend/webhooks.go index 22efe1dce00..018ec45f1b2 100644 --- a/cmd/frontend/graphqlbackend/webhooks.go +++ b/cmd/frontend/graphqlbackend/webhooks.go @@ -4,7 +4,7 @@ import ( "context" "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) @@ -22,7 +22,7 @@ type WebhooksResolver interface { type WebhookConnectionResolver interface { Nodes(ctx context.Context) ([]WebhookResolver, error) TotalCount(ctx context.Context) (int32, error) - PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) + PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) } // WebhookResolver is an interface for querying a single webhook. @@ -61,7 +61,7 @@ type UpdateWebhookArgs struct { } type ListWebhookArgs struct { - graphqlutil.ConnectionArgs + gqlutil.ConnectionArgs After *string Kind *string } diff --git a/cmd/frontend/internal/authz/resolvers/BUILD.bazel b/cmd/frontend/internal/authz/resolvers/BUILD.bazel index 1b7ab829581..156ab183ba9 100644 --- a/cmd/frontend/internal/authz/resolvers/BUILD.bazel +++ b/cmd/frontend/internal/authz/resolvers/BUILD.bazel @@ -15,7 +15,6 @@ go_library( visibility = ["//cmd/frontend:__subpackages__"], deps = [ "//cmd/frontend/graphqlbackend", - "//cmd/frontend/graphqlbackend/graphqlutil", "//internal/actor", "//internal/api", "//internal/auth", @@ -53,7 +52,6 @@ go_test( tags = [TAG_PLATFORM_SOURCE], deps = [ "//cmd/frontend/graphqlbackend", - "//cmd/frontend/graphqlbackend/graphqlutil", "//internal/actor", "//internal/api", "//internal/auth", @@ -65,6 +63,7 @@ go_test( "//internal/dotcom", "//internal/executor", "//internal/extsvc", + "//internal/gqlutil", "//internal/licensing", "//internal/observation", "//internal/timeutil", diff --git a/cmd/frontend/internal/authz/resolvers/permissions_info.go b/cmd/frontend/internal/authz/resolvers/permissions_info.go index 81ed51b6c46..aa75bbb0fc7 100644 --- a/cmd/frontend/internal/authz/resolvers/permissions_info.go +++ b/cmd/frontend/internal/authz/resolvers/permissions_info.go @@ -7,14 +7,12 @@ import ( "github.com/graph-gophers/graphql-go" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" - "github.com/sourcegraph/sourcegraph/internal/actor" - "github.com/sourcegraph/sourcegraph/internal/errcode" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" + "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/authz" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/errcode" "github.com/sourcegraph/sourcegraph/internal/gitserver" "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) @@ -59,13 +57,13 @@ func (r *permissionsInfoResolver) Unrestricted(_ context.Context) bool { var permissionsInfoRepositoryConnectionMaxPageSize = 100 -var permissionsInfoRepositoryConnectionOptions = &graphqlutil.ConnectionResolverOptions{ +var permissionsInfoRepositoryConnectionOptions = &gqlutil.ConnectionResolverOptions{ OrderBy: database.OrderBy{{Field: "repo.id"}}, Ascending: true, MaxPageSize: permissionsInfoRepositoryConnectionMaxPageSize, } -func (r *permissionsInfoResolver) Repositories(_ context.Context, args graphqlbackend.PermissionsInfoRepositoriesArgs) (*graphqlutil.ConnectionResolver[graphqlbackend.PermissionsInfoRepositoryResolver], error) { +func (r *permissionsInfoResolver) Repositories(_ context.Context, args graphqlbackend.PermissionsInfoRepositoriesArgs) (*gqlutil.ConnectionResolver[graphqlbackend.PermissionsInfoRepositoryResolver], error) { if r.userID == 0 { return nil, nil } @@ -81,7 +79,7 @@ func (r *permissionsInfoResolver) Repositories(_ context.Context, args graphqlba query: query, } - return graphqlutil.NewConnectionResolver[graphqlbackend.PermissionsInfoRepositoryResolver](connectionStore, &args.ConnectionResolverArgs, permissionsInfoRepositoryConnectionOptions) + return gqlutil.NewConnectionResolver[graphqlbackend.PermissionsInfoRepositoryResolver](connectionStore, &args.ConnectionResolverArgs, permissionsInfoRepositoryConnectionOptions) } type permissionsInfoRepositoriesStore struct { @@ -157,13 +155,13 @@ func (r permissionsInfoRepositoryResolver) UpdatedAt() *gqlutil.DateTime { var permissionsInfoUserConnectionMaxPageSize = 100 -var permissionsInfoUserConnectionOptions = &graphqlutil.ConnectionResolverOptions{ +var permissionsInfoUserConnectionOptions = &gqlutil.ConnectionResolverOptions{ OrderBy: database.OrderBy{{Field: "users.username"}}, Ascending: true, MaxPageSize: permissionsInfoUserConnectionMaxPageSize, } -func (r *permissionsInfoResolver) Users(ctx context.Context, args graphqlbackend.PermissionsInfoUsersArgs) (*graphqlutil.ConnectionResolver[graphqlbackend.PermissionsInfoUserResolver], error) { +func (r *permissionsInfoResolver) Users(ctx context.Context, args graphqlbackend.PermissionsInfoUsersArgs) (*gqlutil.ConnectionResolver[graphqlbackend.PermissionsInfoUserResolver], error) { if r.repoID == 0 { return nil, nil } @@ -180,7 +178,7 @@ func (r *permissionsInfoResolver) Users(ctx context.Context, args graphqlbackend query: query, } - return graphqlutil.NewConnectionResolver[graphqlbackend.PermissionsInfoUserResolver](connectionStore, &args.ConnectionResolverArgs, permissionsInfoUserConnectionOptions) + return gqlutil.NewConnectionResolver[graphqlbackend.PermissionsInfoUserResolver](connectionStore, &args.ConnectionResolverArgs, permissionsInfoUserConnectionOptions) } type permissionsInfoUsersStore struct { diff --git a/cmd/frontend/internal/authz/resolvers/permissions_sync_jobs.go b/cmd/frontend/internal/authz/resolvers/permissions_sync_jobs.go index 7f9d3e68562..59cc871be94 100644 --- a/cmd/frontend/internal/authz/resolvers/permissions_sync_jobs.go +++ b/cmd/frontend/internal/authz/resolvers/permissions_sync_jobs.go @@ -8,7 +8,6 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/errcode" @@ -21,7 +20,7 @@ import ( const permissionsSyncJobIDKind = "PermissionsSyncJob" -func NewPermissionsSyncJobsResolver(logger log.Logger, db database.DB, args graphqlbackend.ListPermissionsSyncJobsArgs) (*graphqlutil.ConnectionResolver[graphqlbackend.PermissionsSyncJobResolver], error) { +func NewPermissionsSyncJobsResolver(logger log.Logger, db database.DB, args graphqlbackend.ListPermissionsSyncJobsArgs) (*gqlutil.ConnectionResolver[graphqlbackend.PermissionsSyncJobResolver], error) { store := &permissionsSyncJobConnectionStore{ logger: logger.Scoped("permissions_sync_jobs_resolver"), db: db, @@ -32,7 +31,7 @@ func NewPermissionsSyncJobsResolver(logger log.Logger, db database.DB, args grap return nil, errors.New("please provide either userID or repoID, but not both.") } - return graphqlutil.NewConnectionResolver[graphqlbackend.PermissionsSyncJobResolver]( + return gqlutil.NewConnectionResolver[graphqlbackend.PermissionsSyncJobResolver]( store, &args.ConnectionResolverArgs, nil) } diff --git a/cmd/frontend/internal/authz/resolvers/permissions_sync_jobs_test.go b/cmd/frontend/internal/authz/resolvers/permissions_sync_jobs_test.go index b2c059d46e3..315d6fd2922 100644 --- a/cmd/frontend/internal/authz/resolvers/permissions_sync_jobs_test.go +++ b/cmd/frontend/internal/authz/resolvers/permissions_sync_jobs_test.go @@ -9,9 +9,9 @@ import ( "github.com/stretchr/testify/require" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/database/dbmocks" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -19,7 +19,7 @@ import ( func TestPermissionSyncJobsResolver(t *testing.T) { ctx := context.Background() first := int32(1337) - args := graphqlutil.ConnectionResolverArgs{First: &first} + args := gqlutil.ConnectionResolverArgs{First: &first} t.Run("No jobs found", func(t *testing.T) { db := dbmocks.NewMockDB() diff --git a/cmd/frontend/internal/authz/resolvers/repositories.go b/cmd/frontend/internal/authz/resolvers/repositories.go index b61947e8218..54755f808b7 100644 --- a/cmd/frontend/internal/authz/resolvers/repositories.go +++ b/cmd/frontend/internal/authz/resolvers/repositories.go @@ -7,11 +7,11 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gitserver" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" ) @@ -28,7 +28,7 @@ type repositoryConnectionResolver struct { // cache results because they are used by multiple fields once sync.Once repos []*types.Repo - pageInfo *graphqlutil.PageInfo + pageInfo *gqlutil.PageInfo err error } @@ -40,7 +40,7 @@ type repositoryConnectionResolver struct { // r.ids - the full slice of sorted repo IDs // r.after - (optional) the repo ID to start the paging after (does not include the after ID itself) // r.first - the # of repo IDs to return -func (r *repositoryConnectionResolver) compute(ctx context.Context) ([]*types.Repo, *graphqlutil.PageInfo, error) { +func (r *repositoryConnectionResolver) compute(ctx context.Context) ([]*types.Repo, *gqlutil.PageInfo, error) { r.once.Do(func() { var idSubset []int32 if r.after == nil { @@ -68,7 +68,7 @@ func (r *repositoryConnectionResolver) compute(ctx context.Context) ([]*types.Re // No IDs to find, return early if len(idSubset) == 0 { r.repos = []*types.Repo{} - r.pageInfo = graphqlutil.HasNextPage(false) + r.pageInfo = gqlutil.HasNextPage(false) return } // If we have more ids than we need, trim them @@ -90,10 +90,10 @@ func (r *repositoryConnectionResolver) compute(ctx context.Context) ([]*types.Re // The last id in this page is the last id in r.ids, no more pages if int32(repoIDs[len(repoIDs)-1]) == r.ids[len(r.ids)-1] { - r.pageInfo = graphqlutil.HasNextPage(false) + r.pageInfo = gqlutil.HasNextPage(false) } else { // Additional repo IDs to paginate through. endCursor := string(graphqlbackend.MarshalRepositoryID(repoIDs[len(repoIDs)-1])) - r.pageInfo = graphqlutil.NextPageCursor(endCursor) + r.pageInfo = gqlutil.NextPageCursor(endCursor) } }) return r.repos, r.pageInfo, r.err @@ -127,7 +127,7 @@ func (r *repositoryConnectionResolver) TotalCount(ctx context.Context, args *gra return &count, nil } -func (r *repositoryConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *repositoryConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { // 🚨 SECURITY: Only site admins may access this method. if err := auth.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil { return nil, err diff --git a/cmd/frontend/internal/authz/resolvers/resolver.go b/cmd/frontend/internal/authz/resolvers/resolver.go index 51334d98677..b06455e7848 100644 --- a/cmd/frontend/internal/authz/resolvers/resolver.go +++ b/cmd/frontend/internal/authz/resolvers/resolver.go @@ -11,7 +11,6 @@ import ( "golang.org/x/exp/maps" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/auth" @@ -23,6 +22,7 @@ import ( "github.com/sourcegraph/sourcegraph/internal/dotcom" "github.com/sourcegraph/sourcegraph/internal/errcode" "github.com/sourcegraph/sourcegraph/internal/extsvc" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/licensing" "github.com/sourcegraph/sourcegraph/internal/observation" "github.com/sourcegraph/sourcegraph/internal/types" @@ -635,7 +635,7 @@ func (r *Resolver) UserPermissionsInfo(ctx context.Context, id graphql.ID) (grap }, nil } -func (r *Resolver) PermissionsSyncJobs(ctx context.Context, args graphqlbackend.ListPermissionsSyncJobsArgs) (*graphqlutil.ConnectionResolver[graphqlbackend.PermissionsSyncJobResolver], error) { +func (r *Resolver) PermissionsSyncJobs(ctx context.Context, args graphqlbackend.ListPermissionsSyncJobsArgs) (*gqlutil.ConnectionResolver[graphqlbackend.PermissionsSyncJobResolver], error) { // 🚨 SECURITY: Only site admins can query sync jobs records or the users themselves. if args.UserID != nil { userID, err := graphqlbackend.UnmarshalUserID(*args.UserID) diff --git a/cmd/frontend/internal/authz/resolvers/users.go b/cmd/frontend/internal/authz/resolvers/users.go index 55eda0c9825..c6dd6516bba 100644 --- a/cmd/frontend/internal/authz/resolvers/users.go +++ b/cmd/frontend/internal/authz/resolvers/users.go @@ -7,9 +7,9 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" ) @@ -26,7 +26,7 @@ type userConnectionResolver struct { // cache results because they are used by multiple fields once sync.Once users []*types.User - pageInfo *graphqlutil.PageInfo + pageInfo *gqlutil.PageInfo err error } @@ -38,7 +38,7 @@ type userConnectionResolver struct { // r.ids - the full slice of sorted user IDs // r.after - (optional) the user ID to start the paging after (does not include the after ID itself) // r.first - the # of user IDs to return -func (r *userConnectionResolver) compute(ctx context.Context) ([]*types.User, *graphqlutil.PageInfo, error) { +func (r *userConnectionResolver) compute(ctx context.Context) ([]*types.User, *gqlutil.PageInfo, error) { r.once.Do(func() { var idSubset []int32 if r.after == nil { @@ -66,7 +66,7 @@ func (r *userConnectionResolver) compute(ctx context.Context) ([]*types.User, *g if len(idSubset) == 0 { r.users = []*types.User{} - r.pageInfo = graphqlutil.HasNextPage(false) + r.pageInfo = gqlutil.HasNextPage(false) return } @@ -84,10 +84,10 @@ func (r *userConnectionResolver) compute(ctx context.Context) ([]*types.User, *g // No more user IDs to paginate through. if idSubset[len(idSubset)-1] == r.ids[len(r.ids)-1] { - r.pageInfo = graphqlutil.HasNextPage(false) + r.pageInfo = gqlutil.HasNextPage(false) } else { // Additional user IDs to paginate through. endCursor := string(graphqlbackend.MarshalUserID(idSubset[len(idSubset)-1])) - r.pageInfo = graphqlutil.NextPageCursor(endCursor) + r.pageInfo = gqlutil.NextPageCursor(endCursor) } }) return r.users, r.pageInfo, r.err @@ -119,7 +119,7 @@ func (r *userConnectionResolver) TotalCount(ctx context.Context) (int32, error) return int32(len(r.ids)), nil } -func (r *userConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *userConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { // 🚨 SECURITY: Only site admins may access this method. if err := auth.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil { return nil, err diff --git a/cmd/frontend/internal/batches/resolvers/BUILD.bazel b/cmd/frontend/internal/batches/resolvers/BUILD.bazel index 7ab287c7adc..23d14fda0ea 100644 --- a/cmd/frontend/internal/batches/resolvers/BUILD.bazel +++ b/cmd/frontend/internal/batches/resolvers/BUILD.bazel @@ -42,7 +42,6 @@ go_library( "//cmd/frontend/enterprise", "//cmd/frontend/graphqlbackend", "//cmd/frontend/graphqlbackend/externallink", - "//cmd/frontend/graphqlbackend/graphqlutil", "//cmd/frontend/internal/githubapp", "//internal/actor", "//internal/api", diff --git a/cmd/frontend/internal/batches/resolvers/batch_change_connection.go b/cmd/frontend/internal/batches/resolvers/batch_change_connection.go index 5b7588c95f9..eae95c0e36f 100644 --- a/cmd/frontend/internal/batches/resolvers/batch_change_connection.go +++ b/cmd/frontend/internal/batches/resolvers/batch_change_connection.go @@ -8,10 +8,10 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/batches/store" btypes "github.com/sourcegraph/sourcegraph/internal/batches/types" "github.com/sourcegraph/sourcegraph/internal/gitserver" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) var _ graphqlbackend.BatchChangesConnectionResolver = &batchChangesConnectionResolver{} @@ -55,15 +55,15 @@ func (r *batchChangesConnectionResolver) TotalCount(ctx context.Context) (int32, return int32(count), err } -func (r *batchChangesConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *batchChangesConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { _, next, err := r.compute(ctx) if err != nil { return nil, err } if next != 0 { - return graphqlutil.NextPageCursor(strconv.Itoa(int(next))), nil + return gqlutil.NextPageCursor(strconv.Itoa(int(next))), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } func (r *batchChangesConnectionResolver) compute(ctx context.Context) ([]*btypes.BatchChange, int64, error) { diff --git a/cmd/frontend/internal/batches/resolvers/batch_spec_connection.go b/cmd/frontend/internal/batches/resolvers/batch_spec_connection.go index 201846aeb43..7dabf0b87f4 100644 --- a/cmd/frontend/internal/batches/resolvers/batch_spec_connection.go +++ b/cmd/frontend/internal/batches/resolvers/batch_spec_connection.go @@ -8,9 +8,9 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/batches/store" btypes "github.com/sourcegraph/sourcegraph/internal/batches/types" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) type batchSpecConnectionResolver struct { @@ -49,15 +49,15 @@ func (r *batchSpecConnectionResolver) TotalCount(ctx context.Context) (int32, er return int32(count), err } -func (r *batchSpecConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *batchSpecConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { _, next, err := r.compute(ctx) if err != nil { return nil, err } if next != 0 { - return graphqlutil.NextPageCursor(strconv.Itoa(int(next))), nil + return gqlutil.NextPageCursor(strconv.Itoa(int(next))), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } func (r *batchSpecConnectionResolver) compute(ctx context.Context) ([]*btypes.BatchSpec, int64, error) { diff --git a/cmd/frontend/internal/batches/resolvers/batch_spec_workspace_connection.go b/cmd/frontend/internal/batches/resolvers/batch_spec_workspace_connection.go index c7a00fd2647..a30a956617a 100644 --- a/cmd/frontend/internal/batches/resolvers/batch_spec_workspace_connection.go +++ b/cmd/frontend/internal/batches/resolvers/batch_spec_workspace_connection.go @@ -8,10 +8,10 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/batches/store" btypes "github.com/sourcegraph/sourcegraph/internal/batches/types" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -80,15 +80,15 @@ func (r *batchSpecWorkspaceConnectionResolver) TotalCount(ctx context.Context) ( return int32(count), err } -func (r *batchSpecWorkspaceConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *batchSpecWorkspaceConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { _, next, err := r.compute(ctx) if err != nil { return nil, err } if next != 0 { - return graphqlutil.NextPageCursor(strconv.Itoa(int(next))), nil + return gqlutil.NextPageCursor(strconv.Itoa(int(next))), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } func (r *batchSpecWorkspaceConnectionResolver) compute(ctx context.Context) ([]*btypes.BatchSpecWorkspace, int64, error) { diff --git a/cmd/frontend/internal/batches/resolvers/batch_spec_workspace_file_connection.go b/cmd/frontend/internal/batches/resolvers/batch_spec_workspace_file_connection.go index 7bf070877ce..1a508ee0d9d 100644 --- a/cmd/frontend/internal/batches/resolvers/batch_spec_workspace_file_connection.go +++ b/cmd/frontend/internal/batches/resolvers/batch_spec_workspace_file_connection.go @@ -6,9 +6,9 @@ import ( "sync" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/batches/store" btypes "github.com/sourcegraph/sourcegraph/internal/batches/types" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) var _ graphqlbackend.BatchSpecWorkspaceFileConnectionResolver = &batchSpecWorkspaceFileConnectionResolver{} @@ -29,15 +29,15 @@ func (r *batchSpecWorkspaceFileConnectionResolver) TotalCount(ctx context.Contex return int32(count), err } -func (r *batchSpecWorkspaceFileConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *batchSpecWorkspaceFileConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { _, next, err := r.compute(ctx) if err != nil { return nil, err } if next != 0 { - return graphqlutil.NextPageCursor(strconv.Itoa(int(next))), nil + return gqlutil.NextPageCursor(strconv.Itoa(int(next))), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } func (r *batchSpecWorkspaceFileConnectionResolver) Nodes(ctx context.Context) ([]graphqlbackend.BatchWorkspaceFileResolver, error) { diff --git a/cmd/frontend/internal/batches/resolvers/batch_spec_workspace_step.go b/cmd/frontend/internal/batches/resolvers/batch_spec_workspace_step.go index ddacf4c32c1..3d9e5fe4d4b 100644 --- a/cmd/frontend/internal/batches/resolvers/batch_spec_workspace_step.go +++ b/cmd/frontend/internal/batches/resolvers/batch_spec_workspace_step.go @@ -8,7 +8,6 @@ import ( "time" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/batches/store" btypes "github.com/sourcegraph/sourcegraph/internal/batches/types" "github.com/sourcegraph/sourcegraph/internal/executor" @@ -440,12 +439,12 @@ func (r *batchSpecWorkspaceOutputLinesResolver) TotalCount() (int32, error) { return totalCount, r.err } -func (r *batchSpecWorkspaceOutputLinesResolver) PageInfo() (*graphqlutil.PageInfo, error) { +func (r *batchSpecWorkspaceOutputLinesResolver) PageInfo() (*gqlutil.PageInfo, error) { _, _, hasNextPage := r.compute() if hasNextPage { - return graphqlutil.NextPageCursor(strconv.Itoa(int(r.endCursor))), r.err + return gqlutil.NextPageCursor(strconv.Itoa(int(r.endCursor))), r.err } - return graphqlutil.HasNextPage(hasNextPage), r.err + return gqlutil.HasNextPage(hasNextPage), r.err } func (r *batchSpecWorkspaceOutputLinesResolver) Nodes() ([]string, error) { diff --git a/cmd/frontend/internal/batches/resolvers/bulk_operation_connection.go b/cmd/frontend/internal/batches/resolvers/bulk_operation_connection.go index 776c12c7f90..bc32a3cb332 100644 --- a/cmd/frontend/internal/batches/resolvers/bulk_operation_connection.go +++ b/cmd/frontend/internal/batches/resolvers/bulk_operation_connection.go @@ -8,10 +8,10 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/batches/store" btypes "github.com/sourcegraph/sourcegraph/internal/batches/types" "github.com/sourcegraph/sourcegraph/internal/gitserver" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) type bulkOperationConnectionResolver struct { @@ -41,17 +41,17 @@ func (r *bulkOperationConnectionResolver) TotalCount(ctx context.Context) (int32 return int32(count), nil } -func (r *bulkOperationConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *bulkOperationConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { _, next, err := r.compute(ctx) if err != nil { return nil, err } if next != 0 { - return graphqlutil.NextPageCursor(strconv.Itoa(int(next))), nil + return gqlutil.NextPageCursor(strconv.Itoa(int(next))), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } func (r *bulkOperationConnectionResolver) Nodes(ctx context.Context) ([]graphqlbackend.BulkOperationResolver, error) { diff --git a/cmd/frontend/internal/batches/resolvers/changeset_apply_preview_connection.go b/cmd/frontend/internal/batches/resolvers/changeset_apply_preview_connection.go index 374f9c40a0f..d600c23f6f0 100644 --- a/cmd/frontend/internal/batches/resolvers/changeset_apply_preview_connection.go +++ b/cmd/frontend/internal/batches/resolvers/changeset_apply_preview_connection.go @@ -9,13 +9,13 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/batches/service" "github.com/sourcegraph/sourcegraph/internal/batches/store" "github.com/sourcegraph/sourcegraph/internal/batches/syncer" btypes "github.com/sourcegraph/sourcegraph/internal/batches/types" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gitserver" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/lib/batches" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -54,18 +54,18 @@ func (r *changesetApplyPreviewConnectionResolver) TotalCount(ctx context.Context return int32(page.TotalCount), nil } -func (r *changesetApplyPreviewConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *changesetApplyPreviewConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { if r.opts.LimitOffset == nil { - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } mappings, err := r.compute(ctx) if err != nil { return nil, err } if (r.opts.LimitOffset.Limit + r.opts.LimitOffset.Offset) >= len(mappings.All) { - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } - return graphqlutil.NextPageCursor(strconv.Itoa(r.opts.LimitOffset.Limit + r.opts.LimitOffset.Offset)), nil + return gqlutil.NextPageCursor(strconv.Itoa(r.opts.LimitOffset.Limit + r.opts.LimitOffset.Offset)), nil } func (r *changesetApplyPreviewConnectionResolver) Nodes(ctx context.Context) ([]graphqlbackend.ChangesetApplyPreviewResolver, error) { diff --git a/cmd/frontend/internal/batches/resolvers/changeset_connection.go b/cmd/frontend/internal/batches/resolvers/changeset_connection.go index 87feeb4c62f..67c05b92411 100644 --- a/cmd/frontend/internal/batches/resolvers/changeset_connection.go +++ b/cmd/frontend/internal/batches/resolvers/changeset_connection.go @@ -9,11 +9,11 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/batches/store" "github.com/sourcegraph/sourcegraph/internal/batches/syncer" btypes "github.com/sourcegraph/sourcegraph/internal/batches/types" "github.com/sourcegraph/sourcegraph/internal/gitserver" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) type changesetsConnectionResolver struct { @@ -100,15 +100,15 @@ func (r *changesetsConnectionResolver) compute(ctx context.Context) (cs btypes.C return r.changesets, r.next, r.err } -func (r *changesetsConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *changesetsConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { _, next, err := r.compute(ctx) if err != nil { return nil, err } if next > 0 { - return graphqlutil.NextPageCursor(strconv.Itoa(int(next))), nil + return gqlutil.NextPageCursor(strconv.Itoa(int(next))), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } diff --git a/cmd/frontend/internal/batches/resolvers/changeset_event_connection.go b/cmd/frontend/internal/batches/resolvers/changeset_event_connection.go index 13035c81821..e942d7387cc 100644 --- a/cmd/frontend/internal/batches/resolvers/changeset_event_connection.go +++ b/cmd/frontend/internal/batches/resolvers/changeset_event_connection.go @@ -6,9 +6,9 @@ import ( "sync" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/batches/store" btypes "github.com/sourcegraph/sourcegraph/internal/batches/types" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) type changesetEventsConnectionResolver struct { @@ -46,15 +46,15 @@ func (r *changesetEventsConnectionResolver) TotalCount(ctx context.Context) (int return int32(count), err } -func (r *changesetEventsConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *changesetEventsConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { _, next, err := r.compute(ctx) if err != nil { return nil, err } if next != 0 { - return graphqlutil.NextPageCursor(strconv.Itoa(int(next))), nil + return gqlutil.NextPageCursor(strconv.Itoa(int(next))), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } func (r *changesetEventsConnectionResolver) compute(ctx context.Context) ([]*btypes.ChangesetEvent, int64, error) { diff --git a/cmd/frontend/internal/batches/resolvers/changeset_spec_connection.go b/cmd/frontend/internal/batches/resolvers/changeset_spec_connection.go index 3c0048f0b20..ac0ff7115b0 100644 --- a/cmd/frontend/internal/batches/resolvers/changeset_spec_connection.go +++ b/cmd/frontend/internal/batches/resolvers/changeset_spec_connection.go @@ -6,10 +6,10 @@ import ( "sync" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/batches/store" btypes "github.com/sourcegraph/sourcegraph/internal/batches/types" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" ) @@ -39,7 +39,7 @@ func (r *changesetSpecConnectionResolver) TotalCount(ctx context.Context) (int32 return int32(count), nil } -func (r *changesetSpecConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *changesetSpecConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { _, _, next, err := r.compute(ctx) if err != nil { return nil, err @@ -48,10 +48,10 @@ func (r *changesetSpecConnectionResolver) PageInfo(ctx context.Context) (*graphq if next != 0 { // We don't use the RandID for pagination, because we can't paginate database // entries based on the RandID. - return graphqlutil.NextPageCursor(strconv.Itoa(int(next))), nil + return gqlutil.NextPageCursor(strconv.Itoa(int(next))), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } func (r *changesetSpecConnectionResolver) Nodes(ctx context.Context) ([]graphqlbackend.ChangesetSpecResolver, error) { diff --git a/cmd/frontend/internal/batches/resolvers/code_host_connection.go b/cmd/frontend/internal/batches/resolvers/code_host_connection.go index 1784926de41..7621841e38f 100644 --- a/cmd/frontend/internal/batches/resolvers/code_host_connection.go +++ b/cmd/frontend/internal/batches/resolvers/code_host_connection.go @@ -8,10 +8,10 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/batches/store" btypes "github.com/sourcegraph/sourcegraph/internal/batches/types" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) type batchChangesCodeHostConnectionResolver struct { @@ -40,7 +40,7 @@ func (c *batchChangesCodeHostConnectionResolver) TotalCount(ctx context.Context) return int32(len(chs)), err } -func (c *batchChangesCodeHostConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (c *batchChangesCodeHostConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { chs, _, _, err := c.compute(ctx) if err != nil { return nil, err @@ -48,10 +48,10 @@ func (c *batchChangesCodeHostConnectionResolver) PageInfo(ctx context.Context) ( idx := c.limitOffset.Limit + c.limitOffset.Offset if idx < len(chs) { - return graphqlutil.NextPageCursor(strconv.Itoa(idx)), nil + return gqlutil.NextPageCursor(strconv.Itoa(idx)), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } func (c *batchChangesCodeHostConnectionResolver) Nodes(ctx context.Context) ([]graphqlbackend.BatchChangesCodeHostResolver, error) { @@ -169,8 +169,8 @@ func (c *emptyBatchChangesCodeHostConnectionResolver) TotalCount(ctx context.Con return 0, nil } -func (c *emptyBatchChangesCodeHostConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { - return graphqlutil.HasNextPage(false), nil +func (c *emptyBatchChangesCodeHostConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { + return gqlutil.HasNextPage(false), nil } func (c *emptyBatchChangesCodeHostConnectionResolver) Nodes(ctx context.Context) ([]graphqlbackend.BatchChangesCodeHostResolver, error) { diff --git a/cmd/frontend/internal/batches/resolvers/resolver.go b/cmd/frontend/internal/batches/resolvers/resolver.go index 4c4e2efe0b3..5b1c0cd9a84 100644 --- a/cmd/frontend/internal/batches/resolvers/resolver.go +++ b/cmd/frontend/internal/batches/resolvers/resolver.go @@ -7,8 +7,6 @@ import ( "strconv" "strings" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" - "github.com/graph-gophers/graphql-go" "go.opentelemetry.io/otel/attribute" @@ -32,6 +30,7 @@ import ( "github.com/sourcegraph/sourcegraph/internal/featureflag" ghstore "github.com/sourcegraph/sourcegraph/internal/github_apps/store" "github.com/sourcegraph/sourcegraph/internal/gitserver" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/licensing" "github.com/sourcegraph/sourcegraph/internal/rbac" "github.com/sourcegraph/sourcegraph/internal/trace" @@ -2005,7 +2004,7 @@ func (r *Resolver) MaxUnlicensedChangesets(ctx context.Context) int32 { } } -func (r *Resolver) GetChangesetsByIDs(ctx context.Context, args *graphqlbackend.GetChangesetsByIDsArgs) (_ graphqlutil.SliceConnectionResolver[graphqlbackend.ChangesetResolver], err error) { +func (r *Resolver) GetChangesetsByIDs(ctx context.Context, args *graphqlbackend.GetChangesetsByIDsArgs) (_ gqlutil.SliceConnectionResolver[graphqlbackend.ChangesetResolver], err error) { tr, ctx := trace.New(ctx, "Resolver.GetChangesetsByIDs", attribute.String("batchChange", string(args.BatchChange)), attribute.Int("changesets.len", len(args.Changesets))) @@ -2048,7 +2047,7 @@ func (r *Resolver) GetChangesetsByIDs(ctx context.Context, args *graphqlbackend. cs[i] = NewChangesetResolver(r.store, r.gitserverClient, r.logger, changeset, repo) } - return graphqlutil.NewSliceConnectionResolver(cs, len(cs), len(cs)), nil + return gqlutil.NewSliceConnectionResolver(cs, len(cs), len(cs)), nil } func parseBatchChangeStates(ss *[]string) ([]btypes.BatchChangeState, error) { diff --git a/cmd/frontend/internal/codemonitors/resolvers/BUILD.bazel b/cmd/frontend/internal/codemonitors/resolvers/BUILD.bazel index d3435118918..79d7ae5b788 100644 --- a/cmd/frontend/internal/codemonitors/resolvers/BUILD.bazel +++ b/cmd/frontend/internal/codemonitors/resolvers/BUILD.bazel @@ -9,7 +9,6 @@ go_library( visibility = ["//cmd/frontend:__subpackages__"], deps = [ "//cmd/frontend/graphqlbackend", - "//cmd/frontend/graphqlbackend/graphqlutil", "//internal/auth", "//internal/codemonitors", "//internal/codemonitors/background", diff --git a/cmd/frontend/internal/codemonitors/resolvers/resolvers.go b/cmd/frontend/internal/codemonitors/resolvers/resolvers.go index c768a550eec..a895e81ba08 100644 --- a/cmd/frontend/internal/codemonitors/resolvers/resolvers.go +++ b/cmd/frontend/internal/codemonitors/resolvers/resolvers.go @@ -11,7 +11,6 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/codemonitors" "github.com/sourcegraph/sourcegraph/internal/codemonitors/background" @@ -733,11 +732,11 @@ func (m *monitorConnection) TotalCount() int32 { return m.totalCount } -func (m *monitorConnection) PageInfo() *graphqlutil.PageInfo { +func (m *monitorConnection) PageInfo() *gqlutil.PageInfo { if len(m.monitors) == 0 || !m.hasNextPage { - return graphqlutil.HasNextPage(false) + return gqlutil.HasNextPage(false) } - return graphqlutil.NextPageCursor(string(m.monitors[len(m.monitors)-1].ID())) + return gqlutil.NextPageCursor(string(m.monitors[len(m.monitors)-1].ID())) } const ( @@ -954,11 +953,11 @@ func (a *monitorTriggerEventConnection) TotalCount() int32 { return a.totalCount } -func (a *monitorTriggerEventConnection) PageInfo() *graphqlutil.PageInfo { +func (a *monitorTriggerEventConnection) PageInfo() *gqlutil.PageInfo { if len(a.events) == 0 { - return graphqlutil.HasNextPage(false) + return gqlutil.HasNextPage(false) } - return graphqlutil.NextPageCursor(string(a.events[len(a.events)-1].ID())) + return gqlutil.NextPageCursor(string(a.events[len(a.events)-1].ID())) } // MonitorTriggerEvent @@ -1039,13 +1038,13 @@ func (a *monitorActionConnection) TotalCount() int32 { return a.totalCount } -func (a *monitorActionConnection) PageInfo() *graphqlutil.PageInfo { +func (a *monitorActionConnection) PageInfo() *gqlutil.PageInfo { if len(a.actions) == 0 { - return graphqlutil.HasNextPage(false) + return gqlutil.HasNextPage(false) } last := a.actions[len(a.actions)-1] if email, ok := last.ToMonitorEmail(); ok { - return graphqlutil.NextPageCursor(string(email.ID())) + return gqlutil.NextPageCursor(string(email.ID())) } panic("found non-email monitor action") } @@ -1320,11 +1319,11 @@ func (a *monitorActionEmailRecipientsConnection) TotalCount() int32 { return a.totalCount } -func (a *monitorActionEmailRecipientsConnection) PageInfo() *graphqlutil.PageInfo { +func (a *monitorActionEmailRecipientsConnection) PageInfo() *gqlutil.PageInfo { if len(a.recipients) == 0 { - return graphqlutil.HasNextPage(false) + return gqlutil.HasNextPage(false) } - return graphqlutil.NextPageCursor(a.nextPageCursor) + return gqlutil.NextPageCursor(a.nextPageCursor) } // MonitorActionEventConnection @@ -1341,11 +1340,11 @@ func (a *monitorActionEventConnection) TotalCount() int32 { return a.totalCount } -func (a *monitorActionEventConnection) PageInfo() *graphqlutil.PageInfo { +func (a *monitorActionEventConnection) PageInfo() *gqlutil.PageInfo { if len(a.events) == 0 { - return graphqlutil.HasNextPage(false) + return gqlutil.HasNextPage(false) } - return graphqlutil.NextPageCursor(string(a.events[len(a.events)-1].ID())) + return gqlutil.NextPageCursor(string(a.events[len(a.events)-1].ID())) } // MonitorEvent diff --git a/cmd/frontend/internal/dotcom/productsubscription/BUILD.bazel b/cmd/frontend/internal/dotcom/productsubscription/BUILD.bazel index 214d94d0b84..c1636ae38f0 100644 --- a/cmd/frontend/internal/dotcom/productsubscription/BUILD.bazel +++ b/cmd/frontend/internal/dotcom/productsubscription/BUILD.bazel @@ -28,7 +28,6 @@ go_library( visibility = ["//cmd/frontend:__subpackages__"], deps = [ "//cmd/frontend/graphqlbackend", - "//cmd/frontend/graphqlbackend/graphqlutil", "//cmd/frontend/internal/cody", "//internal/accesstoken", "//internal/actor", diff --git a/cmd/frontend/internal/dotcom/productsubscription/licenses_graphql.go b/cmd/frontend/internal/dotcom/productsubscription/licenses_graphql.go index b488b579412..3d9c1439782 100644 --- a/cmd/frontend/internal/dotcom/productsubscription/licenses_graphql.go +++ b/cmd/frontend/internal/dotcom/productsubscription/licenses_graphql.go @@ -11,7 +11,6 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/conf" "github.com/sourcegraph/sourcegraph/internal/database" @@ -261,10 +260,10 @@ func (r *productLicenseConnection) TotalCount(ctx context.Context) (int32, error return int32(count), err } -func (r *productLicenseConnection) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *productLicenseConnection) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { results, err := r.compute(ctx) if err != nil { return nil, err } - return graphqlutil.HasNextPage(r.opt.LimitOffset != nil && len(results) > r.opt.Limit), nil + return gqlutil.HasNextPage(r.opt.LimitOffset != nil && len(results) > r.opt.Limit), nil } diff --git a/cmd/frontend/internal/dotcom/productsubscription/subscriptions_graphql.go b/cmd/frontend/internal/dotcom/productsubscription/subscriptions_graphql.go index fe52e348430..4991a184558 100644 --- a/cmd/frontend/internal/dotcom/productsubscription/subscriptions_graphql.go +++ b/cmd/frontend/internal/dotcom/productsubscription/subscriptions_graphql.go @@ -14,7 +14,6 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/audit" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" @@ -151,7 +150,7 @@ func (r *productSubscription) computeActiveLicense(ctx context.Context) (*dbLice return r.activeLicense, r.activeLicenseErr } -func (r *productSubscription) ProductLicenses(ctx context.Context, args *graphqlutil.ConnectionArgs) (graphqlbackend.ProductLicenseConnection, error) { +func (r *productSubscription) ProductLicenses(ctx context.Context, args *gqlutil.ConnectionArgs) (graphqlbackend.ProductLicenseConnection, error) { // 🚨 SECURITY: Only site admins may list historical product licenses (to reduce confusion // around old license reuse). Other viewers should use ProductSubscription.activeLicense. if err := auth.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil { @@ -409,10 +408,10 @@ func (r *productSubscriptionConnection) TotalCount(ctx context.Context) (int32, return int32(count), err } -func (r *productSubscriptionConnection) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *productSubscriptionConnection) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { results, err := r.compute(ctx) if err != nil { return nil, err } - return graphqlutil.HasNextPage(r.opt.LimitOffset != nil && len(results) > r.opt.Limit), nil + return gqlutil.HasNextPage(r.opt.LimitOffset != nil && len(results) > r.opt.Limit), nil } diff --git a/cmd/frontend/internal/embeddings/resolvers/BUILD.bazel b/cmd/frontend/internal/embeddings/resolvers/BUILD.bazel index bab0fd66d49..726f2f14c97 100644 --- a/cmd/frontend/internal/embeddings/resolvers/BUILD.bazel +++ b/cmd/frontend/internal/embeddings/resolvers/BUILD.bazel @@ -12,7 +12,6 @@ go_library( visibility = ["//cmd/frontend:__subpackages__"], deps = [ "//cmd/frontend/graphqlbackend", - "//cmd/frontend/graphqlbackend/graphqlutil", "//cmd/frontend/internal/cody", "//internal/api", "//internal/auth", diff --git a/cmd/frontend/internal/embeddings/resolvers/repo_embedding_jobs.go b/cmd/frontend/internal/embeddings/resolvers/repo_embedding_jobs.go index a8136c5ca00..73990dc4ee9 100644 --- a/cmd/frontend/internal/embeddings/resolvers/repo_embedding_jobs.go +++ b/cmd/frontend/internal/embeddings/resolvers/repo_embedding_jobs.go @@ -9,7 +9,6 @@ import ( "github.com/graph-gophers/graphql-go/relay" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/database" repobg "github.com/sourcegraph/sourcegraph/internal/embeddings/background/repo" @@ -24,19 +23,19 @@ func NewRepoEmbeddingJobsResolver( gitserverClient gitserver.Client, repoEmbeddingJobsStore repobg.RepoEmbeddingJobsStore, args graphqlbackend.ListRepoEmbeddingJobsArgs, -) (*graphqlutil.ConnectionResolver[graphqlbackend.RepoEmbeddingJobResolver], error) { +) (*gqlutil.ConnectionResolver[graphqlbackend.RepoEmbeddingJobResolver], error) { store := &repoEmbeddingJobsConnectionStore{ db: db, gitserverClient: gitserverClient, store: repoEmbeddingJobsStore, args: args, } - opts := &graphqlutil.ConnectionResolverOptions{ + opts := &gqlutil.ConnectionResolverOptions{ OrderBy: database.OrderBy{ {Field: "repo_embedding_jobs.id"}, }, } - return graphqlutil.NewConnectionResolver[graphqlbackend.RepoEmbeddingJobResolver](store, &args.ConnectionResolverArgs, opts) + return gqlutil.NewConnectionResolver[graphqlbackend.RepoEmbeddingJobResolver](store, &args.ConnectionResolverArgs, opts) } type repoEmbeddingJobsConnectionStore struct { diff --git a/cmd/frontend/internal/embeddings/resolvers/repo_embedding_jobs_test.go b/cmd/frontend/internal/embeddings/resolvers/repo_embedding_jobs_test.go index 101d7b1fbd9..61abdc2708b 100644 --- a/cmd/frontend/internal/embeddings/resolvers/repo_embedding_jobs_test.go +++ b/cmd/frontend/internal/embeddings/resolvers/repo_embedding_jobs_test.go @@ -19,7 +19,7 @@ import ( ) // TestDBPaginationWithRepoFilter exercises a bug filed in #58313 where -// a unscoped default ordering column from graphqlutil.ConnectionResolver ("id") +// a unscoped default ordering column from gqlutil.ConnectionResolver ("id") // makes into a query joining two tables (both having an id column), // causing ambiguous SQL. func TestDBPaginationWithRepoFilter(t *testing.T) { diff --git a/cmd/frontend/internal/embeddings/resolvers/resolvers.go b/cmd/frontend/internal/embeddings/resolvers/resolvers.go index 2b5afa9e875..4d8d6d52629 100644 --- a/cmd/frontend/internal/embeddings/resolvers/resolvers.go +++ b/cmd/frontend/internal/embeddings/resolvers/resolvers.go @@ -13,7 +13,6 @@ import ( "github.com/sourcegraph/sourcegraph/lib/errors" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cody" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/auth" @@ -22,6 +21,7 @@ import ( "github.com/sourcegraph/sourcegraph/internal/embeddings" repobg "github.com/sourcegraph/sourcegraph/internal/embeddings/background/repo" "github.com/sourcegraph/sourcegraph/internal/gitserver" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" ) func NewResolver( @@ -119,7 +119,7 @@ func (r *Resolver) IsContextRequiredForChatQuery(ctx context.Context, args graph return embeddings.IsContextRequiredForChatQuery(args.Query), nil } -func (r *Resolver) RepoEmbeddingJobs(ctx context.Context, args graphqlbackend.ListRepoEmbeddingJobsArgs) (*graphqlutil.ConnectionResolver[graphqlbackend.RepoEmbeddingJobResolver], error) { +func (r *Resolver) RepoEmbeddingJobs(ctx context.Context, args graphqlbackend.ListRepoEmbeddingJobsArgs) (*gqlutil.ConnectionResolver[graphqlbackend.RepoEmbeddingJobResolver], error) { if !conf.EmbeddingsEnabled() { return nil, errors.New("embeddings are not configured or disabled") } diff --git a/cmd/frontend/internal/guardrails/resolvers/BUILD.bazel b/cmd/frontend/internal/guardrails/resolvers/BUILD.bazel index 5218611405b..40a7b9ef7f4 100644 --- a/cmd/frontend/internal/guardrails/resolvers/BUILD.bazel +++ b/cmd/frontend/internal/guardrails/resolvers/BUILD.bazel @@ -9,8 +9,8 @@ go_library( visibility = ["//cmd/frontend:__subpackages__"], deps = [ "//cmd/frontend/graphqlbackend", - "//cmd/frontend/graphqlbackend/graphqlutil", "//cmd/frontend/internal/guardrails/attribution", + "//internal/gqlutil", "//internal/guardrails", ], ) diff --git a/cmd/frontend/internal/guardrails/resolvers/resolver.go b/cmd/frontend/internal/guardrails/resolvers/resolver.go index 1104962974f..d638dd417ea 100644 --- a/cmd/frontend/internal/guardrails/resolvers/resolver.go +++ b/cmd/frontend/internal/guardrails/resolvers/resolver.go @@ -5,8 +5,8 @@ import ( "sync" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/guardrails/attribution" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/guardrails" ) @@ -71,8 +71,8 @@ func (c snippetAttributionConnectionResolver) LimitHit() bool { } return c.result.LimitHit } -func (c snippetAttributionConnectionResolver) PageInfo() *graphqlutil.PageInfo { - return graphqlutil.HasNextPage(false) +func (c snippetAttributionConnectionResolver) PageInfo() *gqlutil.PageInfo { + return gqlutil.HasNextPage(false) } func (c snippetAttributionConnectionResolver) SnippetThreshold() graphqlbackend.AttributionSnippetThresholdResolver { return &attributionSnippetThresholdResolver{ diff --git a/cmd/frontend/internal/insights/resolvers/BUILD.bazel b/cmd/frontend/internal/insights/resolvers/BUILD.bazel index 5e81214515f..a43e98aabe0 100644 --- a/cmd/frontend/internal/insights/resolvers/BUILD.bazel +++ b/cmd/frontend/internal/insights/resolvers/BUILD.bazel @@ -21,7 +21,6 @@ go_library( visibility = ["//cmd/frontend:__subpackages__"], deps = [ "//cmd/frontend/graphqlbackend", - "//cmd/frontend/graphqlbackend/graphqlutil", "//internal/actor", "//internal/api", "//internal/auth", diff --git a/cmd/frontend/internal/insights/resolvers/admin_resolver.go b/cmd/frontend/internal/insights/resolvers/admin_resolver.go index 2dcacf81669..eda2a1912d3 100644 --- a/cmd/frontend/internal/insights/resolvers/admin_resolver.go +++ b/cmd/frontend/internal/insights/resolvers/admin_resolver.go @@ -14,7 +14,6 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" @@ -394,7 +393,7 @@ func (r *insightViewDebugResolver) Raw(ctx context.Context) ([]string, error) { return viewDebug, nil } -func (r *Resolver) InsightAdminBackfillQueue(ctx context.Context, args *graphqlbackend.AdminBackfillQueueArgs) (*graphqlutil.ConnectionResolver[*graphqlbackend.BackfillQueueItemResolver], error) { +func (r *Resolver) InsightAdminBackfillQueue(ctx context.Context, args *graphqlbackend.AdminBackfillQueueArgs) (*gqlutil.ConnectionResolver[*graphqlbackend.BackfillQueueItemResolver], error) { // 🚨 SECURITY // only admin users can access this resolver actr := actor.FromContext(ctx) @@ -414,10 +413,10 @@ func (r *Resolver) InsightAdminBackfillQueue(ctx context.Context, args *graphqlb orderBy = args.OrderBy } - resolver, err := graphqlutil.NewConnectionResolver[*graphqlbackend.BackfillQueueItemResolver]( + resolver, err := gqlutil.NewConnectionResolver[*graphqlbackend.BackfillQueueItemResolver]( store, &args.ConnectionResolverArgs, - &graphqlutil.ConnectionResolverOptions{ + &gqlutil.ConnectionResolverOptions{ OrderBy: database.OrderBy{ {Field: string(orderByToDBBackfillColumn(orderBy))}, // user selected or default {Field: string(scheduler.BackfillID)}, // key field to support paging diff --git a/cmd/frontend/internal/insights/resolvers/dashboard_resolvers.go b/cmd/frontend/internal/insights/resolvers/dashboard_resolvers.go index fa19973b3f8..a8d7e3680c6 100644 --- a/cmd/frontend/internal/insights/resolvers/dashboard_resolvers.go +++ b/cmd/frontend/internal/insights/resolvers/dashboard_resolvers.go @@ -11,8 +11,8 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/insights/store" "github.com/sourcegraph/sourcegraph/internal/insights/types" "github.com/sourcegraph/sourcegraph/internal/licensing" @@ -102,15 +102,15 @@ func (d *dashboardConnectionResolver) Nodes(ctx context.Context) ([]graphqlbacke return resolvers, nil } -func (d *dashboardConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (d *dashboardConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { _, err := d.compute(ctx) if err != nil { return nil, err } if d.next != 0 { - return graphqlutil.NextPageCursor(string(newRealDashboardID(d.next).marshal())), nil + return gqlutil.NextPageCursor(string(newRealDashboardID(d.next).marshal())), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } type insightsDashboardResolver struct { @@ -192,8 +192,8 @@ func (d *DashboardInsightViewConnectionResolver) Nodes(ctx context.Context) ([]g return resolvers, nil } -func (d *DashboardInsightViewConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { - return graphqlutil.HasNextPage(false), nil +func (d *DashboardInsightViewConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { + return gqlutil.HasNextPage(false), nil } func (d *DashboardInsightViewConnectionResolver) TotalCount(ctx context.Context) (*int32, error) { diff --git a/cmd/frontend/internal/insights/resolvers/disabled_resolver.go b/cmd/frontend/internal/insights/resolvers/disabled_resolver.go index 7013183ee48..d781f10e774 100644 --- a/cmd/frontend/internal/insights/resolvers/disabled_resolver.go +++ b/cmd/frontend/internal/insights/resolvers/disabled_resolver.go @@ -4,7 +4,7 @@ import ( "context" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -100,7 +100,7 @@ func (r *disabledResolver) PreviewRepositoriesFromQuery(ctx context.Context, arg return nil, errors.New(r.reason) } -func (r *disabledResolver) InsightAdminBackfillQueue(ctx context.Context, args *graphqlbackend.AdminBackfillQueueArgs) (*graphqlutil.ConnectionResolver[*graphqlbackend.BackfillQueueItemResolver], error) { +func (r *disabledResolver) InsightAdminBackfillQueue(ctx context.Context, args *graphqlbackend.AdminBackfillQueueArgs) (*gqlutil.ConnectionResolver[*graphqlbackend.BackfillQueueItemResolver], error) { return nil, errors.New(r.reason) } func (r *disabledResolver) RetryInsightSeriesBackfill(ctx context.Context, args *graphqlbackend.BackfillArgs) (*graphqlbackend.BackfillQueueItemResolver, error) { diff --git a/cmd/frontend/internal/insights/resolvers/insight_view_resolvers.go b/cmd/frontend/internal/insights/resolvers/insight_view_resolvers.go index c2ecef7d3ec..5e1afc785b9 100644 --- a/cmd/frontend/internal/insights/resolvers/insight_view_resolvers.go +++ b/cmd/frontend/internal/insights/resolvers/insight_view_resolvers.go @@ -15,10 +15,10 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gitserver" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/insights/background" "github.com/sourcegraph/sourcegraph/internal/insights/query/querybuilder" "github.com/sourcegraph/sourcegraph/internal/insights/scheduler" @@ -1151,16 +1151,16 @@ func (d *InsightViewQueryConnectionResolver) Nodes(ctx context.Context) ([]graph return resolvers, nil } -func (d *InsightViewQueryConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (d *InsightViewQueryConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { _, next, err := d.computeViews(ctx) if err != nil { return nil, err } if next != "" { - return graphqlutil.NextPageCursor(string(relay.MarshalID(insightKind, d.next))), nil + return gqlutil.NextPageCursor(string(relay.MarshalID(insightKind, d.next))), nil } - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } func (r *InsightViewQueryConnectionResolver) TotalCount(ctx context.Context) (*int32, error) { diff --git a/cmd/frontend/internal/notebooks/resolvers/BUILD.bazel b/cmd/frontend/internal/notebooks/resolvers/BUILD.bazel index 41d1b92ce95..fc23fd6cb50 100644 --- a/cmd/frontend/internal/notebooks/resolvers/BUILD.bazel +++ b/cmd/frontend/internal/notebooks/resolvers/BUILD.bazel @@ -13,7 +13,6 @@ go_library( visibility = ["//cmd/frontend:__subpackages__"], deps = [ "//cmd/frontend/graphqlbackend", - "//cmd/frontend/graphqlbackend/graphqlutil", "//internal/database", "//internal/dotcom", "//internal/errcode", diff --git a/cmd/frontend/internal/notebooks/resolvers/resolvers.go b/cmd/frontend/internal/notebooks/resolvers/resolvers.go index c5c78e173df..5e75558f32c 100644 --- a/cmd/frontend/internal/notebooks/resolvers/resolvers.go +++ b/cmd/frontend/internal/notebooks/resolvers/resolvers.go @@ -7,7 +7,6 @@ import ( "github.com/graph-gophers/graphql-go/relay" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/dotcom" "github.com/sourcegraph/sourcegraph/internal/errcode" @@ -354,12 +353,12 @@ func (n *notebookConnectionResolver) TotalCount(ctx context.Context) int32 { return n.totalCount } -func (n *notebookConnectionResolver) PageInfo(ctx context.Context) *graphqlutil.PageInfo { +func (n *notebookConnectionResolver) PageInfo(ctx context.Context) *gqlutil.PageInfo { if len(n.notebooks) == 0 || !n.hasNextPage { - return graphqlutil.HasNextPage(false) + return gqlutil.HasNextPage(false) } // The after value (offset) for the next page is computed from the current after value + the number of retrieved notebooks - return graphqlutil.NextPageCursor(marshalNotebookCursor(n.afterCursor + int64(len(n.notebooks)))) + return gqlutil.NextPageCursor(marshalNotebookCursor(n.afterCursor + int64(len(n.notebooks)))) } type notebookResolver struct { diff --git a/cmd/frontend/internal/notebooks/resolvers/stars_resolvers.go b/cmd/frontend/internal/notebooks/resolvers/stars_resolvers.go index 901b74093b8..af3593a16a5 100644 --- a/cmd/frontend/internal/notebooks/resolvers/stars_resolvers.go +++ b/cmd/frontend/internal/notebooks/resolvers/stars_resolvers.go @@ -7,7 +7,6 @@ import ( "github.com/graph-gophers/graphql-go/relay" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/notebooks" @@ -44,12 +43,12 @@ func (n *notebookStarConnectionResolver) TotalCount() int32 { return n.totalCount } -func (n *notebookStarConnectionResolver) PageInfo() *graphqlutil.PageInfo { +func (n *notebookStarConnectionResolver) PageInfo() *gqlutil.PageInfo { if len(n.stars) == 0 || !n.hasNextPage { - return graphqlutil.HasNextPage(false) + return gqlutil.HasNextPage(false) } // The after value (offset) for the next page is computed from the current after value + the number of retrieved notebook stars - return graphqlutil.NextPageCursor(marshalNotebookStarCursor(n.afterCursor + int64(len(n.stars)))) + return gqlutil.NextPageCursor(marshalNotebookStarCursor(n.afterCursor + int64(len(n.stars)))) } type notebookStarResolver struct { diff --git a/cmd/frontend/internal/own/resolvers/BUILD.bazel b/cmd/frontend/internal/own/resolvers/BUILD.bazel index ffcfa27992c..27a29c1e4af 100644 --- a/cmd/frontend/internal/own/resolvers/BUILD.bazel +++ b/cmd/frontend/internal/own/resolvers/BUILD.bazel @@ -16,7 +16,6 @@ go_library( visibility = ["//cmd/frontend:__subpackages__"], deps = [ "//cmd/frontend/graphqlbackend", - "//cmd/frontend/graphqlbackend/graphqlutil", "//internal/actor", "//internal/api", "//internal/auth", diff --git a/cmd/frontend/internal/own/resolvers/codeowners_resolvers.go b/cmd/frontend/internal/own/resolvers/codeowners_resolvers.go index 342ecc8a05f..5fc4a532ae6 100644 --- a/cmd/frontend/internal/own/resolvers/codeowners_resolvers.go +++ b/cmd/frontend/internal/own/resolvers/codeowners_resolvers.go @@ -9,7 +9,6 @@ import ( "github.com/graph-gophers/graphql-go/relay" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/auth" @@ -187,7 +186,7 @@ func (r *ownResolver) CodeownersIngestedFiles(ctx context.Context, args *graphql codeownersStore: r.db.Codeowners(), } if args.After != nil { - cursor, err := graphqlutil.DecodeIntCursor(args.After) + cursor, err := gqlutil.DecodeIntCursor(args.After) if err != nil { return nil, err } @@ -262,7 +261,7 @@ type codeownersIngestedFileConnectionResolver struct { once sync.Once cursor int32 limit int - pageInfo *graphqlutil.PageInfo + pageInfo *gqlutil.PageInfo err error codeownersFiles []*types.CodeownersFile @@ -283,9 +282,9 @@ func (r *codeownersIngestedFileConnectionResolver) compute(ctx context.Context) } r.codeownersFiles = codeownersFiles if next > 0 { - r.pageInfo = graphqlutil.EncodeIntCursor(&next) + r.pageInfo = gqlutil.EncodeIntCursor(&next) } else { - r.pageInfo = graphqlutil.HasNextPage(false) + r.pageInfo = gqlutil.HasNextPage(false) } }) } @@ -308,7 +307,7 @@ func (r *codeownersIngestedFileConnectionResolver) TotalCount(ctx context.Contex return r.codeownersStore.CountCodeownersFiles(ctx) } -func (r *codeownersIngestedFileConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (r *codeownersIngestedFileConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { r.compute(ctx) return r.pageInfo, r.err } diff --git a/cmd/frontend/internal/own/resolvers/resolvers.go b/cmd/frontend/internal/own/resolvers/resolvers.go index 160df17a7cc..7b7e046daa2 100644 --- a/cmd/frontend/internal/own/resolvers/resolvers.go +++ b/cmd/frontend/internal/own/resolvers/resolvers.go @@ -14,7 +14,6 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/auth" @@ -399,7 +398,7 @@ func (r *ownResolver) ownershipConnection( } // 5. Apply pagination from the parameter & compute next cursor: - cursor, err := graphqlutil.DecodeCursor(args.After) + cursor, err := gqlutil.DecodeCursor(args.After) if err != nil { return nil, err } @@ -496,8 +495,8 @@ func (r *ownershipConnectionResolver) TotalOwners(_ context.Context) (int32, err return int32(r.totalOwners), nil } -func (r *ownershipConnectionResolver) PageInfo(_ context.Context) (*graphqlutil.PageInfo, error) { - return graphqlutil.EncodeCursor(r.next), nil +func (r *ownershipConnectionResolver) PageInfo(_ context.Context) (*gqlutil.PageInfo, error) { + return gqlutil.EncodeCursor(r.next), nil } func (r *ownershipConnectionResolver) Nodes(_ context.Context) ([]graphqlbackend.OwnershipResolver, error) { diff --git a/cmd/frontend/internal/prompts/resolvers/BUILD.bazel b/cmd/frontend/internal/prompts/resolvers/BUILD.bazel index 813e9457679..c8c106cd039 100644 --- a/cmd/frontend/internal/prompts/resolvers/BUILD.bazel +++ b/cmd/frontend/internal/prompts/resolvers/BUILD.bazel @@ -12,7 +12,6 @@ go_library( visibility = ["//cmd/frontend:__subpackages__"], deps = [ "//cmd/frontend/graphqlbackend", - "//cmd/frontend/graphqlbackend/graphqlutil", "//internal/auth", "//internal/database", "//internal/gqlutil", @@ -38,12 +37,12 @@ go_test( ], deps = [ "//cmd/frontend/graphqlbackend", - "//cmd/frontend/graphqlbackend/graphqlutil", "//internal/actor", "//internal/auth", "//internal/database", "//internal/database/dbmocks", "//internal/database/dbtest", + "//internal/gqlutil", "//internal/types", "//lib/pointers", "@com_github_derision_test_go_mockgen_v2//testutil/require", diff --git a/cmd/frontend/internal/prompts/resolvers/connection_test.go b/cmd/frontend/internal/prompts/resolvers/connection_test.go index 6384c84472c..140247a6502 100644 --- a/cmd/frontend/internal/prompts/resolvers/connection_test.go +++ b/cmd/frontend/internal/prompts/resolvers/connection_test.go @@ -7,10 +7,10 @@ import ( "github.com/sourcegraph/log/logtest" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/database/dbtest" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" "github.com/sourcegraph/sourcegraph/lib/pointers" ) @@ -55,20 +55,20 @@ func TestPromptsConnectionStore(t *testing.T) { } t.Run("no orderBy", func(t *testing.T) { - graphqlutil.TestConnectionResolverStoreSuite(t, connectionStore, nil) + gqlutil.TestConnectionResolverStoreSuite(t, connectionStore, nil) }) t.Run("orderBy updated_at", func(t *testing.T) { - var pgArgs graphqlutil.TestPaginationArgs + var pgArgs gqlutil.TestPaginationArgs pgArgs.OrderBy, pgArgs.Ascending = database.PromptsOrderByUpdatedAt.ToOptions() - graphqlutil.TestConnectionResolverStoreSuite(t, connectionStore, &pgArgs) + gqlutil.TestConnectionResolverStoreSuite(t, connectionStore, &pgArgs) }) t.Run("orderBy name_with_owner", func(t *testing.T) { - var pgArgs graphqlutil.TestPaginationArgs + var pgArgs gqlutil.TestPaginationArgs pgArgs.OrderBy, pgArgs.Ascending = database.PromptsOrderByNameWithOwner.ToOptions() - graphqlutil.TestConnectionResolverStoreSuite(t, connectionStore, &pgArgs) + gqlutil.TestConnectionResolverStoreSuite(t, connectionStore, &pgArgs) }) } -var dummyConnectionResolverArgs = graphqlutil.ConnectionResolverArgs{First: pointers.Ptr[int32](1)} +var dummyConnectionResolverArgs = gqlutil.ConnectionResolverArgs{First: pointers.Ptr[int32](1)} diff --git a/cmd/frontend/internal/prompts/resolvers/resolvers.go b/cmd/frontend/internal/prompts/resolvers/resolvers.go index f0a14979ceb..2a09505230a 100644 --- a/cmd/frontend/internal/prompts/resolvers/resolvers.go +++ b/cmd/frontend/internal/prompts/resolvers/resolvers.go @@ -9,7 +9,6 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gqlutil" @@ -229,10 +228,10 @@ func (r *Resolver) Prompts(ctx context.Context, args graphqlbackend.PromptsArgs) return nil, errors.New("invalid orderBy") } - opts := graphqlutil.ConnectionResolverOptions{} + opts := gqlutil.ConnectionResolverOptions{} opts.OrderBy, opts.Ascending = orderBy.ToOptions() - return graphqlutil.NewConnectionResolver(connectionStore, &args.ConnectionResolverArgs, &opts) + return gqlutil.NewConnectionResolver(connectionStore, &args.ConnectionResolverArgs, &opts) } func (r *Resolver) CreatePrompt(ctx context.Context, args *graphqlbackend.CreatePromptArgs) (graphqlbackend.PromptResolver, error) { diff --git a/cmd/frontend/internal/repos/webhooks/resolvers/BUILD.bazel b/cmd/frontend/internal/repos/webhooks/resolvers/BUILD.bazel index 1204d7ad928..08f0c4b330a 100644 --- a/cmd/frontend/internal/repos/webhooks/resolvers/BUILD.bazel +++ b/cmd/frontend/internal/repos/webhooks/resolvers/BUILD.bazel @@ -9,7 +9,6 @@ go_library( visibility = ["//cmd/frontend:__subpackages__"], deps = [ "//cmd/frontend/graphqlbackend", - "//cmd/frontend/graphqlbackend/graphqlutil", "//cmd/frontend/internal/backend", "//internal/auth", "//internal/conf", diff --git a/cmd/frontend/internal/repos/webhooks/resolvers/resolver.go b/cmd/frontend/internal/repos/webhooks/resolvers/resolver.go index 787c49e3f0a..fc4e1918259 100644 --- a/cmd/frontend/internal/repos/webhooks/resolvers/resolver.go +++ b/cmd/frontend/internal/repos/webhooks/resolvers/resolver.go @@ -10,7 +10,6 @@ import ( "github.com/graph-gophers/graphql-go/relay" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/backend" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/conf" @@ -197,16 +196,16 @@ func (c *webhooksConnectionResolver) TotalCount(ctx context.Context) (int32, err return int32(count), nil } -func (c *webhooksConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.PageInfo, error) { +func (c *webhooksConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.PageInfo, error) { _, next, err := c.compute(ctx) if err != nil { return nil, err } if next == 0 { - return graphqlutil.HasNextPage(false), nil + return gqlutil.HasNextPage(false), nil } - return graphqlutil.NextPageCursor(MarshalWebhookCursor( + return gqlutil.NextPageCursor(MarshalWebhookCursor( &types.Cursor{ Column: c.opt.Cursor.Column, Value: fmt.Sprintf("%d", next), diff --git a/cmd/frontend/internal/savedsearches/resolvers/BUILD.bazel b/cmd/frontend/internal/savedsearches/resolvers/BUILD.bazel index c6f61687e76..28ed99ec81e 100644 --- a/cmd/frontend/internal/savedsearches/resolvers/BUILD.bazel +++ b/cmd/frontend/internal/savedsearches/resolvers/BUILD.bazel @@ -12,7 +12,6 @@ go_library( visibility = ["//cmd/frontend:__subpackages__"], deps = [ "//cmd/frontend/graphqlbackend", - "//cmd/frontend/graphqlbackend/graphqlutil", "//internal/auth", "//internal/database", "//internal/errcode", @@ -40,12 +39,12 @@ go_test( ], deps = [ "//cmd/frontend/graphqlbackend", - "//cmd/frontend/graphqlbackend/graphqlutil", "//internal/actor", "//internal/auth", "//internal/database", "//internal/database/dbmocks", "//internal/database/dbtest", + "//internal/gqlutil", "//internal/types", "//lib/errors", "//lib/pointers", diff --git a/cmd/frontend/internal/savedsearches/resolvers/connection_test.go b/cmd/frontend/internal/savedsearches/resolvers/connection_test.go index 2a8171d1a60..c1ea589051e 100644 --- a/cmd/frontend/internal/savedsearches/resolvers/connection_test.go +++ b/cmd/frontend/internal/savedsearches/resolvers/connection_test.go @@ -7,10 +7,10 @@ import ( "github.com/sourcegraph/log/logtest" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/database/dbtest" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/types" "github.com/sourcegraph/sourcegraph/lib/pointers" ) @@ -56,20 +56,20 @@ func TestSavedSearchesConnectionStore(t *testing.T) { } t.Run("no orderBy", func(t *testing.T) { - graphqlutil.TestConnectionResolverStoreSuite(t, connectionStore, nil) + gqlutil.TestConnectionResolverStoreSuite(t, connectionStore, nil) }) t.Run("orderBy updated_at", func(t *testing.T) { - var pgArgs graphqlutil.TestPaginationArgs + var pgArgs gqlutil.TestPaginationArgs pgArgs.OrderBy, pgArgs.Ascending = database.SavedSearchesOrderByUpdatedAt.ToOptions() - graphqlutil.TestConnectionResolverStoreSuite(t, connectionStore, &pgArgs) + gqlutil.TestConnectionResolverStoreSuite(t, connectionStore, &pgArgs) }) t.Run("orderBy description", func(t *testing.T) { - var pgArgs graphqlutil.TestPaginationArgs + var pgArgs gqlutil.TestPaginationArgs pgArgs.OrderBy, pgArgs.Ascending = database.SavedSearchesOrderByDescription.ToOptions() - graphqlutil.TestConnectionResolverStoreSuite(t, connectionStore, &pgArgs) + gqlutil.TestConnectionResolverStoreSuite(t, connectionStore, &pgArgs) }) } -var dummyConnectionResolverArgs = graphqlutil.ConnectionResolverArgs{First: pointers.Ptr[int32](1)} +var dummyConnectionResolverArgs = gqlutil.ConnectionResolverArgs{First: pointers.Ptr[int32](1)} diff --git a/cmd/frontend/internal/savedsearches/resolvers/resolvers.go b/cmd/frontend/internal/savedsearches/resolvers/resolvers.go index 4cc23c1f3b5..08a244a0c69 100644 --- a/cmd/frontend/internal/savedsearches/resolvers/resolvers.go +++ b/cmd/frontend/internal/savedsearches/resolvers/resolvers.go @@ -9,7 +9,6 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/errcode" @@ -222,10 +221,10 @@ func (r *Resolver) SavedSearches(ctx context.Context, args graphqlbackend.SavedS return nil, errors.New("invalid orderBy") } - opts := graphqlutil.ConnectionResolverOptions{} + opts := gqlutil.ConnectionResolverOptions{} opts.OrderBy, opts.Ascending = orderBy.ToOptions() - return graphqlutil.NewConnectionResolver(connectionStore, &args.ConnectionResolverArgs, &opts) + return gqlutil.NewConnectionResolver(connectionStore, &args.ConnectionResolverArgs, &opts) } func (r *Resolver) CreateSavedSearch(ctx context.Context, args *graphqlbackend.CreateSavedSearchArgs) (graphqlbackend.SavedSearchResolver, error) { diff --git a/cmd/frontend/internal/search/resolvers/BUILD.bazel b/cmd/frontend/internal/search/resolvers/BUILD.bazel index d58ea20af66..a89378c84e4 100644 --- a/cmd/frontend/internal/search/resolvers/BUILD.bazel +++ b/cmd/frontend/internal/search/resolvers/BUILD.bazel @@ -12,7 +12,6 @@ go_library( visibility = ["//cmd/frontend:__subpackages__"], deps = [ "//cmd/frontend/graphqlbackend", - "//cmd/frontend/graphqlbackend/graphqlutil", "//internal/conf", "//internal/database", "//internal/errcode", diff --git a/cmd/frontend/internal/search/resolvers/resolver.go b/cmd/frontend/internal/search/resolvers/resolver.go index 1bfac4ffa2e..5c4a6ab00bf 100644 --- a/cmd/frontend/internal/search/resolvers/resolver.go +++ b/cmd/frontend/internal/search/resolvers/resolver.go @@ -13,8 +13,8 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/search/exhaustive/service" "github.com/sourcegraph/sourcegraph/internal/search/exhaustive/store" "github.com/sourcegraph/sourcegraph/internal/types" @@ -66,7 +66,7 @@ func (r *Resolver) DeleteSearchJob(ctx context.Context, args *graphqlbackend.Del return &graphqlbackend.EmptyResponse{}, r.svc.DeleteSearchJob(ctx, jobID) } -func newSearchJobConnectionResolver(ctx context.Context, db database.DB, service *service.Service, args *graphqlbackend.SearchJobsArgs) (*graphqlutil.ConnectionResolver[graphqlbackend.SearchJobResolver], error) { +func newSearchJobConnectionResolver(ctx context.Context, db database.DB, service *service.Service, args *graphqlbackend.SearchJobsArgs) (*gqlutil.ConnectionResolver[graphqlbackend.SearchJobResolver], error) { var states []string if args.States != nil { states = *args.States @@ -96,10 +96,10 @@ func newSearchJobConnectionResolver(ctx context.Context, db database.DB, service query: query, userIDs: ids, } - return graphqlutil.NewConnectionResolver[graphqlbackend.SearchJobResolver]( + return gqlutil.NewConnectionResolver[graphqlbackend.SearchJobResolver]( s, &args.ConnectionResolverArgs, - &graphqlutil.ConnectionResolverOptions{ + &gqlutil.ConnectionResolverOptions{ Ascending: !args.Descending, OrderBy: database.OrderBy{{Field: normalize(args.OrderBy)}, {Field: "id"}}}, ) @@ -219,7 +219,7 @@ func (s *searchJobsConnectionStore) UnmarshalCursor(cursor string, orderBy datab } } -func (r *Resolver) SearchJobs(ctx context.Context, args *graphqlbackend.SearchJobsArgs) (*graphqlutil.ConnectionResolver[graphqlbackend.SearchJobResolver], error) { +func (r *Resolver) SearchJobs(ctx context.Context, args *graphqlbackend.SearchJobsArgs) (*gqlutil.ConnectionResolver[graphqlbackend.SearchJobResolver], error) { return newSearchJobConnectionResolver(ctx, r.db, r.svc, args) } diff --git a/cmd/frontend/internal/searchcontexts/resolvers/BUILD.bazel b/cmd/frontend/internal/searchcontexts/resolvers/BUILD.bazel index 630f88cf409..14114c926fc 100644 --- a/cmd/frontend/internal/searchcontexts/resolvers/BUILD.bazel +++ b/cmd/frontend/internal/searchcontexts/resolvers/BUILD.bazel @@ -9,7 +9,6 @@ go_library( visibility = ["//cmd/frontend:__subpackages__"], deps = [ "//cmd/frontend/graphqlbackend", - "//cmd/frontend/graphqlbackend/graphqlutil", "//internal/actor", "//internal/api", "//internal/auth", diff --git a/cmd/frontend/internal/searchcontexts/resolvers/resolvers.go b/cmd/frontend/internal/searchcontexts/resolvers/resolvers.go index a7d36abc615..608c27bb075 100644 --- a/cmd/frontend/internal/searchcontexts/resolvers/resolvers.go +++ b/cmd/frontend/internal/searchcontexts/resolvers/resolvers.go @@ -7,7 +7,6 @@ import ( "github.com/graph-gophers/graphql-go/relay" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/actor" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/auth" @@ -529,12 +528,12 @@ func (s *searchContextConnectionResolver) TotalCount() int32 { return s.totalCount } -func (s *searchContextConnectionResolver) PageInfo() *graphqlutil.PageInfo { +func (s *searchContextConnectionResolver) PageInfo() *gqlutil.PageInfo { if len(s.searchContexts) == 0 || !s.hasNextPage { - return graphqlutil.HasNextPage(false) + return gqlutil.HasNextPage(false) } // The after value (offset) for the next page is computed from the current after value + the number of retrieved search contexts - return graphqlutil.NextPageCursor(marshalSearchContextCursor(s.afterCursor + int32(len(s.searchContexts)))) + return gqlutil.NextPageCursor(marshalSearchContextCursor(s.afterCursor + int32(len(s.searchContexts)))) } type searchContextRepositoryRevisionsResolver struct { diff --git a/cmd/frontend/internal/telemetry/resolvers/BUILD.bazel b/cmd/frontend/internal/telemetry/resolvers/BUILD.bazel index 99ce5b8da45..b1549e9eeaf 100644 --- a/cmd/frontend/internal/telemetry/resolvers/BUILD.bazel +++ b/cmd/frontend/internal/telemetry/resolvers/BUILD.bazel @@ -13,7 +13,6 @@ go_library( visibility = ["//cmd/frontend:__subpackages__"], deps = [ "//cmd/frontend/graphqlbackend", - "//cmd/frontend/graphqlbackend/graphqlutil", "//internal/auth", "//internal/database", "//internal/gqlutil", diff --git a/cmd/frontend/internal/telemetry/resolvers/exportedevents_resolvers.go b/cmd/frontend/internal/telemetry/resolvers/exportedevents_resolvers.go index 2aa481610ec..16161ef35b9 100644 --- a/cmd/frontend/internal/telemetry/resolvers/exportedevents_resolvers.go +++ b/cmd/frontend/internal/telemetry/resolvers/exportedevents_resolvers.go @@ -10,7 +10,6 @@ import ( "google.golang.org/protobuf/encoding/protojson" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/lib/errors" @@ -18,7 +17,7 @@ import ( ) func decodeExportedEventsCursor(cursor string) (*time.Time, error) { - cursor, err := graphqlutil.DecodeCursor(&cursor) + cursor, err := gqlutil.DecodeCursor(&cursor) if err != nil { return nil, errors.Wrap(err, "invalid cursor") } @@ -29,12 +28,12 @@ func decodeExportedEventsCursor(cursor string) (*time.Time, error) { return &t, nil } -func encodeExportedEventsCursor(t time.Time) *graphqlutil.PageInfo { +func encodeExportedEventsCursor(t time.Time) *gqlutil.PageInfo { ts, err := t.MarshalText() if err != nil { - return graphqlutil.HasNextPage(false) + return gqlutil.HasNextPage(false) } - return graphqlutil.EncodeCursor(pointers.Ptr(string(ts))) + return gqlutil.EncodeCursor(pointers.Ptr(string(ts))) } type ExportedEventResolver struct { @@ -86,9 +85,9 @@ func (r *ExportedEventsConnectionResolver) TotalCount() (int32, error) { return int32(count), nil } -func (r *ExportedEventsConnectionResolver) PageInfo() *graphqlutil.PageInfo { +func (r *ExportedEventsConnectionResolver) PageInfo() *gqlutil.PageInfo { if len(r.exported) == 0 || len(r.exported) < r.limit { - return graphqlutil.HasNextPage(false) + return gqlutil.HasNextPage(false) } lastEvent := r.exported[len(r.exported)-1] return encodeExportedEventsCursor(lastEvent.Timestamp) diff --git a/internal/codeintel/codenav/transport/graphql/BUILD.bazel b/internal/codeintel/codenav/transport/graphql/BUILD.bazel index 095963cdc67..d4568da264a 100644 --- a/internal/codeintel/codenav/transport/graphql/BUILD.bazel +++ b/internal/codeintel/codenav/transport/graphql/BUILD.bazel @@ -25,7 +25,6 @@ go_library( tags = [TAG_PLATFORM_GRAPH], visibility = ["//:__subpackages__"], deps = [ - "//cmd/frontend/graphqlbackend/graphqlutil", "//internal/actor", "//internal/api", "//internal/authz", @@ -40,6 +39,7 @@ go_library( "//internal/conf", "//internal/database", "//internal/gitserver", + "//internal/gqlutil", "//internal/metrics", "//internal/observation", "//internal/types", diff --git a/internal/codeintel/codenav/transport/graphql/root_resolver_code_graph.go b/internal/codeintel/codenav/transport/graphql/root_resolver_code_graph.go index 60b5b81049a..4a2b2b901d1 100644 --- a/internal/codeintel/codenav/transport/graphql/root_resolver_code_graph.go +++ b/internal/codeintel/codenav/transport/graphql/root_resolver_code_graph.go @@ -7,9 +7,9 @@ import ( "github.com/sourcegraph/scip/bindings/go/scip" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" resolverstubs "github.com/sourcegraph/sourcegraph/internal/codeintel/resolvers" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/observation" "github.com/sourcegraph/sourcegraph/lib/pointers" ) @@ -21,10 +21,10 @@ func (c *codeGraphDataResolver) Occurrences(ctx context.Context, args *resolvers const maxPageSize = 100000 args = args.Normalize(maxPageSize) - impl, err := graphqlutil.NewConnectionResolver[resolverstubs.SCIPOccurrenceResolver]( + impl, err := gqlutil.NewConnectionResolver[resolverstubs.SCIPOccurrenceResolver]( &occurrenceConnectionStore{c}, - &graphqlutil.ConnectionResolverArgs{First: args.First, After: args.After}, - &graphqlutil.ConnectionResolverOptions{MaxPageSize: maxPageSize, Reverse: pointers.Ptr(false)}) + &gqlutil.ConnectionResolverArgs{First: args.First, After: args.After}, + &gqlutil.ConnectionResolverOptions{MaxPageSize: maxPageSize, Reverse: pointers.Ptr(false)}) if err != nil { return nil, err } @@ -32,7 +32,7 @@ func (c *codeGraphDataResolver) Occurrences(ctx context.Context, args *resolvers } type occurrenceConnectionResolver struct { - impl *graphqlutil.ConnectionResolver[resolverstubs.SCIPOccurrenceResolver] + impl *gqlutil.ConnectionResolver[resolverstubs.SCIPOccurrenceResolver] // Arguments graphData *codeGraphDataResolver @@ -45,11 +45,11 @@ func (o *occurrenceConnectionResolver) Nodes(ctx context.Context) ([]resolverstu return o.impl.Nodes(ctx) } -func (o *occurrenceConnectionResolver) PageInfo(ctx context.Context) (*graphqlutil.ConnectionPageInfo[resolverstubs.SCIPOccurrenceResolver], error) { +func (o *occurrenceConnectionResolver) PageInfo(ctx context.Context) (*gqlutil.ConnectionPageInfo[resolverstubs.SCIPOccurrenceResolver], error) { return o.impl.PageInfo(ctx) } -var _ graphqlutil.ConnectionResolverStore[resolverstubs.SCIPOccurrenceResolver] = &occurrenceConnectionStore{} +var _ gqlutil.ConnectionResolverStore[resolverstubs.SCIPOccurrenceResolver] = &occurrenceConnectionStore{} type scipOccurrence struct { impl *scip.Occurrence @@ -78,7 +78,7 @@ type occurrenceConnectionStore struct { graphData *codeGraphDataResolver } -var _ graphqlutil.ConnectionResolverStore[resolverstubs.SCIPOccurrenceResolver] = &occurrenceConnectionStore{} +var _ gqlutil.ConnectionResolverStore[resolverstubs.SCIPOccurrenceResolver] = &occurrenceConnectionStore{} func (o *occurrenceConnectionStore) ComputeTotal(ctx context.Context) (int32, error) { doc, err := o.graphData.tryRetrieveDocument(ctx) diff --git a/internal/codeintel/resolvers/BUILD.bazel b/internal/codeintel/resolvers/BUILD.bazel index a6cb00effaf..098222824a8 100644 --- a/internal/codeintel/resolvers/BUILD.bazel +++ b/internal/codeintel/resolvers/BUILD.bazel @@ -17,7 +17,6 @@ go_library( tags = [TAG_PLATFORM_GRAPH], visibility = ["//:__subpackages__"], deps = [ - "//cmd/frontend/graphqlbackend/graphqlutil", "//internal/api", "//internal/codeintel/codenav", "//internal/codeintel/core", diff --git a/internal/codeintel/resolvers/codenav.go b/internal/codeintel/resolvers/codenav.go index 9779ba09c97..a0944b9596b 100644 --- a/internal/codeintel/resolvers/codenav.go +++ b/internal/codeintel/resolvers/codenav.go @@ -11,13 +11,13 @@ import ( "github.com/sourcegraph/scip/bindings/go/scip" - "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav" "github.com/sourcegraph/sourcegraph/internal/codeintel/core" "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gitserver" + "github.com/sourcegraph/sourcegraph/internal/gqlutil" "github.com/sourcegraph/sourcegraph/internal/markdown" "github.com/sourcegraph/sourcegraph/internal/types" "github.com/sourcegraph/sourcegraph/lib/errors" @@ -270,7 +270,7 @@ func (args *OccurrencesArgs) Normalize(maxPageSize int32) *OccurrencesArgs { type SCIPOccurrenceConnectionResolver interface { ConnectionResolver[SCIPOccurrenceResolver] - PageInfo(ctx context.Context) (*graphqlutil.ConnectionPageInfo[SCIPOccurrenceResolver], error) + PageInfo(ctx context.Context) (*gqlutil.ConnectionPageInfo[SCIPOccurrenceResolver], error) } type SCIPOccurrenceResolver interface { diff --git a/internal/gqlutil/BUILD.bazel b/internal/gqlutil/BUILD.bazel index c48704aa833..1fd93fe026c 100644 --- a/internal/gqlutil/BUILD.bazel +++ b/internal/gqlutil/BUILD.bazel @@ -3,16 +3,38 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") go_library( name = "gqlutil", - srcs = ["datetime.go"], + srcs = [ + "connection.go", + "connection_resolver.go", + "cursors.go", + "datetime.go", + "doc.go", + "offset.go", + "page_info.go", + "slice_connection_resolver.go", + ], importpath = "github.com/sourcegraph/sourcegraph/internal/gqlutil", visibility = ["//:__subpackages__"], - deps = ["//lib/errors"], + deps = [ + "//internal/database", + "//lib/errors", + "//lib/pointers", + ], ) go_test( name = "gqlutil_test", timeout = "short", - srcs = ["datetime_test.go"], + srcs = [ + "connection_resolver_test.go", + "datetime_test.go", + "slice_connection_resolver_test.go", + ], embed = [":gqlutil"], - deps = ["@com_github_stretchr_testify//require"], + deps = [ + "//internal/database", + "@com_github_google_go_cmp//cmp", + "@com_github_graph_gophers_graphql_go//:graphql-go", + "@com_github_stretchr_testify//require", + ], ) diff --git a/cmd/frontend/graphqlbackend/graphqlutil/connection.go b/internal/gqlutil/connection.go similarity index 97% rename from cmd/frontend/graphqlbackend/graphqlutil/connection.go rename to internal/gqlutil/connection.go index af19159319f..581b96a03a6 100644 --- a/cmd/frontend/graphqlbackend/graphqlutil/connection.go +++ b/internal/gqlutil/connection.go @@ -1,4 +1,4 @@ -package graphqlutil +package gqlutil import "github.com/sourcegraph/sourcegraph/internal/database" diff --git a/cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go b/internal/gqlutil/connection_resolver.go similarity index 99% rename from cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go rename to internal/gqlutil/connection_resolver.go index 0612eba9e19..30c01a8637e 100644 --- a/cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go +++ b/internal/gqlutil/connection_resolver.go @@ -1,4 +1,4 @@ -package graphqlutil +package gqlutil import ( "context" diff --git a/cmd/frontend/graphqlbackend/graphqlutil/connection_resolver_test.go b/internal/gqlutil/connection_resolver_test.go similarity index 99% rename from cmd/frontend/graphqlbackend/graphqlutil/connection_resolver_test.go rename to internal/gqlutil/connection_resolver_test.go index 51ca5673134..7aa4fb420ad 100644 --- a/cmd/frontend/graphqlbackend/graphqlutil/connection_resolver_test.go +++ b/internal/gqlutil/connection_resolver_test.go @@ -1,4 +1,4 @@ -package graphqlutil +package gqlutil import ( "context" diff --git a/cmd/frontend/graphqlbackend/graphqlutil/cursors.go b/internal/gqlutil/cursors.go similarity index 98% rename from cmd/frontend/graphqlbackend/graphqlutil/cursors.go rename to internal/gqlutil/cursors.go index d71a767d8b2..beb4a43eb1f 100644 --- a/cmd/frontend/graphqlbackend/graphqlutil/cursors.go +++ b/internal/gqlutil/cursors.go @@ -1,4 +1,4 @@ -package graphqlutil +package gqlutil import ( "encoding/base64" diff --git a/internal/gqlutil/doc.go b/internal/gqlutil/doc.go new file mode 100644 index 00000000000..129008a3109 --- /dev/null +++ b/internal/gqlutil/doc.go @@ -0,0 +1,2 @@ +// package gqlutil contains utilities for working with GraphQL. +package gqlutil diff --git a/cmd/frontend/graphqlbackend/graphqlutil/offset.go b/internal/gqlutil/offset.go similarity index 94% rename from cmd/frontend/graphqlbackend/graphqlutil/offset.go rename to internal/gqlutil/offset.go index 5dd5b2cb840..5027a1dc22c 100644 --- a/cmd/frontend/graphqlbackend/graphqlutil/offset.go +++ b/internal/gqlutil/offset.go @@ -1,4 +1,4 @@ -package graphqlutil +package gqlutil // NextOffset determines the offset that should be used for a subsequent request. // If there are no more results in the paged result set, this function returns nil. diff --git a/cmd/frontend/graphqlbackend/graphqlutil/page_info.go b/internal/gqlutil/page_info.go similarity index 96% rename from cmd/frontend/graphqlbackend/graphqlutil/page_info.go rename to internal/gqlutil/page_info.go index 4688e39401c..e73beb5dd94 100644 --- a/cmd/frontend/graphqlbackend/graphqlutil/page_info.go +++ b/internal/gqlutil/page_info.go @@ -1,4 +1,4 @@ -package graphqlutil +package gqlutil // PageInfo implements the GraphQL type PageInfo. type PageInfo struct { diff --git a/cmd/frontend/graphqlbackend/graphqlutil/slice_connection_resolver.go b/internal/gqlutil/slice_connection_resolver.go similarity index 98% rename from cmd/frontend/graphqlbackend/graphqlutil/slice_connection_resolver.go rename to internal/gqlutil/slice_connection_resolver.go index e3a7640bfad..4e29ed484c8 100644 --- a/cmd/frontend/graphqlbackend/graphqlutil/slice_connection_resolver.go +++ b/internal/gqlutil/slice_connection_resolver.go @@ -1,4 +1,4 @@ -package graphqlutil +package gqlutil import ( "context" diff --git a/cmd/frontend/graphqlbackend/graphqlutil/slice_connection_resolver_test.go b/internal/gqlutil/slice_connection_resolver_test.go similarity index 98% rename from cmd/frontend/graphqlbackend/graphqlutil/slice_connection_resolver_test.go rename to internal/gqlutil/slice_connection_resolver_test.go index badb9e137c9..85ea8ac60b5 100644 --- a/cmd/frontend/graphqlbackend/graphqlutil/slice_connection_resolver_test.go +++ b/internal/gqlutil/slice_connection_resolver_test.go @@ -1,4 +1,4 @@ -package graphqlutil +package gqlutil import ( "bytes"