Helix in Gateway to pass headers down to subschema?
zawadzkip opened this issue · 1 comments
zawadzkip commented
Having some issues with headers not making it down to sub-services in my gateway setup.
Namely we send authorization headers through our client to the gateway and I would like to use graphql-shield
on the subschema services to check against these headers.
It doesn't seem like the auth headers are making it past the gateway into the subschema. Is there a way to resolve this? Am I setting up my helix/gateway incorrect? (Almost identical to the example) Any help would be appreciated, thank you!
const fastify = require('fastify')
const { getGraphQLParameters, processRequest, renderGraphiQL, shouldRenderGraphiQL, sendResult } = require("graphql-helix");
const { envelop, useLogger, useSchema, useTiming } = require("@envelop/core")
const { useGenericAuth } = require('@envelop/generic-auth')
const { useResponseCache } = require('@envelop/response-cache');
const { resolveUserFn, validateUserFn } = require('./authUtils')
const SchemaLoader = require('./SchemaWithLoader')
const MIN_IN_MS = 60000
SchemaLoader.reload().then(async () => {
const app = fastify()
const getEnveloped = envelop({
plugins: [
// useNewRelic also exists, but isnt setup in this use case
useTiming({
skipIntrospection: true
}),
// useResponseCache({
// ttl: 1000,
// }),
useSchema(SchemaLoader.schema),
]
})
app.route({
method: ['GET', 'POST'],
url: '/graphql',
async handler(req, res) {
const request = {
body: req.body,
headers: req.headers,
method: req.method,
query: req.query,
}
const { parse, validate, contextFactory, execute, schema } = getEnveloped({ req })
if (shouldRenderGraphiQL(request)) {
res.type("text/html");
res.send(renderGraphiQL())
return
}
const { operationName, query, variables } = getGraphQLParameters(request);
const result = await processRequest({
operationName,
query,
variables,
request,
schema,
parse,
validate,
execute,
})
sendResult(result, res.raw)
}
})
app.listen(3000, () => {
console.log(`⛩️ Gateway Server ready at http://localhost:3000/graphql`);
})
SchemaLoader.autoRefresh(30000)
})
zawadzkip commented
Totally a bug on my end :) Forgot to pass the header through the remote executor through the context here.