Getting other subgraphs input types

Hi everyone, first time posting here as I didnt know there is a forum dedicated for apollo :slight_smile:

So long story short, I am wondering if let’s say subgraph A is for Contact and subgraph B is for Account, and let’s say a contact will have an associated account to it, so when a client is trying to search for contact(s) that is under Account X, we use the query

{
  Contacts(filters:[
    { Account: { Name: { $eq: {'X'} }}}
  ]) {
     Id
  }
}

Now, the question is, Account has other fields (eg. CreatedDate), do I need to add all of those input types to Contact subgraph or is there a way that gateway will automagically found those?

Hello @tim-t, welcome to the community.

With federation, you should be able to extend a type (that is defined in a subgraph) in a different subgraph.

Here’s how you would do it:

*//Subgraph A:*

type Account {
  id: String
}
*//Subgraph B:*

type Contract {
  id: String
  account: Account
}

extend type Account {
   createdDate: String #field Subgraph B adds
   anotherField: String #field Subgraph B adds
}

When the final schema is stiched, here is what the types would look like:

type Account {
  id: String
  createdDate: String
  newField: String
}

type Contract {
  id: String
  account: Account
}

So, the client should be able to query for all the fields on the Account type.

Check out the Federated Schema docs for more details.

Hi Kartik,

Thanks for the reply. Yeah, I m ok with type, but will it work for input?

1 Like

Yes, you should be able to extend the input types similar to the entity types.

If Account is a input type defined in Subgraph A, you can extend it in subgraph B:

*//Subgraph B:*
extend input Account {
   createdDate: String #field Subgraph B adds
   anotherField: String #field Subgraph B adds
}