Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Custom resolvers #231

Open
intellix opened this issue Jun 14, 2019 · 3 comments
Open

Feature: Custom resolvers #231

intellix opened this issue Jun 14, 2019 · 3 comments

Comments

@intellix
Copy link
Contributor

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.

@birkir
Copy link
Owner

birkir commented Jun 14, 2019

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
Copy link
Owner

birkir commented Jun 14, 2019

Or are you talking on a PrimeField level?

@intellix
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants