Hi there,
I’m developing a new custom App (Remix, GraphQL) for my shop. I’m using the Admin API to get the Collections and Publications via GraphQL - On App load I’m getting the first 25 or lets say 100 collections, based on which limit I set to the query. So far so good. I’m also added a pagination to my table like this one:
When I’m clicking on next, the onNext() function is called. And in that function I want to fetch the next 25 or 100 results, but I can’t access the GraphQL client anymore.
I tried to use the Apollo Client, but without success .
That here is my loader function:
export async function loader({ request }) {
const { admin, session } = await shopify.authenticate.admin(request)
gadmin = admin
const publications = await getPublications()
let onlineShop = {}
console.log(publications)
publications.map(({ id, name }) => {
if (name === 'Online Store') {
onlineShop = {
id,
name
}
}
}) || [];
const collections = await getCollections(onlineShop.id, 1, null);
console.log(collections)
// const collections = {}
return json({
request,
onlineShop,
collections,
});
}
That works on app load and I’m getting the results in my Index() to show them in a table.
In my onNext() function I’m trying this one:
async function onNext(){
const {test} = await getPublications()
console.log(test)
}
and this is my getPublications():
async function getPublications() {
const publicationResponse = await gadmin.graphql(GET_PUBLICATIONS)
const {
data: {
publications: { nodes }
}
} = await publicationResponse.json();
return nodes;
}
But when I’m clicking onto the pagination next button in the App admin frontend, I’m getting the following error message:
app._index.jsx:64 Uncaught (in promise) TypeError: gadmin.graphql is not a function
at getPublications (app._index.jsx:64:44)
at onNext (app._index.jsx:164:15)
at HTMLUnknownElement.callCallback2 (react-dom.development.js:4164:14)
at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:16)
at invokeGuardedCallback (react-dom.development.js:4277:31)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4291:25)
at executeDispatch (react-dom.development.js:9041:3)
at processDispatchQueueItemsInOrder (react-dom.development.js:9073:7)
at processDispatchQueue (react-dom.development.js:9086:5)
at dispatchEventsForPlugins (react-dom.development.js:9097:3)
getPublications @ app._index.jsx:64
onNext @ app._index.jsx:164
callCallback2 @ react-dom.development.js:4164
invokeGuardedCallbackDev @ react-dom.development.js:4213
invokeGuardedCallback @ react-dom.development.js:4277
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:4291
executeDispatch @ react-dom.development.js:9041
processDispatchQueueItemsInOrder @ react-dom.development.js:9073
processDispatchQueue @ react-dom.development.js:9086
dispatchEventsForPlugins @ react-dom.development.js:9097
(anonymous) @ react-dom.development.js:9288
batchedUpdates$1 @ react-dom.development.js:26140
batchedUpdates @ react-dom.development.js:3991
dispatchEventForPluginEventSystem @ react-dom.development.js:9287
dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay @ react-dom.development.js:6465
dispatchEvent @ react-dom.development.js:6457
dispatchDiscreteEvent @ react-dom.development.js:6430
await in dispatchDiscreteEvent (async)
callCallback2 @ react-dom.development.js:4164
invokeGuardedCallbackDev @ react-dom.development.js:4213
invokeGuardedCallback @ react-dom.development.js:4277
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:4291
executeDispatch @ react-dom.development.js:9041
processDispatchQueueItemsInOrder @ react-dom.development.js:9073
processDispatchQueue @ react-dom.development.js:9086
dispatchEventsForPlugins @ react-dom.development.js:9097
(anonymous) @ react-dom.development.js:9288
batchedUpdates$1 @ react-dom.development.js:26140
batchedUpdates @ react-dom.development.js:3991
dispatchEventForPluginEventSystem @ react-dom.development.js:9287
dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay @ react-dom.development.js:6465
dispatchEvent @ react-dom.development.js:6457
dispatchDiscreteEvent @ react-dom.development.js:6430
I think, that the problem is that I’m calling the Admin API from the Apps Frontend and maybe it’s not allowed, based on security issues, which makes sense to me. But how can I call it?
Any ideas, how I can solve this problem? The pagination is a required feature when working with shopify apps, but there are no working solutions or examples. And it’s not only a pagination problem -
Thanks, Jochen ![]()