Handling graphql requests that include items the user can no longer access

default discord avatar
devperson
7 months ago
4

In our platform we have a favourites collection that's a many to many relationship between content items and users, however there are scenarios whereby users could favourite a content post and then subsequently not have access to that content item, meaning we get the following error when querying via gql



Cannot return null for non-nullable field Favourite.content

I am wondering whether there is a good way of handing this? Ideally without modifying the favourites table, as they could regain access to that content in the future



Anyone have any ideas on this?



Not been able to figure this one out yet, anyone got any ideas?

  • discord user avatar
    jesschow
    Payload Team
    6 months ago

    hi @devperson - can you update

    favourite.content

    to be a nullable field? can you show where you are defining the schema?



    Also, this page is helpful:

    https://graphql.wtf/episodes/42-graphql-nullability
  • default discord avatar
    devperson
    5 months ago

    It was a graphql schema generated by payload, is there a way to mark a field as nullable?

  • discord user avatar
    jesschow
    Payload Team
    2 months ago

    Sorry for the delay - do you still need help here @devperson?

  • default discord avatar
    devperson
    2 months ago

    not urgently, we worked around this by making a custom graphql endpoint rather than the default payload generated endpoint to handle this

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.