I’m experiencing some weird behaviour when using @custom directives fields in my Dgraph GraphQL schema.
I encountered this first on my locally running Dgraph instance inside Docker, but was able to replicate the issue on Slash GraphQL as well.
The example I came up to replicate the problem is as follows:
Schema:
type ItemType {
typeId: String! @id
name: String
# The MarketStats would usually be a separate GraphQL server, but the bug can be reproduced with a single server as well.
marketStats: MarketStatsR @custom(http: {
url: "<url to my slash graphql instance>",
method: POST,
graphql: "query($typeId:String!) { getMarketStats(typeId: $typeId) }",
skipIntrospection: true,
})
}
type Blueprint {
blueprintId: String! @id
# Two variants to retrieve the blueprint's products, to better demonstrate the bug
shallowProducts: [ItemType]
deepProducts: [BlueprintProduct]
}
type BlueprintProduct {
itemType: ItemType
amount: Int
}
type MarketStats {
typeId: String! @id
price: Float
}
type MarketStatsR @remote {
typeId: String
price: Float
}
Basically I have Blueprints
that produce Items
. The Items
have prices that are dynamically fetched by a different GraphQL server (which in this example is actually the same server, but the query is still sent via HTTP, so this still works).
The IDs all come from an external source and as such as decorated with @id
.
I then added some data to the database:
mutation AddExampleData {
addItemType(input: {
typeId: "1"
name: "Test"
}) { numUids }
addMarketStats(input: {
typeId: "1"
price: 9.99
}) { numUids }
addBlueprint(input: {
blueprintId: "bp1"
shallowProducts: [{ typeId: "1" }]
deepProducts: [{
amount: 1
itemType: { typeId: "1" }
}]
}) { numUids }
}
The following query works fine:
query WorkingQuery {
getItemType(typeId:"1") {
typeId
marketStats {
price
}
}
getBlueprint(blueprintId:"bp1") {
shallowProducts {
typeId
marketStats { price }
}
}
}
which returns (as expected):
{
"data": {
"getItemType": {
"typeId": "1",
"marketStats": { "price": 9.99 }
},
"getBlueprint": {
"shallowProducts": [
{
"typeId": "1",
"marketStats": { "price": 9.99 }
}
]
}
}
}
However, when trying to access the marketStats through the deepProducts
edge:
query BrokenQuery {
getBlueprint(blueprintId:"bp1") {
deepProducts {
itemType {
typeId
marketStats { price }
}
}
}
}
What I expected to be returned:
{
"data": { "getBlueprint": { "deepProducts": [{
"itemType": {
"typeId": "1",
"marketStats": { "price": 9.99 }
}
}] } }
}
What is actually returned:
{
"data": { "getBlueprint": { "deepProducts": [{
"itemType": {
"typeId": "1",
"marketStats": null
}
}] } }
}
Am I doing something wrong, or is this indeed a Bug in Dgraph?
Any help would be greatly appreciated.