Dgo mutate inserts all null values (id gets generated)

I’m trying to insert data into Dgraph using Dgo - when I mutate, all the values that are supposed to get inserted are null:

{
  "data": {
    "queryEsop": [
      {
        "id": "0x4e28",
        "name": null,
        "type": null,
        "version": null,
        "description": null,
        "service_endpoint": null
      }
    ]
  }
}

The Go struct:

type TestInput struct {
		Name            string `json:"name,omitempty"`
		Description     string `json:"description,omitempty"`
		Type            string `json:"type,omitempty"`
		Version         string `json:"version,omitempty"`
		ServiceEndpoint string `json:"service_endpoint,omitempty"`
		DgraphType      string `json:"dgraph.type,omitempty"`
	}

The marshalled Json byte array, printed as a string shows:

"{\"name\":\"The Name\",\"description\":\"The Description\",\"type\":\"The Type\",\"version\":\"The Version\",\"service_endpoint\":\"The Endpoint\",\"dgraph.type\":\"Esop\"}"

The schema

type Esop {
  id: ID!
  name: String @search(by: [regexp])
  type: String
  version: String
  description: String
  service_endpoint: String

  hasWorkflows: LeaveApplication @hasInverse(field: isWorkflowOf)
}

I’m using the latest Dgo packages with the latest version of Dgraph Docker images (for zero and alpha)

"github.com/dgraph-io/dgo/v210"
"github.com/dgraph-io/dgo/v210/protos/api"

Using DQL and GraphQL together will cause problems if you don’t do it correctly. You need to map your predicates.

Ok, I’ve finally got it to work. Thanks.

For anyone else encountering the same issue - when you specify a GraphQL schema, a DQL schema is automatically generated.

The DQL mutation requires a JSON that is similar to the GraphQL schema, except it has “dgraph.type” (the value is the type of the entity) and every attribute requires the entity type to be prepended.

type Esop struct {
	Name            string `json:"name,omitempty"`
	Description     string `json:"description,omitempty"`
	Version         string `json:"version,omitempty"`
	ServiceEndpoint string `json:"service_endpoint,omitempty"`
	DgraphType      string `json:"dgraph.type,omitempty"`
}

type EsopDQL struct {
	Name            string `json:"Esop.name,omitempty"`
	Description     string `json:"Esop.description,omitempty"`
	Version         string `json:"Esop.version,omitempty"`
	ServiceEndpoint string `json:"Esop.service_endpoint,omitempty"`
	DgraphType      string `json:"dgraph.type,omitempty"`
}

Mapping my JSON from the top (Esop) to (EsopDQL) worked.

Thanks.