Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add missing service GQL error defn #1123

Merged
merged 6 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions graphql_api/tests/test_owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

from billing.helpers import mock_all_plans_and_tiers
from codecov.commands.exceptions import (
MissingService,
UnauthorizedGuestAccess,
)
from codecov_auth.models import GithubAppInstallation, OwnerProfile
Expand Down Expand Up @@ -708,7 +707,6 @@ def test_owner_query_with_no_service(self):

res = self.gql_request(query, provider="", with_errors=True)

assert res["errors"][0]["message"] == MissingService.message
assert res["data"]["owner"] is None

def test_owner_query_with_private_repos(self):
Expand Down Expand Up @@ -1195,3 +1193,19 @@ def test_fetch_available_plans_is_enterprise_plan(self):
]
}
}

def test_fetch_owner_with_no_service(self):
current_org = OwnerFactory(
username="random-plan-user",
service="github",
plan=PlanName.BASIC_PLAN_NAME.value,
)

query = """{
owner(username: "%s") {
username
}
}
""" % (current_org.username)
data = self.gql_request(query, owner=current_org, provider="", with_errors=True)
assert data == {"data": {"owner": None}}
4 changes: 4 additions & 0 deletions graphql_api/types/errors/errors.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ type ProviderError implements ResolverError {
type OwnerNotActivatedError implements ResolverError {
message: String!
}

type MissingService implements ResolverError {
message: String!
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
union UpdateDefaultOrganizationError = UnauthenticatedError | ValidationError
union UpdateDefaultOrganizationError = UnauthenticatedError | ValidationError | MissingService

type UpdateDefaultOrganizationPayload {
error: UpdateDefaultOrganizationError
Expand Down
3 changes: 3 additions & 0 deletions graphql_api/types/query/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ async def resolve_owner(
configure_sentry_scope(query_name(info))

service = info.context["service"]
if not service:
return None

user = info.context["request"].current_owner or info.context["request"].user

if settings.IS_ENTERPRISE and settings.GUEST_ACCESS is False:
Expand Down