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

Passing a header into AWSAppSyncClient? #761

Open
cristal2431 opened this issue Nov 21, 2023 · 0 comments
Open

Passing a header into AWSAppSyncClient? #761

cristal2431 opened this issue Nov 21, 2023 · 0 comments

Comments

@cristal2431
Copy link

Here's what I am trying to do essentially in Angular.

I am passing the credentials with the users identityId And JWT token to Appsync to authenticate them.

const client = new AWSAppSyncClient({
  url: appSyncConfig.graphqlEndpoint,
  region: appSyncConfig.region,
  auth: {
      type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS,
      jwtToken: async () => (await Auth.currentSession()).getIdToken().getJwtToken(),      
  }
});

My question is, is there any way I can pass an additional header here?

For queries I am using below code which works fine:

const observable = client.watchQuery({
          query: gql(
            getToDo
          ),  
          fetchPolicy: 'cache-and-network',
          variables: variables,
          context: {
            headers:{
              'x-appsync-domain': environment.host,
            }
          }
        });

However, in mutate it does not work.

const result =  await client.mutate(buildMutation(
        client,
        gql(createTodo),
        {
          inputType: gql(createTodoInput),
          variables: {
            input: todo
          },
        },
        _variables => [gql(listTodo)],
        "Todo"
      ));

Is there any other way, I can pass header to mutate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant