GraphQLSwift / Graphiti

The Swift GraphQL Schema framework for macOS and Linux
MIT License
531 stars 67 forks source link

Federation N+1 query problem #101

Closed ZirgVoice closed 1 year ago

ZirgVoice commented 1 year ago

In schema in key i can't return an array

        Type(ProductUser.self, as: "User") {
            Field("email", at: \.email)
            Field("name", at: \.name)
            Field("totalProductsCreated", at: \.totalProductsCreated)
            Field("yearsOfEmployment", at: \.yearsOfEmployment)
            Field("averageProductsCreatedPerYear", at: \.averageProductsCreatedPerYear)
        }.key(at: ProductResolver.getUsers) {
            Argument("email", at: \.email)
        }

This is necessary to solve the N+1 problem

Now I'm using graphql-transform-federation it has batchDelegateToSchema from graphql-tools, I tried to do something similar via DataLoader but I can't return the result because it's an array

NeedleInAJayStack commented 1 year ago

Why weren't you able to use DataLoader to address this? You can definitely create a resolver function that uses a DataLoader that returns a single object (not an array), thereby addressing the N+1 problem.

ZirgVoice commented 1 year ago

Oh right, I forgot about that, thanks!