Skip to content

Graphql returning null for fields of type upload #6221

Closed

Description

@pzpsofficial

Link to reproduction

https://github.com/pzpsofficial/payload-graphql-issue

Describe the Bug

Hi!

All of a sudden graphql has stopped returning any data for all media relation fields of type upload. If the field is not required I'm getting just null, and when it's I'm getting error: cannot return null for non-nullable field.

The REST API is working as expected. The graphql just stopped working at some point.

Here is my default media collection with right read access:

import { CollectionConfig } from 'payload/types'

const Media: CollectionConfig = {
  slug: 'media',
  upload: true,
  fields: [],
  access: {
    read: () => true
  }
}

export default Media;

And example field that is returning null:

...
{
  name: 'image',
  type: 'upload',
  relationTo: 'media',
  admin: {
    condition: (_, data) => data.type === 'image',
  }
},
...

To Reproduce

The thing is it just stopped working. Only thing I can think of would be that I've prepared demo about Payload at work, so I created other Payload project in the same parent directory, but it seems so impossible that I almost feel ashamed thinking about this.

Update: I've just uploaded the reproduction repo. In order to reproduce it you need to enter admin panel, create example Page, then go to localhost:3000/api/graphql-playground and execute the following query. You will see null instead of image id in the gql response.

query Test {
  Pages {
      docs {
        image {
          id
        }
      }
   }
}

Payload Version

2.0.0

Adapters and Plugins

No response

Activity

  1. added
    status: needs-triage
    on May 5, 2024
  2. flamedmg commented on May 5, 2024

    @flamedmg

    i have the same issue, it was working just fine on firay, but on saturday it stopped to work. No changes were made.

  3. slavanossar commented on May 6, 2024

    @slavanossar
    Contributor

    Also experiencing this issue, works in 2.14.2 but breaks after upgrading to 2.15.0.

    Possibly related to #6141.

  4. jonowu commented on May 6, 2024

    @jonowu
    Contributor

    I was experiencing the same issue and was able to work around it for now.

    I believe this issue is caused by the 2.15.0 release. After reverting back to 2.14.0 my upload fields don't return null anymore.

    Likely you didn't update any packages on your side manually, but as this is a minor patch you'll want to remove the caret in your package version e.g. ^2.0.0 can be 2.0.0

  5. sburgpit commented on May 6, 2024

    @sburgpit

    Also experiencing same issue, when upgrading from 2.14.2 to 2.15.0

  6. slongiaru-dmind commented on May 6, 2024

    @slongiaru-dmind

    Here too update from 2.12.1 to 2.15.0.
    Via the REST API it seems to work fine.

  7. JarrodMFlesch commented on May 6, 2024

    @JarrodMFlesch
    Contributor

    Hey everyone, thanks for the report. The fix will go out after this PR is merged into main and main is released (shooting for today). Will also make PR for beta branch too.

  8. linked a pull request that will close this issueFix/graphql upload relations #6233on May 6, 2024
  9. JarrodMFlesch commented on May 6, 2024

    @JarrodMFlesch
    Contributor

    Fix was released in 2.16.0.

  10. pzpsofficial commented on May 6, 2024

    @pzpsofficial
    Author

    @JarrodMFlesch Thanks for that fix and for all great work 💪

  11. ayarse commented on May 11, 2024

    @ayarse

    @JarrodMFlesch I'm still having this issue on 2.16.1.
    In my case, the issue is even stranger because the upload field doesn't return null for every GraphQL request.

    When I spam the server with requests in Altair and I can see null being returned for like 1/10 requests. Can this be an unresolved promise or something?

  12. eweren commented on May 12, 2024

    @eweren

    Having the same as @ayarse for the beta branch. Seems to only occur on media relations,

  13. github-actions commented on Sep 6, 2024

    @github-actions
    Contributor

    This issue has been automatically locked.
    Please open a new issue if this issue persists with any additional detail.

  14. locked as resolved and limited conversation to collaborators on Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions