Hi, still trying to get started with Dgraph and I’m having an issue querying a type, when I have populated it.
I’m using Golang and my code is the following:
Insert user code:
type UserGraphQL struct {
Xid string `json:"xid,omitempty"`
EmailAddress string `json:"emailAddress,omitempty"`
HashedPassword string `json:"hashedPassword,omitempty"`
FirstName string `json:"firstName,omitempty"`
LastName string `json:"lastName,omitempty"`
CompanyName string `json:"companyName,omitempty"`
Role string `json:"role,omitempty"`
LastLogin *time.Time `json:"lastLogin,omitempty"`
DType []string `json:"dgraph.type,omitempty"`
}
func (f *Obj) insertUser(user UserMySQL) {
ctx := context.Background()
txn := f.Dg.NewTxn()
defer txn.Discard(ctx)
u := UserGraphQL{
Xid: user.Id,
EmailAddress: user.EmailAddress,
HashedPassword: user.HashedPassword,
FirstName: user.FirstName,
LastName: user.LastName,
CompanyName: user.CompanyName,
Role: user.Role,
LastLogin: user.LastLogin,
DType: []string{"User"},
}
ub, err := json.Marshal(u)
if err != nil {
fmt.Println("problem marshalling json")
fmt.Println(err)
}
mu := &api.Mutation{
CommitNow: true,
SetJson: ub,
}
res, err := txn.Mutate(ctx, mu)
if err != nil {
fmt.Println("failed to mutate")
fmt.Println(err)
}
fmt.Println(res)
fmt.Println("------------")
}
My Schema:
type User {
id: ID!
xid: String! @search(by: [exact])
emailAddress: String! @search(by: [exact])
hashedPassword: String!
firstName: String!
lastName: String!
companyName: String
role: Role
lastLogin: DateTime
createdAt: DateTime!
updatedAt: DateTime
deletedAt: DateTime
}
The query:
query User {
queryUser {
id
firstName
lastName
}
}
The result:
"errors": [
{
"message": "Non-nullable field 'firstName' (type String!) was not present in result from Dgraph. GraphQL error propagation triggered.",
"locations": [
{
"line": 4,
"column": 5
}
],
"path": [
"queryUser",
0,
"firstName"
]
},
One side note, if I just query for the id. I get no errors, why would this be?
Have I missing something along the way? Would appreciate if someone can point me in the right direction.
Thanks