Skip to content

Commit

Permalink
[header-link] adding header-link
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanith committed Nov 29, 2018
1 parent a02c409 commit bc28b7b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"apollo-cache-inmemory": "^1.3.11",
"apollo-client": "^2.4.7",
"apollo-link": "^1.2.4",
"apollo-link-context": "^1.0.10",
"apollo-link-http": "^1.5.7",
"aws-sdk": "^2.363.0",
"aws4": "^1.8.0",
Expand Down
14 changes: 14 additions & 0 deletions src/header-link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { setContext } from 'apollo-link-context'

export default headers =>
setContext((_request, context) => {
console.log('context', context)
if (!context.graphqlContext) return {}
if (!context.graphqlContext.headers) return {}
return {
headers: {
...context.graphqlContext.headers,
...headers
}
}
})
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { default as graphqlHttpRequest } from './http-request'
export { default as graphqlLambdaRequest } from './lambda-request'
export { default as createLambdaLink } from './lambda-link'
export { default as createHeaderLink } from './header-link'
export { default as hmacfetch } from './aws4-signer'
export { default as formatError } from './format-error'
14 changes: 9 additions & 5 deletions src/lambda-request.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { ApolloLink } from 'apollo-link'
import { graphqlRequest } from './core/graphql-request'
import createHeaderLink from './header-link'
import createLambdaLink from './lambda-link'

export default ({ lambdaName, region, request, variables, headers = {} }) => {
const link = createLambdaLink({
lambdaName,
region,
headers
})
const link = ApolloLink.from([
createHeaderLink(),
createLambdaLink({
lambdaName,
region
})
])
return graphqlRequest({ name: lambdaName, link, request, variables })
}
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,12 @@ apollo-client@^2.4.7:
optionalDependencies:
"@types/async" "2.0.50"

apollo-link-context@^1.0.10:
version "1.0.10"
resolved "https://registry.yarnpkg.com/apollo-link-context/-/apollo-link-context-1.0.10.tgz#c20b0b32c6e4e08c0d3967174f9c2a897c8431fe"
dependencies:
apollo-link "^1.2.4"

apollo-link-dedup@^1.0.0:
version "1.0.11"
resolved "https://registry.yarnpkg.com/apollo-link-dedup/-/apollo-link-dedup-1.0.11.tgz#6f34ea748d2834850329ad03111ef18445232b05"
Expand Down

0 comments on commit bc28b7b

Please sign in to comment.