Use safe navigation operator to avoid GraphQL errors when querying nonexistent package
What does this MR do and why?
This MR is intended to address #434001. I assembled this during the FY25-Q1 Support Hackathon: gitlab-com/support/support-team-meta#5827 (closed).
This MR adds a single character. In PackageDetailsResolver
, this line is adjusted so that GraphQL doesn't return an error when someone attempts to query a package that doesn't exist.
Before
package if package.default?
After
package if package&.default?
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before this change
After this change
How to set up and validate locally
To observe the current behavior, browse to gitlab.com/-/graphql-explorer and issue the query below.
To observe my changes:
- Browse to
https://gdk:3000/-/graphql-explorer
- Issue a query like the one below
- Observe the
Internal server error
in themessage
that is returned
query package {
package(id: "gid://gitlab/Packages::Package/00099999999999999999999999") {
id
name
}
}
Edited by Brie Carranza