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

RFC: Support multiple keys on a node #30

Open
mxstbr opened this issue Dec 1, 2023 · 0 comments
Open

RFC: Support multiple keys on a node #30

mxstbr opened this issue Dec 1, 2023 · 0 comments
Labels
RFC A discussion about a future feature

Comments

@mxstbr
Copy link
Member

mxstbr commented Dec 1, 2023

Summary

Many nodes are uniquely identifiable by more than one key. Common example: BlogPost.id and BlogPost.slug.

Proposed Solution

First idea:

const BlogPostNode = node({
  keys: ['id', 'slug'], // Array
  // keys arg is an array of { id?: string, slug?: string }
  // if possible, even better if it's a union { id: string } | { slug: string }
  load: async (keys) => {
    return keys.map(({ id, slug }) => id ? getById(id) : getBySlug(slug) )
  }
})

addNodeFields(User, (t) => ({
  highlightedBlogPost: t.field({
    type: BlogPostNode,
    // Can return either { id: string } | { slug: string }
    resolve: (parent) => ({ slug: parent.highlightedBlogPostSlug })
  )}
}))
@JoviDeCroock JoviDeCroock added the RFC A discussion about a future feature label Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC A discussion about a future feature
Projects
None yet
Development

No branches or pull requests

2 participants