Skip to content

Instantly share code, notes, and snippets.

@ronderksen
Last active January 23, 2019 13:54
Show Gist options
  • Save ronderksen/008e5311e2240bc0460f688a2517ce79 to your computer and use it in GitHub Desktop.
Save ronderksen/008e5311e2240bc0460f688a2517ce79 to your computer and use it in GitHub Desktop.
export function filterHeaders(headers, nameList) {
return nameList
.map(name => name.toLowerCase())
.reduce((acc, name) => ({
...acc,
[name]: headers[name]
}, {})
.filter(Boolean);
}
import { filterHeaders } from './filter-headers';
export const myResolver = {
Query: {
getTodo: (_, { id }, { req, dataSources }) {
// this req has the headers we need
const reqOptions = {
headers: filterHeaders(req.headers, ['x-authorization', ['x-level'])
};
return dataSources.todoAPI.getTodo(id, reqOptions);
}
}
}
import { RESTDataSource } from 'apollo-datasource-rest';
export class TodoAPI extends RESTDataSource {
getTodo(id, options) {
return this.get(`/todo/${id}`, null, options);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment