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

Documentation: a common federation use case for Child Field type #325

Open
dwvd opened this issue May 19, 2023 · 0 comments
Open

Documentation: a common federation use case for Child Field type #325

dwvd opened this issue May 19, 2023 · 0 comments

Comments

@dwvd
Copy link

dwvd commented May 19, 2023

I have gone through the documentation of Show and Reviews and understand that it could be federated with following code.


@DgsEntityFetcher(name = "Show")
    public Show movie(Map<String, Object> values) {
        return new Show((String) values.get("id"), null);
    }

    @DgsData(parentType = "Show", field = "reviews")
    public List<Review> reviewsFetcher(DgsDataFetchingEnvironment dataFetchingEnvironment)  {
        Show show = dataFetchingEnvironment.getSource();
        return reviews.get(show.getId());
    }

But my problem is that not enough documentation is provided to understand how leverage the federation if entity is child element like below schema:-

type User
{
    id:String
    name :String
    product:Product
}
type Product @key(fields: "id") @extends{
id : String @external
}

As you see type product is part of User and I am trying to make it work with following code, but it is not working. I tried to implement this in multiple ways but it is not working. If you have any sample code or documentation that would be helpful.

@DgsEntityFetcher(name = "product")
    public Product getProduct(Map<String, Object> values) {
        return new Product((String) values.get("id"));
    }

    @DgsData(parentType = "Query", field = "getUser")
    public DataFetcherResult<Object> getProduct(@InputArgument UserRequest userRequest, DataFetchingEnvironment dataFetchingEnvironment) {
        log.info(userRequest +":-"+ dataFetchingEnvironment.toString());
        UserResponse userResponse = userService.search(userRequest);
        Product product = dataFetchingEnvironment.getSource();
        log.info("product: " + product);
//        product.getId(userResponse.get);

        return DataFetcherResult.newResult().data(userResponse).build();
    }
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

1 participant