Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve headers #446

Open
sudall opened this issue Feb 5, 2022 · 2 comments
Open

Preserve headers #446

sudall opened this issue Feb 5, 2022 · 2 comments

Comments

@sudall
Copy link

sudall commented Feb 5, 2022

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
Copy link
Collaborator

Alan-Cha commented Feb 8, 2022

@sudall Sorry for the late reply. Have you tried using the headers or requestOptions options? These options should allow you to pass your custom headers and other request options to the endpoint.

If you've tried this and it did not work, please let me know more about your use case.

@cancan101
Copy link
Contributor

@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)
       }
     }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants