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

Add an optional 'customHeaders' field to AWSAppSyncClientOptions to easily add headers to requests #469

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

babouinette
Copy link

@babouinette babouinette commented Oct 8, 2019

Description of changes:

This change allows passing a customHeaders argument to AWSAppSyncClientOptions to easily add headers to requests, by using the 'headers' field in createHttpLink.

For example, to add an authorization header, instead of doing this :

const AppSyncConfig = {
  url:  "url",
  region: "us-east-1",
  auth: {
    type: "API_KEY",
    apiKey: "key"
  }
};

const client = new AWSAppSyncClient(AppSyncConfig, {
  link: createAppSyncLink({
    ...AppSyncConfig,
    resultsFetcherLink: ApolloLink.from([
      createHttpLink({
        uri: AppSyncConfig.url,
        headers: {"Authorization" : "Bearer 1234"},
      })
    ])
  })
});

We could do this :

const AppSyncConfig = {
  url: "url",
  region: "us-east-1",
  auth: {
    type: "API_KEY",
    apiKey: "key",
  },
  customHeaders: {"Authorization" : "Bearer 1234"},
};

const client = new AWSAppSyncClient(AppSyncConfig);

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@pickfire
Copy link

I rather not have this, in our case our custom header is not known until called.

@bpcrao
Copy link

bpcrao commented Sep 11, 2020

I rather not have this, in our case our custom header is not known until called.

is there a better way to do this? like pass headers(tokens) only during mutate or query?
and I do not want to create client every time for every query too

@pickfire
Copy link

is there a better way to do this? like pass headers(tokens) only during mutate or query?
and I do not want to create client every time for every query too

For us, we only know it during the query, every query needs different header, maybe allow the query to be set during runtime?

@bpcrao
Copy link

bpcrao commented Sep 14, 2020

client.mutate({ mutation: mutationName, context: {
headers:{ ....headersJSON} // custom headers
} })

why is this not helping you? it worked for me

@pickfire
Copy link

pickfire commented Sep 14, 2020

How did you do client.mutate? I don't have that function here. Note that I was using angular.

@bpcrao
Copy link

bpcrao commented Sep 16, 2020

@pickfire using AWSAppSyncClient

@pickfire
Copy link

I don't use that directly. Also, I left the company working on this already.

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

Successfully merging this pull request may close these issues.

None yet

3 participants