forwarding headers
This commit is contained in:
1 parent
2f38da331a
commit
2ae9cf9ef6
3 files changed
+23
-2
No files matched your search
Generated
+8
@@ -68,6 +68,14 @@
|
||||
"zen-observable-ts": "^0.8.10"
|
||||
}
|
||||
},
|
||||
"apollo-link-context": {
|
||||
"version": "1.0.9",
|
||||
"resolved": "https://registry.npmjs.org/apollo-link-context/-/apollo-link-context-1.0.9.tgz",
|
||||
"integrity": "sha512-gcC1WH7mTyNtS0bF4fPijepXqnERwZjm1JCkuOT6ADBTpDTXIqK+Ec+/QkVawDO26EV9OX5ujWe4kI1qC6T6tA==",
|
||||
"requires": {
|
||||
"apollo-link": "^1.2.3"
|
||||
}
|
||||
},
|
||||
"apollo-link-http": {
|
||||
"version": "1.5.5",
|
||||
"resolved": "https://registry.npmjs.org/apollo-link-http/-/apollo-link-http-1.5.5.tgz",
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
"nodemon": "^1.18.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"apollo-link-context": "^1.0.9",
|
||||
"apollo-link-http": "^1.5.5",
|
||||
"apollo-server-express": "^1.1.0",
|
||||
"body-parser": "^1.18.3",
|
||||
|
||||
+14
-2
@@ -12,6 +12,7 @@ import {
|
||||
} from 'graphql-tools'
|
||||
import fetch from 'node-fetch'
|
||||
import { createHttpLink } from 'apollo-link-http'
|
||||
import { setContext } from 'apollo-link-context'
|
||||
|
||||
async function run () {
|
||||
const createRemoteSchema = async (uri) => {
|
||||
@@ -21,9 +22,15 @@ async function run () {
|
||||
})
|
||||
const databaseServiceSchemaDefinition = await introspectSchema(makeDatabaseServiceLink())
|
||||
|
||||
const http = makeDatabaseServiceLink()
|
||||
|
||||
const link = setContext((request, previousContext) => (
|
||||
{ headers: previousContext.graphqlContext.headers }
|
||||
)).concat(http)
|
||||
|
||||
return makeRemoteExecutableSchema({
|
||||
schema: databaseServiceSchemaDefinition,
|
||||
link: makeDatabaseServiceLink()
|
||||
link: link
|
||||
})
|
||||
}
|
||||
|
||||
@@ -80,7 +87,12 @@ async function run () {
|
||||
|
||||
const app = express()
|
||||
|
||||
app.use('/graphql', bodyParser.json(), graphqlExpress({ schema }))
|
||||
app.use('/graphql', bodyParser.json(), graphqlExpress(req => {
|
||||
return ({
|
||||
schema: schema,
|
||||
context: req
|
||||
})
|
||||
}))
|
||||
|
||||
app.use(
|
||||
'/graphiql',
|
||||
|
||||
Reference in new issue
Block a user