# Using \`@key\` in one subgraph and \`@shareable\` in another

**URL:** <https://community.apollographql.com/t/using-key-in-one-subgraph-and-shareable-in-another/6706>\
**Category:** Schema Design\
**Tags:** federation\
**Created:** [September 12, 2023, 12:03pm UTC](https://community.apollographql.com/t/using-key-in-one-subgraph-and-shareable-in-another/6706 "2023-09-12T12:03:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bernardo\_Amorim](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/bernardo_amorim/32/4576_2.png) [@Bernardo\_Amorim](https://community.apollographql.com/u/Bernardo_Amorim)\
**Post date:** [September 12, 2023, 12:03pm UTC](https://community.apollographql.com/t/using-key-in-one-subgraph-and-shareable-in-another/6706/1 "2023-09-12T12:03:12Z")

</div>

Suppose that there are two subgraphs, `sub1` and `sub2`, defined for an Apollo Federation supergraph of version 2.0 or higher.  
`sub1`’s schema contains:

```auto
#...
type MyType @shareable {
   idField: ID
   myField: String
}
#...

```

`sub2`’s schema contains:

```auto
#...
type MyType @key(fields:"idField") {
   idField: ID
   myField: String
}
#...

```

Is that a valid combination, or will it generate a schema composition error?

---

<div class="post-metadata">

**Author:** ![shanemyrick](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/shanemyrick/32/5474_2.png) [@shanemyrick](https://community.apollographql.com/u/shanemyrick)\
**Post date:** [September 12, 2023, 9:02pm UTC](https://community.apollographql.com/t/using-key-in-one-subgraph-and-shareable-in-another/6706/2 "2023-09-12T21:02:13Z")

</div>

This is specific to Fed 2, but this is not a valid combination. `@shareable` and `@key` should not exist on the same type. They can be used for fields and other types, but not for Entities.

To understand more, see our [What’s new in Federation 2 guide](https://www.apollographql.com/docs/federation/federation-2/new-in-federation-2), but the short answer here is you need to first identity the type as an Entity using the `@key` directive. If the type can not be identified by some id or combination of fields with `@key`, then you should use `@shareable` instead.

But in your case you do have a key. In Fed 2 the fields marked as keys are automatically considered sharedable, all other fields that are shared across subgraph definitions need to be marked as shareable

```graphql
 # Subgraph 1
type MyType @key(fields: "idField") {
   idField: ID
   myField: String @shareable
   foo: String
}

```

```graphql
 # Subgraph 2
type MyType @key(fields: "idField") {
   idField: ID
   myField: String @shareable
   bar: String
}

```

---

<div class="post-metadata">

**Author:** ![Justin\_Gonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/justin_gonzalez/32/5359_2.png) [@Justin\_Gonzalez](https://community.apollographql.com/u/Justin_Gonzalez)\
**Post date:** [February 6, 2025, 8:48pm UTC](https://community.apollographql.com/t/using-key-in-one-subgraph-and-shareable-in-another/6706/3 "2025-02-06T20:48:25Z")

</div>


