Skip to content

Using async atoms within an atomsWithQuery call #12

Description

@wcardosodev

I have a use case where I need to call a query, but one of the variables to the query relies on an async atom. I can't seem to find a good way to achieve this at the moment. Is this currently possible? I.e

export const [playerAtom] = atomsWithQuery(async get => {
  const playerId = get(playerIdAtom);
  const playerTeams = get(playerTeamsAtom);
  const selectedPlayerMatches = await get(selectedPlayerMatchAtom);

  return {
    query: playerQuery,
    variables: {
      playerId: +playerId!,
      teamIds,
      matchIds,
    },
  };
});

Which gives me an error, I think due to the potential of the playerAtom returning a promise: https://www.apollographql.com/docs/react/errors/#%7B"version"%3A"3.8.5"%2C"message"%3A71%2C"args"%3A%5B%5D%7D

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions