-
Notifications
You must be signed in to change notification settings - Fork 359
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Batching type resolution #1867
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
Comments
Hello, thank you for reaching out, as you well mentioned, we decided to refactor the federated type resolution to match with other federation implementations, you can refer to the federation section of the documentation to check how to use DataLoaders, the only constrain is that you will have to use the FederatedTypePromiseResolver, |
Hey @samuelAndalon, thanks for the response. I'm not sure I fully understood. How would I use |
// This service does not own the "Product" type but is extending it with new fields
@KeyDirective(fields = FieldSet("id"))
@ExtendsDirective
class Product(@ExternalDirective val id: String) {
fun newField(): String = getNewFieldByProductId(id)
}
// This is how the "Product" class is created from the "_entities" query using promise resolver
class ProductResolver : FederatedTypePromiseResolver<Product> {
override val typeName: String = "Product"
override fun resolve(
environment: DataFetchingEnvironment,
representation: Map<String, Any>
): CompletableFuture<Product?> {
val id = representation["id"]?.toString()
// use dataloader to resolve Product by id
return environment.getDataLoader<String, Product?>("ProductDataLoader").load(id)
}
}
@Service
class ProductDataLoader : KotlinDataLoader<ID, User> {
override val dataLoaderName = "ProductDataLoader"
override fun getDataLoader(graphQLContext: GraphQLContext) =
DataLoaderFactory.newDataLoader<ID, User> { ids ->
// call your DB here
}
}
|
please let me know if you need more help, i just copy-pasted what is in the documentation |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
With #1514 the interface for type resolvers has changed to pass a single
representation
instead of multiplerepresentations
. This was done to be more streamlined with other subgraph libraries which makes sense.However, it comes with the disadvantage that type resolution can not be batched anymore. In our case, we would do a batch load from DynamoDB when receiving
representations
as that is more efficient than running a query per requested type. With the current interface this is not possible.What would be the way to reproduce such a logic? I have asked on Slack and a data loader was suggested. From my understanding that does not mean the data loader will automatically be integrated with the type resolver, so I'm guessing some other gluing logic is needed.
Maybe some documentation or helpers in
graphql-kotlin
could be helpful to make the migration to v7 a little easier?The text was updated successfully, but these errors were encountered: