WaspW
Wasp15mo ago
wardbox

AWS file upload query cache invalidation after creation

Using version 0.14.2 on MacOS

I have a query to get a team
query getTeamById {
  fn: import { getTeamById } from "@src/server/queries.js",
  entities: [Team, Organization, OrganizationRole, File]
}


And the team returns a logo (File) if there is one
const team = await context.entities.Team.findFirstOrThrow({
      where: {
        id: id
      },
      include: {
        logo: true,
      }
    });


I also have a form that uploads a file and uses an action to do it.
action createFile {
  fn: import { createFile } from "@src/server/actions.js",
  entities: [User, Player, Team, File]
}

return await context.entities.File.create({
      data: {
        name,
        key,
        uploadUrl,
        type: fileType,
        user: { connect: { id: context.user.id } },
        team: {
          connect: { id: teamId }
        },
      },
    });


When I upload the file and connect it to the team, I expect the getTeamById query to invalidate the cache since I have the File entity in the query and the Team entity in the createFile action. Right now when I upload a new photo, the query invalidates and errors out with a 404 from AWS because it can't find the file. If I do a full page refresh, it loads fine. Is there a way I could do a sleep or something to wait for it to finish uploading?
Was this page helpful?