Skip to content

Non existing package raises the error when query a package via GraphQL

Problem

When query a non existing package via GraphQL it raises the error.

query package {
  package(id:"gid://gitlab/Packages::Package/non_existing") {
    id
  }
}

It will result in undefined method default? for nil:NilClass

Solution

Use & safe navigation operator when checking status of a package in the PackageDetailsResolver