I'm developing a react app using RTK Query & AppSync (graphQL).
I tried a query request as follows, but always the redux status is "rejected" saying "Cannot read properties of undefined (reading 'filter')"
(Please check a pic below).
It seems the request itself is successfully done (200), so I guess it is due to the geaphQL client.
Redux Toolkit without RTK Query works as expected.
Please help
RTK Query (rejected)
import { createApi } from '@reduxjs/toolkit/query/react';
import { graphqlRequestBaseQuery } from '@rtk-query/graphql-request-base-query';
import { API } from 'aws-amplify';
import { GRAPHQL_AUTH_MODE } from '@aws-amplify/api-graphql/lib/types';
import { listSurveyTitles } from 'src/graphql/queries';
import aws_exports from 'src/aws-exports';
API.configure(aws_exports);
export const surveyTitlesApi = createApi({
reducerPath: 'surveyTitles',
baseQuery: graphqlRequestBaseQuery({
url: '/graphql',
}),
endpoints: (builder) => ({
fetchSurveyTitles: builder.query({
query: ({ limit = 2147483647, params }) => ({
document: API.graphql({
query: listSurveyTitles,
variables: { limit, ...params },
authMode: GRAPHQL_AUTH_MODE.API_KEY,
}),
}),
}),
}),
});
export const { useFetchSurveyTitlesQuery } = surveyTitlesApi;
Slice with Redux Toolkit not RTK (fulfilled)
export const fetchSurveyTitles = createAsyncThunk(
'planner/fetchSurveyTitles',
async ({ limit = 2147483647, ...params }, thunkAPI) => {
try {
return await API.graphql({
query: listSurveyTitles,
variables: { limit, ...params },
authMode: GRAPHQL_AUTH_MODE.API_KEY,
});
} catch (e: any) {
return thunkAPI.rejectWithValue(e);
}
}
);