Skip to content

Conversation

@boeckMt
Copy link

@boeckMt boeckMt commented Mar 31, 2025

Versions

  • payload: 3.17.1
  • @payload-enchants/sdk: 1.2.2

Current Situation

The typing of select in the following functions

that specified an array K extends (keyof C['collections'][T])[] was not correct as input for queryString.stringify(...) (qs). As a result, the function only returned the ID if select was used in the form of an array.

// Import it from generated types
import { Config } from 'payload-types';

const client = new PayloadApiClient<Config>({
  apiURL: 'http://localhost:3000/api',
});

const { docs } = await client.find({
      collection: 'datasets',
      depth: 2,
      select: ['slug', 'title']
});

The resulting query looked like this ...datasets?depth=2&select[0]=slug&select[1]=title

Fix

Types are changed to a Partial object and boolean values.

...
const { docs } = await client.find({
      collection: 'datasets',
      depth: 2,
      select: {
        slug: true,
        title: true
      }
});

The resulting query ...datasets?depth=2&select[slug]=true&select[title]=true


I think this is the easiest fix, otherwise we would have to pull out the select array from toQs and transform it to an object.

But if this is more appreciated, I can also change the PR to that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant