Hi,
I’ve been playing around with Dgraph, and Go. I’ve got the following schema:
age: int .
name: string @index(exact) .
price: int .
buyerID: uid .
device: string .
id: string @index(exact, term) .
pid: string @index(exact) .
tid: string @index(exact) .
ip: string .
productIDs: [uid] .
<dgraph.drop.op>: string .
<dgraph.graphql.p_query>: string @index(sha256) .
<dgraph.graphql.schema>: string .
<dgraph.graphql.xid>: string @index(exact) @upsert .
type <Buyer> {
id: string
name: string
age: int
}
type <Product> {
pid: string
name: string
price: int
}
type Transaction {
tid: string
buyerID: uid
ip: string
device: string
productIDs: [Person]
}
type <dgraph.graphql> {
dgraph.graphql.schema
dgraph.graphql.xid
}
type <dgraph.graphql.persisted_query> {
dgraph.graphql.p_query
}`
Which, after creating my connection I send in an api.Operation altering the database. Then, I obtain certain info corresponding to the following structs in Go
type Buyer struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Age int `json:"age,omitempty"`
Dtype []string `json:"dgraph.type,omitempty"`
}
type Product struct {
PID string `json:"pid,omitempty"`
Name string `json:"name,omitempty"`
Price int `json:"price,omitempty"`
Dtype []string `json:"dgraph.type,omitempty"`
}
type Transaction struct {
TID string `json:"tid,omitempty"`
BuyerID Buyer `json:"buyer,omitempty"`
IP string `json:"ip,omitempty"`
Device string `json:"device,omitempty"`
ProductIDs []Product `json:"products,omitempty"`
Dtype []string `json:"dgraph.type,omitempty"`
}
No issue thus far, I run mutations adding info for both Buyer and Product adding. However, when looking to add transactions, my “input” has the ID but not the uid assigned by Dgraph. When trying to get the Buyer which corresponds to the specific Transaction, using this queryWithVars:
q := `query myQuery($a: string) {
buyer(func: eq(id, $a)) {
uid
id
name
age
}
}
`
the response.Json is just an array of bytes which I cannot comprehend. Running the same query from the Ratel UI does bring the expected JSON object. Is there any way to change the response, or is this some sort of error. Furthermore, the error obtained from the query is nil. Any ideas? At this point I’ve got no clue how to keep using dgo and get the Buyer.