cda-client problem with typescript and string

Hi,

using the cda-client and passing a string as first parameters I got a “No overload matches this call.”.

e.g. code example

const query = `
  query {
    allArticles {
      id
      title
    }
  }
`;

const result = await executeQuery(query, {
  token: process.env.NEXT_DATOCMS_API_TOKEN,
});

thanks

Enrico


[Mod note: Fixed code block formatting]

Hi @enrico.sardi,

Welcome to the forum and sorry about the confusion there.

I think what you’re seeing is a TypeScript mismatch. You can technically pass executeQuery() a string as the first param, but that’s meant for non-TS environments.

When using TS, we are assuming that you’d pass it a TypedDocumentNode instead of a string. Please see some examples on the readme: https://www.npmjs.com/package/@datocms/cda-client or in our starter kit: https://github.com/datocms/nextjs-starter-kit/blob/main/src/app/(base-layout)/basic/page.tsx (which uses gql.tada to auto-discover and generate the proper types).

If you don’t want to use TypeScript for it, you can either just //@ts-ignore that line or use a .js/.jsx extension for that whole file. But if you’re using TypeScript anyway, getting the proper GraphQL types would save you a lot of headaches later since you can actually see when a query is properly constructed ahead of time.

Hope that helps!