0

I have a Sanity CMS with some data and a Gatsby frontend which fetches the data from Sanity via GraphQL. This works well in most cases but I would need a custom endpoint which gives back a document based on some arbitrary logic.

I've tried the custom plugins but I couldn't figure out how I can publish a new endpoint with them.

laszlo_kiss
  • 436
  • 4
  • 5

1 Answers1

0

The most lightweight solution is probably to install the Dashboard tool to you Studio. Briefly, what you do is

  1. Install the Dashboard tool to you Studio:
sanity install @sanity/dashboard
  1. Create a src/dashboardConfig.js file and make it contain the following:
export default {
  widgets: [
    {
      name: 'project-info'
    },
    {
      name: 'project-users'
    }
  ]
}
  1. Let your Studio know that you've implemented your own dashboard config by appending this to your sanity.json file:
{
  "implements": "part:@sanity/dashboard/config", 
  "path": "./dashboardConfig.js" 
}

Congrats, you now have a Dashboard with two Widgets in your Studio! Confirm this by running it locally and point your browser to http://localhost:3333/dashboard.

Next, you'll want to create your own widget. For a flying start, grab a skinny example which already works

sanity init plugin https://github.com/sanity-io/plugin-template-dashboard-widget-cats/archive/master.zip

The above cats Widget will be installed to the /plugins folder of your Studio. Go ahead and edit it (it's basically just a React component) to get the results you want. Or use it as a guideline for how to create your own widget.

Hope this helps you out!

thomax
  • 9,213
  • 3
  • 49
  • 68