prime icon indicating copy to clipboard operation
prime copied to clipboard

Feature: Custom resolvers

Open intellix opened this issue 5 years ago • 3 comments

Noticed that I hadn't wrote about this yet but it's something I really want from GraphCMS that's missing currently.

It'd be nice to be able to define custom resolvers when fetching data. When you're creating a GQL server you have access to the code so you can write custom resolver logic for individual fields as you need. Since everything is defined via a CMS here you lose out on that power.

Imagine you've got some tiles and someone defined a bunch of images in each one:

{
  tiles: [
    {
      images: [1.jpg, 2.jpg],
      columns: 2
    },
    {
      images: [1.jpg, 2.jpg],
      columns: 1
    },
    {
      images: [1.jpg, 2.jpg],
      columns: 1
    },
    {
      images: [1.jpg, 2.jpg],
      columns: 2
    },
  ]
}

When querying you want to grab the correct image based on the columns value. In the server it looks something like:

resolver(tile: Tile) {
  return tile.images[tile.columns];
}

But without the ability to define a custom resolver you have to overfetch data and select the correct one on the frontend after wasting bandwidth.

intellix avatar Jun 14 '19 04:06 intellix

With graphql-modules you can do this very easily.

https://graphql-modules.com/docs/introduction/resolvers-composition

But it's not very Prime orientated. We could support custom resolvers for fields, but that would take massive refactoring and restructure to do.

birkir avatar Jun 14 '19 12:06 birkir

Or are you talking on a PrimeField level?

birkir avatar Jun 14 '19 12:06 birkir

Yeah on the PrimeField level. I guess another name is "Computed fields". Because when using a CMS you don't really have access to the code level anymore but may still want to have a simple function/custom resolver... I've no idea what that would look like to be honest but I just know I'm missing it currently and it's on the GraphCMS road map

intellix avatar Jun 16 '19 02:06 intellix