Support for Relay Modern

As per Relay’s GraphQL server specification:

The three core assumptions that Relay makes about a GraphQL server are that it provides:

  1. A mechanism for refetching an object.
  2. A description of how to page through connections.
  3. Structure around mutations to make them predictable.

Assumption-1

It requires the following query to be supported by the GraphQL server:

type Query {
   node(id: ID!): Node
}

At present, Dgraph doesn’t enforce a Node interface on the user-defined types. User can choose to define their own Node interface, but that would generate the following query:

type Query {
   getNode(id: ID!): Node
}

Note that it is getNode, and not node although the behavior of these two is the same.

Assumption-2

It strictly requires the cursor-based pagination model described here: GraphQL Cursor Connections Specification
Dgraph’s GraphQL API doesn’t support that model at present. It supports the first, offset based model as in this example:

type Message { ... }

type Query {
   queryMessage(filter: MessageFilter, order: MessageOrder, first: Int, offset: Int): [Message]
}

Also, that model requires nested object lists to be handled with a level of indirection as edges to fit the PageInfo objects. That requires a full rework of how the GraphQL API is generated by Dgraph.

Assumption-3

This is satisfied in Dgraph’s current GraphQL API. No changes required here.

TL;DR

At present, Dgraph generates a free-form GraphQL API, which can be used easily with GraphQL clients like Apollo.
In order to support the Relay framework, it requires a complete rework.
So, a nice idea would be to support two endpoints that serve GraphQL in different forms:

  • /graphql: This is the current endpoint, which serves the free-form GraphQL API.
  • /graphql-relay: A new endpoint to support a GraphQL API that respects the constraints laid down by relay.

GIven that relay is a popular framework, we should be supporting this. But, also given that our current GraphQL API is under fast development as of now, I would not advocate having that support right now. It would be better that once we have a stable GraphQL API, then only we should consider adding support for relay.

So, yes it will receive support, but I don’t expect that to be happening very soon.

Thanks

cc: @vvbalaji

4 Likes