How do I pass the extra parameters from one subgraph to another subgraph?

Scenario :
We have two subgraphs - cart & products and given the product model as an entity in the cart subgraph below
extend type Product @key(fields: "id") { id: ID! @external }

And then from the cart resolver.js, we are trying to send the Product ID & extra info
ProductLineItem: { product(productLineItem) { return { __typename: "Product", id: productLineItem.productId, siteInfo: { siteId: "INT", locale: "en-NL", currency: "EUR" } }; } },

But we are only getting __typename and id.

We even tried adding siteInfo property to the product entity in cart graphql like below
extend type Product @key(fields: "id") { id: ID! @external siteInfo: SiteInfo! }

but getting the GraphQL validation error,

AggregateGraphQLError [GraphQLError]: The schema is not a valid GraphQL schema.. Caused by: The type of "Product.siteInfo" must be Output Type but got "SiteInfo!", a NonNullType. Here is our request body which is been triggered from supergraph - http://127.0.0.1:4000/.

query ExampleQuery($id: String!, $siteInfo: SiteInfo!) { getCart(id: $id, siteInfo: $siteInfo) { productLineItems { itemId product { id name categoryId } } } }

{ "id": "619d86f8acfdb406bba53e3718", "siteInfo": { "siteId": "INT", "locale": "en-NL", "currency": "EUR" } }

We are using router as a gateway.
Could you please assist in getting the SiteInfo values into the Product subgraph?

1 Like

Could someone please reply if you have any idea about this?

I am currently facing the same problem, have you found a solution to this @Sreekanth ?

Hey there @Sreekanth - apologies for missing your post. @Dangis_Bakutis - I hope this helps you as well!

We have documentation for that particular situation here: Advanced topics on federated entities - Apollo GraphQL Docs

Essentially you’ll need to use the @requires directive and the @external directive together. This will let you have access to those fields you need (siteInfo, in your case) in the resolver function (for the cart field in the Products subgraph).

Note that this requires Fed v2.1. Hope that helps!

Thanks for replying quickly, unfortunately, i misread the issue description provided by @Sreekanth . Mine is a little different.

Feel free to create another post with your specific details!