Nodes is not working
@kapa.ai Ok why am I getting this error:
TypeError: Cannot read properties of undefined (reading 'nodes') at getList
If this is the query:
export const OBD_GET_HISTORY = gql
query OBDHistory(
$filter: OBDDataFilter!
$sorting: [OBDDataSort!]!
$paging: OffsetPaging!) {
historicalObdData(filter: $filter, sorting: $sorting, paging: $paging) {
totalCount
nodes {
id
driver
{
id
name
}
timestamp
rpm
speed
coolantTemp
throttlePosition
intakeAirTemp
fuelLevel
engineLoad
mafSensor
runTime
distanceMilOn
commandedEgr
barometricPressure
}
}
}
;
And this is the refine code:
const { data: responseData, isLoading: locationLoading, failureReason: failureReason } = useList<GetFieldsFromList<ObdHistoryQuery>>({
resource: "obd_data",
filters: [
{
field: "vehicle",
value: vehicleId,
operator: "eq",
}
],
meta: {
gqlQuery: OBD_GET_HISTORY,
},
queryOptions: {
enabled: true,
},
});
And on the network this is the response:
{
"data": {
"historicalObdData": {
"totalCount": 149,
"nodes": [
{
"id": "68",
"driver": {
"id": "2",
"name": "Leroy"
},
"timestamp": "2024-09-07 21:15:28.317170+00:00",
"rpm": 6095,
"speed": 76,
"coolantTemp": 4.0,
"throttlePosition": 68.23529411764706,
...8 Replies
Hi @Valugar. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
It looks like you're encountering an issue where the
nodes
property is undefined in the getList
method. This issue might be related to how the getList
method is handling the response from your GraphQL query.
Based on the knowledge sources, there are a few things to check and consider:
1. Response Format: Ensure that the response format from your GraphQL query matches what the getList
method expects. The getList
method typically expects a structure where the data is directly accessible. In your case, it should be able to access nodes
directly from the response.
2. Custom Data Provider: If the default behavior of the getList
method does not suit your API response, you might need to override it. This is mentioned in the documentation (https://refine.dev/docs/faq/#how-i-can-override-specific-function-of-data-providers).
3. GraphQL Providers: The getList
method for GraphQL providers typically expects the total count in specific fields like pageInfo.total
. Ensure that your response structure aligns with these expectations. Refer to the documentation (https://refine.dev/docs/data/hooks/use-list/#retrieving-the-total-row-count) for more details.
Here is a potential solution to ensure that the getList
method correctly interprets your GraphQL response:
In this example, the getList
method is overridden to correctly map the response from your GraphQL query to the structure expected by useList
.
If you continue to face issues, you might want to refer to the Refine documentation (https://refine.dev/docs) for more detailed guidance or consider reaching out on their Discord support thread (https://discord.com/channels/837692625737613362/1214877651769098281) for more personalized help.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@240371095444652032> kapa.ai is still learning and improving, please let us know how it did by reacting below
noble-gold•4w ago
@kapa.ai I dont want to change the data provider.
I just want to use a simple get data as:
const { data: responseData, isLoading: locationLoading, failureReason: failureReason } = useList<GetFieldsFromList<ObdHistoryQuery>>({
resource: "obd_data",
filters: [
{
field: "vehicle",
value: vehicleId,
operator: "eq",
}
],
meta: {
gqlQuery: OBD_GET_HISTORY,
},
queryOptions: {
enabled: true,
},
});
HEre is the query:
export const OBD_GET_HISTORY = gql
query OBDHistory(
$filter: OBDDataFilter!
$sorting: [OBDDataSort!]!
$paging: OffsetPaging!) {
historicalObdData(filter: $filter, sorting: $sorting, paging: $paging) {
nodes {
id
driver {
id
name
}
timestamp
rpm
speed
coolantTemp
throttlePosition
intakeAirTemp
fuelLevel
engineLoad
mafSensor
runTime
distanceMilOn
commandedEgr
barometricPressure
}
totalCount
}
}
;
Is the query wrong for useList?Let me check the knowledge base for you. One moment! :books:
----------------------
Based on the information provided, it seems like the query structure is correct, but there might be an issue with how the
useList
hook is interpreting the response. The useList
hook expects the data to be in a specific format, and it might not be correctly mapping the nodes
and totalCount
fields from your GraphQL response.
To ensure that the useList
hook correctly interprets the response, you can use the meta
property to specify the GraphQL query and the expected response structure. Here's how you can do it:
In this example, the meta
property is used to pass the GraphQL query and the necessary variables. This should help the useList
hook correctly interpret the response from your GraphQL query.
If you continue to face issues, you might want to refer to the Refine documentation (https://refine.dev/docs/data/hooks/use-list/) for more detailed guidance or consider reaching out on their Discord support thread (https://discord.com/channels/837692625737613362/1214877651769098281) for more personalized help.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@240371095444652032> kapa.ai is still learning and improving, please let us know how it did by reacting below
noble-gold•4w ago
@kapa.ai Ok so I noticed something interesting..
I created this query:
const { data: responseData, isLoading: locationLoading, failureReason: failureReason } = useList<GetFieldsFromList<ObdHistoryQuery>>({
resource: "obd_data",
filters: [
{
field: "vehicle",
value: vehicleId,
operator: "eq",
}
],
meta: {
gqlQuery: OBD_GET_HISTORY,
},
queryOptions: {
enabled: true,
},
});
And I get the error: Cannot read properties of undefined (reading 'nodes').
I then decided to try with a different resource:
const { data: responseData, isLoading: locationLoading, failureReason: failureReason } = useList<GetFieldsFromList<ObdHistoryQuery>>({
resource: "gateways",
meta: {
gqlQuery: GATEWAYS_LIST_QUERY,
},
queryOptions: {
enabled: true,
},
});
And it working, but I noticed I get the same error if I remove the resource: "gateways".
So I believe my issue is something with the obd resource.
How should I define it properly?
I don't want it to be a link on the side, so how should I handle this.
Let me check the knowledge base for you. One moment! :books:
----------------------
It seems like the issue might be related to how the
obd_data
resource is defined or handled within your application. Since the useList
hook works with the gateways
resource but not with obd_data
, there are a few things you can check and adjust:
1. Resource Definition: Ensure that the obd_data
resource is correctly defined in your data provider. The resource should be properly registered and configured to handle the GraphQL queries.
2. Data Structure: Verify that the data structure returned by the obd_data
resource matches what the useList
hook expects. Specifically, ensure that the nodes
and totalCount
fields are correctly mapped.
3. Meta Configuration: Make sure that the meta
configuration for the obd_data
resource is correctly set up to use the OBD_GET_HISTORY
query.
Here is an example of how you can define and use the obd_data
resource without it being a link on the side:
Steps to Ensure Proper Resource Definition
1. Check Data Provider Configuration: Ensure that the obd_data
resource is correctly configured in your data provider. This might involve checking the GraphQL endpoint and ensuring that the resource name matches what is expected by the data provider.
2. Verify Response Structure: Make sure that the response from the OBD_GET_HISTORY
query matches the expected structure. The nodes
and totalCount
fields should be present and correctly formatted.
3. Resource Registration: If you are using a custom data provider, ensure that the obd_data
resource is registered correctly. This might involve adding it to the list of resources handled by the data provider.
If you need further assistance, you can refer to the Refine documentation (https://refine.dev/docs) or reach out on their Discord support thread (https://discord.com/channels/837692625737613362/1214877651769098281) for more personalized help.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@240371095444652032> kapa.ai is still learning and improving, please let us know how it did by reacting below