Search code examples
graphqlreact-relay

Do I need to always pull the id field when using react relay


I am curious if I have to always include the id field when making queries to a relay graph QL server?

For example:

users_connection {
    edges {
      node {
        id
        userId
        firstName
      }
    }
}

I sometime use the id field as a component key when looping on results, but generally speaking I don't use it. Does relay use this under the hood on the client to perform caching?

I have tested removing this from my queries and haven't notice a difference to my app.


Solution

  • relay-compiler adds it automatically to any type that has an id field even if it hasn't been explicitly requested. But you still need to add it if you actually use it in your own code.