GraphQL allows us to define a model of our data on the server using a graph schema, which is the most natural way of describing the stuctures and relationships in our data. To feed our model with data, we define resolvers that use the db's own query language (SQL, NoSQL, or Graph query language, etc) or in-memory objects to resolve queries from the UI against the graph data model we define.
With each components in the UI component tree declaring its own data dependencies, GraphQL/Relay creates a projection of the graph data model that maps to the UI component tree, thus allowing us to have an application-agnostic data layer on the server, while at once giving us and UI-specific projection of the data. The queries from GraphQL server to the database are composed in an efficient manner based on the aggregate data dependencies that are declared by each component in the UI component tree, thus eliminating redundant queries to the database.