I have a question which is probably a general GraphQL issue, not necessarily a dgraph issue, but thought maybe someone would be kind to lend a hand.
Take this schema
type Player {
name: String! @id
attributes: [PossessedAttribute] @hasInverse(field:player)
}
type Attribute {
name: String! @id
}
type PossessedAttribute {
id: ID!
player: Player!
attribute: Attribute!
level: Int!
}
For argument’s sake, assume that the Attribute
entity is indeed “entity-worthy”. In other words I simply can’t use its name
identity as is—I need to reference it in the PossessedAttribute
class.
Here’s the mutation to add two Players:
mutation {
addAttribute(
input: [{ name: "strength" }, { name: "dexterity" }, { name: "empathy" }]
) {
attribute {
name
}
}
addPlayer(
input: [
{
name: "John"
attributes: [
{
attribute: { name: "strength" }
level: 5
},
{
attribute: { name: "dexterity" }
level: 10
}
]
},
{
name: "Karen"
attributes: [
{
attribute: { name: "strength" }
level: 6
},
{
attribute: { name: "empathy" }
level: 9
}
]
}
]
) {
player {
name
attributes {
attribute {
name
}
}
}
}
}
Now, searching for Player
s that have a PossessedAttribute
is where I’m fumbling.
query {
queryPlayer {
name
attributes {
attribute(filter: {name: {eq: "dexterity"}}) {
name
}
}
}
}
Yields this:
{
"errors": [
{
"message": "Non-nullable field 'attribute' (type Attribute!) was not present in result from Dgraph. GraphQL error propagation triggered.",
"locations": [
{
"line": 5,
"column": 7
}
],
"path": [
"queryPlayer",
0,
"attributes",
0,
"attribute"
]
},
{
"message": "Non-nullable field 'attribute' (type Attribute!) was not present in result from Dgraph. GraphQL error propagation triggered.",
"locations": [
{
"line": 5,
"column": 7
}
],
"path": [
"queryPlayer",
1,
"attributes",
0,
"attribute"
]
},
{
"message": "Non-nullable field 'attribute' (type Attribute!) was not present in result from Dgraph. GraphQL error propagation triggered.",
"locations": [
{
"line": 5,
"column": 7
}
],
"path": [
"queryPlayer",
1,
"attributes",
1,
"attribute"
]
}
],
"data": {
"queryPlayer": [
{
"name": "John",
"attributes": [
null,
{
"attribute": {
"name": "dexterity"
}
}
]
},
{
"name": "Karen",
"attributes": [
null,
null
]
}
]
}
}
The results are there, but as you can see it’s not that elegant. I realize this just might be a bad schema for the query requirement, or maybe there’s some GraphQL magic that I’ve yet to discover.
Any help appreciated, I’ll definitely buy you a beer at the next Dgraph conference!