'GraphQL Query after another service updates table returns as Null
Our front end service receives an id from a prior mutation, then will query our schedules table checking events to see if the download (from another service is finished). The query works fine and returns the proper information before our download generation service interacts and updates the table. It updates the schedule_runs and schedule_run_events, which are separate tables. There is information it updates in the schedule table itself but I'm not querying for these things. After the download service interacts with the table, the same query that was working and returning data, suddenly begins returning null for all the data. The data still exists in the database table. To make things more difficult, this only occurs in the staging environment, development and local work as expected throughout this process.
This is the error I get: "message": "Cannot return null for non-nullable field schedule.id."
What I've Tried: I've tried changing the ApolloClient fetch-policy from no-cache to network-only. Thinking possibly this was an issue (though I assumed that would happen in Dev as well), this did not fix anything. I tried increasing the polling interval where the first query for status from the front end would occur after the download service interacts with the table, and everything still returned null. I tried removing id from the query (though I need that) to see if anything else was a problem, and low and behold, most fields were returning with that error now. I've been assured that it's not the other service by that service's owner, and as I don't really know Python, can't disagree with them.
Additional Info: It's not only the second query, if the second (or third, and so on) query fires before the download service has updated the table with events, then all information returns as expected. It is only after the download service interacts with the table where the query starts returning null (despite the info in the database actually showing the proper information). Basically, the non-nullable fields aren't null, but returning as null in the query after updated for some reason.
Here's the query to check the download status:
query getSchedule($where: schedules_where!) {
schedules(where: $where) {
id
report_name
search_def_id
schedule_runs(last: 1) {
last_event_flag
event_flag {
event_flag
id
flag_description
__typename
}
schedule_run_events(last: 2) {
event_time
event_flag
event_text
__typename
}
__typename
}
__typename
}
}
Variables:
{
"where": {
"search_def_id": {
"equals": 1234
}
}
}
I expect to receive information as follows, and indeed I do initially (with schedule_runs being an empty array due to not being updated yet), this is successful results from Dev environment:
{
"data": {
"schedules": [
{
"id": 00001,
"report_name": "TestResults",
"search_def_id": 1234,
"schedule_runs": [
{
"last_event_flag": "d",
"event_flag": {
"event_flag": "d",
"id": "d",
"flag_description": "done, report is sucessful",
"__typename": "event_flag"
},
"schedule_run_events": [
{
"event_time": "2022-05-06T22:54:18.000Z",
"event_flag": "V",
"event_text": "redacted",
"__typename": "schedule_run_event"
},
{
"event_time": "2022-05-06T22:54:18.000Z",
"event_flag": "d",
"event_text": null,
"__typename": "schedule_run_event"
}
],
"__typename": "schedule_run"
}
],
"__typename": "schedule"
}
]
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
