GraphQL custom resolver payload schema

Hi MongoDB community!

I’m having trouble formatting the payload type for a custom GraphQL resolver.

I’m wanting to implement a search query, and return matching documents to a given search. I’ve got the function all set up, but I cannot figure out how to re-use existing schema types from my MongoDB Atlas schema as the payload type.

I want to send an array of documents as the payload, and this was what I came up with:

    {
  "type": "object",
  "title": "SearchResults",
  "properties": {
    "artists": {
      "type": "array",
      "description": "Returns the artist documents from this search",
      "items": {
        "type": "object",
        "$ref": "#/realm/mongodb-atlas/music/artists"
      }
    }
  }
}

I’m getting an error when using $ref, and I’m also not sure if the $ref schema link is right. Basically, the artists schema already exists as defined in Realm rules, and I just want to reuse this as the payload type.

Will I just have to redefine the document schema in this payload, or can I access this already-existing schema type?

Thank you so much! Please let me know if this question is clear or if I could add anything else :slight_smile:

Hi Pierre,

At the moment you will need to re-define the schema type for artists in your payload type. However, we are actually planning on releasing the ability to reuse schema types this month (likely in the next week or so). Hope that helps.

3 Likes

@Pierre_Rodgers, this should be available to try out in the Custom Resolver UI now. You can also read more about it in our docs.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.