Preserve headers
sudall opened this issue · comments
sudall commented
Hello,
Is there a way to preserve headers that are passed to the graphql endpoint? ie. forward headers on the REST API endpoint. I tried passing along an Authorization header, but it seems to get lost at some point and the REST API returns with a 401. I've looked through the docs, but I didn't see anything that would do this.
Alan Cha commented
Alex Rothberg commented
@sudall you would want to pass this in correctly, but this is how I hacked the CLI to proxy the Authorization
header:
diff --git a/packages/openapi-to-graphql-cli/src/index.ts b/packages/openapi-to-graphql-cli/src/index.ts
index 9393c34..0a21d43 100644
--- a/packages/openapi-to-graphql-cli/src/index.ts
+++ b/packages/openapi-to-graphql-cli/src/index.ts
@@ -144,7 +144,12 @@ Promise.all(
* for the OpenAPI-to-GraphQL library
*/
...{
- headers: parseKeyValuePairs(program.header),
+ // headers: parseKeyValuePairs(program.header),
+ headers(method, path, title, { source, args, context, info }) {
+ return context.headers.authorization
+ ? { Authorization: context.headers.authorization }
+ : {}
+ },
qs: parseKeyValuePairs(program.queryString)
}
}