I started an XM Cloud project using Next.js as Rendering Host. I added some Graphql code, but when I want to run jss build I got an error similar to the next one. https://sitecore.stackexchange.com/questions/33141/error-during-build-of-sample-next-js-app
./src/components/graphql/GraphQL-ConnectedDemo.dynamic.tsx:114:72
Type error: Argument of type 'TypedDocumentNode<ConnectedDemoQueryQuery, Exact<{ datasource: string; contextItem: string; language: string; }>>' is not assignable to parameter of type 'string | DocumentNode'.
Type 'TypedDocumentNode<ConnectedDemoQueryQuery, Exact<{ datasource: string; contextItem: string; language: string; }>>' is not assignable to type 'DocumentNode'.
Types of property 'kind' are incompatible.
Type '"Document"' is not assignable to type 'Kind.DOCUMENT'.
Environment
- @sitecore-jss/sitecore-jss-nextjs: "^21.0.0"
- @sitecore-jss/sitecore-jss-cli: "^21.0.0"
- XM Cloud
After some research I found a workaround. I know this is not the best solution. But if someone else know how to fix this issue please, feel free to leave a comment.
Workaround
In order to stop the type error, I wrap the Graphql call into a js file.
index.js
export async function myFunctionToExecuteQuery
{
.... some code here
const result = await graphQLClient.request(MyQueryDocument, {
myParam: myParam,
});
return result;
}
Then I added an index.d.ts
to declare the types.
export declare async function myFunctionToExecuteQuery<TResult>(
myParam: string
): Promise<TResult| null>;
With that workaround I can still declare the query result type, and also run jss build
without any error.
As I mentioned, this is not the best solution, but I can build the Next.js application successfully.