-
Notifications
You must be signed in to change notification settings - Fork 72
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
How to add headers? #134
Comments
The best instructions we have for that are here: https://github.com/bgentry/ember-apollo-client/blob/master/README.md#apollo-service-api You'd have to override the link: computed(function() {
let httpLink = this._super(...arguments);
let authLink = setContext((request, context) => {
return { headers: { "App-Key": "someValue" } };
});
return authLink.concat(httpLink);
}), The Apollo Link docs have more info on what you can do with links. Hope that helps! Gonna close this as it's not an issue with the project itself. |
@bgentry Thanks. I apologize for my stupidity... |
@afuno Does it helped? Could you get it working? I might be wrong, but I guess someone on my team said me that something from README about Apollo Links was not working as suggested - I'll try to confirm this info, @bgentry. Anyway, this is how we do it in our app: import ApolloService from 'ember-apollo-client/services/apollo';
import { computed } from '@ember/object';
import { assign } from '@ember/polyfills';
import { inject as service } from '@ember/service';
import { from } from 'apollo-link';
import { setContext } from 'apollo-link-context';
export default ApolloService.extend({
fastboot: service(),
session: service(),
link: computed(function() {
let httpLink = this._super(...arguments);
let setAuthorizationLink = setContext(this.setAuthorization.bind(this));
let setCompanyLink = setContext(this.setCompany.bind(this));
return from([
setCompanyLink,
setAuthorizationLink,
httpLink
]);
}),
setCompany(_, previousContext) {
let context = assign({ headers: {} }, previousContext);
let host = this.get('fastboot.request.host');
if (host) {
context.headers.company_domain = host.split(':')[0];
}
return context;
},
setAuthorization(_, previousContext) {
let context = assign({ headers: {} }, previousContext);
if (this.get('session.isAuthenticated')) {
return new RSVPPromise(success => {
this.get('session').authorize('authorizer:custom', (headerName, headerContent) => {
context.headers[headerName] = headerContent;
success(context);
});
});
} else {
delete context.headers.Authorization;
return context;
}
}
}); |
Sorry, but I absolutely did not understand how to add headers...
I need to have headers sent with each request (Аor example:
App-Key
).I do not understand how to implement this in Ember. But I did it successfully in Vue.
Tell me, please, how to place links, interfaces from Apollo and the like.
Thank you very much in advance!
P. S. I just started to study Ember. Please do not kick me with sticks.
The text was updated successfully, but these errors were encountered: