Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

singleDocData option seems works only with .getById #1350

Open
Merkur39 opened this issue Apr 26, 2023 · 2 comments
Open

singleDocData option seems works only with .getById #1350

Merkur39 opened this issue Apr 26, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@Merkur39
Copy link
Member

Avec une requête comme ci-dessous :

export const buildAppSettingsQuery = () => ({
  definition: () => Q(SETTINGS_DOCTYPE),
  options: {
    singleDocData: true,
    as: `${SETTINGS_DOCTYPE}`,
    fetchPolicy: defaultFetchPolicy
  }
})

Nous obtenons toujours le résultat suivant : { data: [{ _id: 'foo', ... }], ... }

La solution pour que l'option singleDocData soit respectée est de passer par la méthode getById, soit :

export const buildAppSettingsQuery = () => ({
  definition: () => Q(SETTINGS_DOCTYPE).getById('configuration'),
  options: {
    singleDocData: true,
    as: `${SETTINGS_DOCTYPE}`,
    fetchPolicy: defaultFetchPolicy
  }
})

Et ainsi nous obtenons bien : { data: { _id: 'foo', ... }, ... }

@paultranvan
Copy link
Contributor

This is because of

const isSingleDocQuery =
queryResults.definition && queryResults.definition.id
, which is indeed a bit misleading

But since there is no .limitBy(1) in your example, what would be the expected behavior if there is actually more than one doc? Return the first one? Throw an error? Ignore the singleDocData?

@Merkur39
Copy link
Member Author

Ok, I missed that info

  1. I would say return the most recent, we should still have the information via the count if there is more than one.

  2. As for the .limitBy(1), it should do it implicitly (I think I saw an issue at this subject)

The first point is debatable, maybe limiting to the use of limitBy is better 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants