Hi guys, I hope you all are doing well. I am working on a project that is based on Azure APIM with a Synthetic GraphQL endpoint. Initially, it worked smoothly with limited data, but after deploying it to production with a larger dataset, it is failing sometimes with an error. I'm sharing the GraphQL schema and relevant information below. Please review:
# Other schema part ...
type AllBranchData {
message: String
data: [Branch!]
}
type Branch {
id: Int
name: String
colorSchema: BranchColorSchema
# Other fields ...
}
type BranchColorSchema {
logo: String
background: String
# Other fields ...
}
# Query:
type Query {
getAllBranches: AllBranchData!
}
# Other schema part ...
Above is the schema snippet which consists of a query and related types. Here we have created a resolver for the query and in this, we are fetching the data from an APIM API. We have another API for the colorSchema field which fetches data from another APIM API. Both APIs are also located in the same account and this is the 3rd GraphQl endpoint.
Now, I am sharing the resolver of the colorSchema field:
<http-data-source>
<http-request>
<set-method>GET</set-method>
<set-url>@($"https://example.net/api/mockBranchData?qtype=branch_color_schema")</set-url>
<set-header name="ocp-apim-subscription-key" exists-action="override">
<value>xyz</value>
</set-header>
</http-request>
<http-response>
<set-body>@{
var body = context.Response.Body.As<JObject>();
var bodyData = body["data"];
return bodyData.ToString();
}</set-body>
</http-response>
</http-data-source>
In this, you can see that this field resolver data source is an API, which sends us a data key in the response and we need only this so we have extracted the data and sent it back from here.
Now, I am sharing the actual error that I am facing when the data size from the main query API is around 500KB (this is not a complete response due to security reasons):
{
"errors": [
{
"message": "Error trying to resolve field 'colorSchema'.",
"locations": [
{
"line": 4,
"column": 4
}
],
"path": ["getAllBranches", "data", 56, "colorSchema"],
"extensions": {
"code": "ARGUMENT",
"codes": ["ARGUMENT"]
}
}
],
"data": {
"getAllBranches": {
"data": [
{
"colorSchema": {
"logo": "test",
"background": "test"
},
"id": 8101
},
{
"colorSchema": {
"logo": "",
"background": "
},
"id": 8103
},
{
"colorSchema": null,
"id": 8104
}
]
}
}
}
In the above error, you can see that sometimes we are getting null instead of object and when I tried with the trace then found the following error:
{
"ClassName": "System.ArgumentException",
"Message": "An item with the same key has already been added.",
"Data": {},
"InnerException": null,
"HelpURL": null,
"StackTraceString": " at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)\r\n at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)\r\n at Microsoft.WindowsAzure.ApiManagement.Proxy.Gateway.Policies.Transform.PipelineMessageExtensions.SetBodyPolicyMessageProcess(IPipelineMessage message, IPipelineContext context, String processedContent, CancellationToken cancellation)\r\n at Microsoft.WindowsAzure.ApiManagement.Proxy.Gateway.Policies.Transform.SetBodyValueHandler.ProcessAsync(IPipelineContext context, CancellationToken cancellation)\r\n at Microsoft.WindowsAzure.ApiManagement.Proxy.Gateway.Policies.PipelineWalker.