GraphQL orderBy value as javascript parameter?

How to pass orderBy value as parameter to GraphQL query? I tried as String but this will get you error something similar as:

“message”: “Argument ‘orderBy’ on Field ‘allDownloads’ has an invalid value ("name_ASC"). Expected type ‘[DownloadModelOrderBy]’.”,

Currently I have this, but this still gives me query error. I can’t figure what do I need to pass as sortOrder value to match Expected type [DownloadModelOrderBy]?

export async function getDownloadsByCategoryId(
  categoryId, 
  sortOrder,
  skip, 
  locale, 
  preview
) {
  const data = await fetchAPI(
    `
      query DownloadsByCategoryId(
        $categoryId: ItemId = "", 
        $sort: [DownloadModelOrderBy], 
        $skip: IntType!, 
        $locale: SiteLocale = ${process.env.DEFAULT_SITE_LOCALE}
      ) {
        allDownloads(
          first: 100, 
          skip: $skip, 
          locale: $locale, 
          filter: {category: {eq: $categoryId}}, 
          orderBy: $sort
        ) {
          __typename
          id
          name
          language
          version
          attribute1
          attribute2
          description
          fileType
          changeLog
          seo: _seoMetaTags {
            ...metaTagsFragment
          }
          asset {
            url
            size
            filename
            mimeType
          }
        }
      }
      ${metaTagsFragment}
    `,
    {
      preview,
      variables: {
        locale: normalizeLanguages(locale),
        categoryId: categoryId,
        skip: skip,
        sort: sortOrder,
      }
    },
  )

  return data;
}

but I can figure what value to pass into the function to fit [DownloadModelOrderBy]?

Hey @primoz.rome, sorry for the delay on this, it seems i missed this topic!

If you are not using TS, just passing a value of [“en”] to the variable should be accepted as a SiteLocale (if “en” is in your locale list. However it should be inside an array, as just the string won’t be accepted as a fallbacklocale value.