2

I am currently making a NextJS website with KeystoneJS as the CMS. I can't find any good guides on how to set this up correctly so I have just jumped in. An issue that I am currently experiencing is that I am unable to request data from GraphQL. I can do it through the playground, just not the nextjs pages.

I have tried the following methods:

Axios => Module not found: Can't resolve 'async_hooks'

fetchAPI => Module not found: Can't resolve 'async_hooks'

getItems => Error: No executable schema named 'public' is available. Have you setup '@keystonejs/app-graphql'?

I am pretty sure that I should be using getItems since it is imported from @/keystonejs/server-side-graphql-client. However I'm not sure if I have set it up correctly.

My current project setup is installing KeystoneJS - Blank template. and then I have manually installed NextJS based on the installation guide. My module exports looks like this:

module.exports = {
    keystone,
    apps: [
        new GraphQLApp(),
        new AdminUIApp({
            name: PROJECT_NAME,
            enableDefaultRoute: false,
            authStrategy,
            isAccessAllowed: isAdmin,
        })
    ],
};

Here is my getItems request:

export async function getStaticProps() {
    const posts = await getItems({
        keystone,
        listKey: 'Post',
        returnFields: 'name'
    });
    console.log(posts);
    return {
        props: {
            posts,
        },
    }
};
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
James Hill
  • 25
  • 3
  • Might be related: https://stackoverflow.com/questions/64481222/custom-keystonejs-server-side-functions-no-executable-schema-named-public-e? – juliomalves Feb 18 '21 at 10:19
  • 2
    I found this a tricky error. In my case as @juliomalves has mentioned, the issue was that I had set up a separate Express instance, but I remember running into the same error message a few times. Are you using the starter project? If so, might we worth adding the full content of index.js to your question – Matt Saunders Feb 22 '21 at 16:09
  • Otherwise, it looks like you're working on server side queries, when you might want to be making graphQL queries directly to `localhost:3000/admin/api` from your Next application. I did the same thing and ended up building a whole load of unnecessary "REST" style endpoints. – Matt Saunders Feb 22 '21 at 16:14
  • You can get an auth key from your app following the method here: https://stackoverflow.com/questions/63077526/perform-an-authenticated-keystone-js-graphql-api-query/63112432#63112432. Then it's just a case of submitting graphQL queries to `localhost:3000/admin/api` as you would from the playground – Matt Saunders Feb 22 '21 at 16:16

0 Answers0