1

I'm trying to pass a JWT token to my nested queries in AppSync to check that the user has the right to ask for such data.

The problem is that AppSync doesn't let me forward the JWT token from my parent queries to any child resolver.

Example :

mutation test {
emailSignIn(input: {email: "0@gmail.com", password: "XYZ"}) {
token
currentUser {
  id
  profilePicture {
    uuid
  }
  ... on Client {
    lastName
    pleadingList{
      id
      pleadingFiles {
        uuid
      }
      pleadingParticipantSlots {
        id
        participant {
          id
        }
      }
    }
  }

}
}
}

Here profilePicture, pleadingList, pleadingFiles, pleadingParticipantSlots, participant are subqueries and I want to be able to identify who is doing each subqueries not only the main/parent query

Is there any solution?

What I already tried:

The issue is that when I add dynamically the token to the main result, it doesn't always work (in a sense that if what I get back from my query is an array of Item, and a subquery is a launch for each item, then I don't have access to the token in each subrequest because the $ctx.source will only be the item without the token.

  • I also tried pipeline to add the JWT token to ctx.stash but it's even worst because the ctx.stash (and the ctx.args) get cleared before any subrequest

So what I would like is a way to pass a variable to all my child resolver or a way to keep my header from parent request to nested query.

The only way I make it work (and it's very ugly and I don't want to do that ;) ) is to add in the front-end the token as query and subquery parameter each time ...

like:

mutation test {
emailSignIn(input: {email: "0@gmail.com", password: "XYZ"}) {
token
currentUser {
  id
  profilePicture(token: "blablabla") {
    uuid
  }
  ... on Client {
    lastName
    pleadingList(token: "blablabla") {
      id
      pleadingFiles(token: "blablabla") {
        uuid
      }
      pleadingParticipantSlots {
        id
        participant(token: "blablabla") {
          id
        }
      }
    }
  }

}
}
}

I'm kind of lost and don't find anything relevant in AWS AppSync docs. Is there any way? Or am I thinking it wrong?

Thanks

Yves M.
  • 29,855
  • 23
  • 108
  • 144
bryan
  • 11
  • 3

1 Answers1

0

Currently, AppSync does not support passing JWT tokens from the parent to child resolver. The workaround you have mentioned might be one of the current options.