# What are the ramifications of differing entity definitions?

**URL:** <https://community.apollographql.com/t/what-are-the-ramifications-of-differing-entity-definitions/6368>\
**Category:** Server\
**Tags:** server, federation\
**Created:** [June 15, 2023, 5:03pm UTC](https://community.apollographql.com/t/what-are-the-ramifications-of-differing-entity-definitions/6368 "2023-06-15T17:03:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick\_Hansen](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/patrick_hansen/32/3230_2.png) [@Patrick\_Hansen](https://community.apollographql.com/u/Patrick_Hansen)\
**Post date:** [June 15, 2023, 5:03pm UTC](https://community.apollographql.com/t/what-are-the-ramifications-of-differing-entity-definitions/6368/1 "2023-06-15T17:03:46Z")

</div>

I’m working to migrate from one system to another, and as such my entities have two primary keys, one is a reference to the new system, and the second is a reference to the old system.

```auto
type User @key(fields: "oldId") @key(fields: "newId") {
  oldId: ID!
  newId: ID!
}

```

Some of our subgraphs are able to resolve based on only the old id, others off of only the new id, and others off of either. I was under the impression that the entity definition had to match across all subgraphs, but I’ve seen now that that is not the case. Subgraphs can disagree about which fields are keys.

So my question is: what are the ramifications of subgraphs disagreeing? Will I run into problems if one subgraph declares `@key(fields: "oldId")` and another doesn’t declare that key? Can a subgraph resolve out entities with a different subgraphs key if it doesn’t know that it considers that a key?

For instance if I declare

```auto
type User @key(fields: "oldId") {
  oldId: ID!
  newId: ID!
}

```

and then resolve

```auto
 return {
   __typename: "User",
  newId: "SomeUUID"
 } 

```

Is that legal? Will the next subgraph in the query plan be able to resolve off of that if it declares `newId` as a key? Should I _always_ resolve out the id that I know about?

What happens if I query for a field that `@requires(fields: "oldId")` but the initial subgraph didn’t resolve it? Will it hit some other subgraph to find it?

---

<div class="post-metadata">

**Author:** ![dkuc](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/dkuc/32/2892_2.png) [@dkuc](https://community.apollographql.com/u/dkuc)\
**Post date:** [June 16, 2023, 8:44pm UTC](https://community.apollographql.com/t/what-are-the-ramifications-of-differing-entity-definitions/6368/2 "2023-06-16T20:44:43Z")

</div>

Hello 👋  
As long as there exists some execution path to resolve all the requested data, it is perfectly legal to have different entity `@key` definitions across subgraphs. `@key` information is used by the router/gateway to come up with an optimal [query plan](https://www.apollographql.com/docs/federation/query-plans/) on how to fetch all the requested data.

i.e. given subgraph A

```auto
type Query {
  foo(id: ID!): Foo
}

type Foo @key(fields: "id") {
  id: ID!
  a: String
  # some other fields here but no "oldId"
}

```

and a subgraph B

```auto
type Foo @key(fields: "oldId") {
  oldId: ID!
  b: String
  # some other fields here but no "id"
}

```

It is not possible to resolve the following query as there is no way to reach `b` field with only information from the `A` subgraph

```auto
{
  foo(id: "123") {
    a
    b
  }
}

```

We can make it valid if we add another subgraph C that defines both keys (so the query plan would result in calls to A → C → B).

```auto
type Foo @key(fields: "id") @key(fields: "oldId") {
  id: ID!
  oldId: ID!
  c: String
  # other fields
}

```

I’d recommend to run some of the test queries against your supergraph and check out the generated query plans to see exactly what is happening there. See [query plan docs](https://www.apollographql.com/docs/federation/query-plans/) for more details.

---

<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/what-are-the-ramifications-of-differing-entity-definitions/6368/3 "2025-02-06T20:48:45Z")

</div>


