Last active
January 23, 2019 13:54
-
-
Save ronderksen/008e5311e2240bc0460f688a2517ce79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function filterHeaders(headers, nameList) { | |
return nameList | |
.map(name => name.toLowerCase()) | |
.reduce((acc, name) => ({ | |
...acc, | |
[name]: headers[name] | |
}, {}) | |
.filter(Boolean); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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