remkoj / optimizely-saas-starter

Optimizely Graph Powered Next.JS Starter
Apache License 2.0
5 stars 4 forks source link

Cannot query field "Content" on type "Query". Did you mean "_Content"?" #2

Open rsudworth opened 3 weeks ago

rsudworth commented 3 weeks ago

I'm trying to get into Optimizely SaaS, but found the code at https://github.com/episerver/cms-saas-vercel-demo a little too complete to learn and build from, so I've been using this as my starter instead. Thank you for all the effort that has gone into these tools to use SaaS.

After following the read me instructions, I got this error:

Cannot query field "Content" on type "Query". Did you mean "_Content"?"

I found it was coming from src/app/[[...path]]/page.tsx, which in turn calls a graph query from https://github.com/remkoj/optimizely-dxp-clients/blob/main/packages/optimizely-cms-nextjs/src/cms-page/data.ts. I was able to replicate the same error in my Saas instance and fix it by swapping to _Content.

I tried to fix it by updating the referenced pakages to *-pre5, but they still had the same issue.

I noticed that the larger cms-saas-vercel-demo codebase doesn't use the same query and instead page.tsx uses the graph functions inside the site code (which I think are generated?). Based on this, I was able to get my optimizely-saas-starter site going with the following page.tsx:

import { CmsPage as OptimizelyCmsPage } from "@remkoj/optimizely-cms-nextjs";
import getFactory from "@/components/factory";
import { getContentByPath } from "@/gql/functions";

// const { CmsPage, generateMetadata, generateStaticParams } = OptimizelyCmsPage.createPage(getFactory(), {})
const { generateMetadata, generateStaticParams, CmsPage } =
  OptimizelyCmsPage.createPage(getFactory(), {
    getContentByPath:
      getContentByPath as OptimizelyCmsPage.GetContentByPathMethod,
  });

// Configure the Next.JS route handling for the pages
export const dynamic = "force-static"; // Make sure we cache pages
export const dynamicParams = true; // Allow new pages to be resolved without rebuilding the site
export const revalidate = false; // Keep the cache untill manually revalidated using the Webhook
export const fetchCache = "default-cache"; // Cache fetch results by default

// Export CMS Page
export { generateMetadata, generateStaticParams };
export default CmsPage;

I'm not sure if the Optimizey graph schema has changed, this is a bug, or all of this code Optimizely have suggested we use to inboard with Saas is still a work in progress, but I though it couldn't hurt to raise the issue.

moel-levo commented 2 weeks ago

You are right, the base types were changed a while ago and are now prefixed with "_".

image (4)