Enable `_label` field to specify its GraphQL dependencies
See original GitHub issueGiven a User
list:
keystone.createList('User', {
fields: {
name: { type: Text },
posts: { type: Relationship, many: true }
}
});
We want to display the label as <name> (3 posts)
.
As it stands today, the labelResolver
option doesn’t expose any way to get the number of posts:
keystone.createList('User', {
fields: {
name: { type: Text },
posts: { type: Relationship, many: true }
},
labelResolver: item => {
// This will fail because `item._postsMeta` is not set
return `${item.name} (${item._postsMeta.count} posts)`;
}
});
Ideally, we’d be able to specify a query snippet which is injected into the item query, something like:
keystone.createList('User', {
fields: {
name: { type: Text },
posts: { type: Relationship, many: true }
},
labelFragment: `
_postsMeta {
count
}
`,
labelResolver: item => {
// This will now succeed!
return `${item.name} (${item._postsMeta.count} posts)`;
}
});
Gotchyas
- Need to de-dupe the
labelFragment
from any incoming query - Need to consider how this will impact Virtual Fields (#1117)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Using GraphQL with Python – A Complete Guide
Set up a Python web server with Flask; Use the Ariadne library to implement GraphQL; Compose a GraphQL Schema; Perform queries and mutations ......
Read more >Objects - GitHub Docs
About objects. Objects in GraphQL represent the resources you can access. An object can contain a list of fields, which are specifically typed....
Read more >GraphQL API style guide - GitLab Docs
GraphQL API style guide. This document outlines the style guide for the GitLab GraphQL API. How GitLab implements GraphQL. We use the GraphQL...
Read more >Introduction to New Relic NerdGraph, our GraphQL API
You can use NerdGraph to return and configure a wide range of data. One way to see what NerdGraph can do is to...
Read more >Instrumentation (Tracing, Metrics) - DGS Framework
GraphQL Java supports the concept of instrumentation . ... but you can turn it off by setting graphql.tracing.enabled=false in your ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For additional context I’m currently looking into the actual implementation of this this. The main focus will be on getting the desired behaviour for
_label
. It is expected that this will inform the full implementation of #1117, but if it turns out the the delta from this specific case to the general case is tiny then I’ll do it all in one hit.I imagine that, post #1117, we could reimplement the
_label
special field as a built-in virtual field that is automatically added to every list.(background for anyone reading that and wondering “why” without context: the Admin UI needs to be able to make an assumption on how to render an item when it’s displayed in various contexts. that’s what we use the built-in
_label
field for. it’s a bit of a kludge and more opinionated than most things we do in keystone, but simplifies what would otherwise be a large amount of required configuration. I think I’m open to discussing this down the track if there’s a valid use-case for not having it?)