0
votes

I am integrating the Microsoft graph API in my application, so currently I am getting access token at the client-side through MSAL npm module, so I need access token at the apollo server to hit the Microsoft graph API's(This access token is only required for only one resolver, for the application authorization I have different access token that I check for every resolver), so is there any way I can add context while mutation like I tried this -

<Mutation mutation={CREATE_MICROSOFT_TEAMS} context={{ microsoftgraphaccesstoken: msalAccessToken }}> I have tried to pass context in the mutation but it doesn't work, is there something like this, or should I pass the token in the argument and then add that in to the headers when my apollo server is going to hit the microsoft graph API's.

1

1 Answers

0
votes

There are multiple ways to access the token server-side, the easiest way is to consider the token as part of the mutation variables, since it is specific to one resolver anyway.

Using mutation variables:

// client.js

<Mutation 
  mutation={CREATE_MICROSOFT_TEAMS} 
  variables={{ microsoftgraphaccesstoken: msalAccessToken }}
>
// server.js

function createMsTeamsResolver(source, args, context, info) {
  console.log(args.microsoftgraphaccesstoken);
}

That way you can also access any arguments as you would normally.