Mapping GraphQL to existing dgraph using facets

I am creating a graphql API using typescript, type graphql, and dgraph using dgraphjs as the client. I’m trying to pass input for facet using graphql.

The documentation on facets mutation illustrates this usage:

  "name": "Carol",
  "name|initial": "C",
  "dgraph.type": "Person",
  "friend": {
    "name": "Daryl",
    "friend|close": "yes",
    "dgraph.type": "Person"

However, graphql specification does not allow "friend|close": yes as an input for a mutation because of allowed character in field name.

mutation {
  createPerson(input: {
    name: "Carol"
    "name|initial": "C"
    friends: [{
         "name": "Daryl"
         "friend|close": "yes"

In this case facets will need to be renamed and handled internally in the resolver or service before calling dgraph client to translate graphql to dgraph so that facets are created and not attributes. I have intentionally ignored passing dgraph.type since that is easily handled using default values for graphql input types.

Is there another approach to doing this or is this even a recommended way of tackling this problem?

Facets are not supported yet by GraphQL feature.

Understood. As per graphql specifications it is not and I doubt graphql will implement facets. But since Dgraph supports facets, will these be exposed in the near future through graphql as this?

Yes, there are plans to support Facets in Dgraph’s GraphQL feature. GraphQL won’t support it as it has no meaning in GraphQL context. But we gonna have an approach for this.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.