-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forwarding x-forwarded and x-original header to gql response and back…
…end requests (#19) * improves readability of package.json * adds plugin to append custom headers and x-forwarded header to gql response * repairs tests after adding custom http header plugins * attaches x-forwarded or x-original headers to calls to backend * adds tests for headers that were added to backend calls * adds tests for http header plugin * moves http-headers-plugin out to instantiating client * cleans up params in instantiation of Apollo Server * Refactoring headers and body processing, Improving unit test for get-body-headers * Fixing linting issue * Removing inline comments * Minor version up to 1.0.9 Co-authored-by: nischal.bachu <[email protected]> Co-authored-by: Osvaldo Aguilar Lauzurique <[email protected]>
- Loading branch information
1 parent
fea6656
commit 83360b4
Showing
6 changed files
with
90 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,33 @@ | ||
const { URLSearchParams } = require('url') | ||
|
||
const HEADERS_TO_PROXY = ['authorization', 'x-forwarded', 'x-original'] | ||
module.exports = (body, bodyType, headers) => { | ||
const headersToProxy = {} | ||
if (headers) { | ||
Object.entries(headers).forEach(([key, value]) => { | ||
for (const header of HEADERS_TO_PROXY) { | ||
if (key.indexOf(header) !== -1) { | ||
headersToProxy[key] = value | ||
} | ||
} | ||
}) | ||
} | ||
|
||
if (!body) { | ||
return { headers } | ||
return { headers: headersToProxy } | ||
} | ||
|
||
if (bodyType === 'json') { | ||
return { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
...headers | ||
...headersToProxy | ||
}, | ||
body: JSON.stringify(body) | ||
} | ||
} | ||
|
||
return { | ||
headers, | ||
headers: headersToProxy, | ||
body: new URLSearchParams(body) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,35 @@ | ||
{ | ||
"name": "gql-gateway", | ||
"description": "GraphQL Gateway that does magic on top of REST services that provides Swagger/OpenAPI specifications.", | ||
"keywords": [ | ||
"graphql", | ||
"gateway", | ||
"swagger" | ||
], | ||
"version": "1.0.9", | ||
"license": "MIT", | ||
"author": { | ||
"name": "Ivan Martinez Pupo", | ||
"email": "[email protected]" | ||
}, | ||
"homepage": "https://github.com/segpacto/gql-gateway#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://[email protected]/segpacto/gql-gateway.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/segpacto/gql-gateway/issues" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"helpers" | ||
], | ||
"main": "index.js", | ||
"scripts": { | ||
"lint:fix": "npx standard --fix", | ||
"lint": "npx standard", | ||
"test": "jest --coverage --detectOpenHandles --runInBand --testRegex=test/.*\\.spec\\.js --testPathIgnorePatterns=test/mocks/*.js" | ||
}, | ||
"dependencies": { | ||
"apollo-server": "^2.9.16", | ||
"graphql": "^14.5.8", | ||
|
@@ -14,7 +38,6 @@ | |
"swagger-to-graphql": "^4.0.2", | ||
"node-fetch": "^2.6.0" | ||
}, | ||
"description": "GraphQL Gateway that does magic on top of REST services that provides Swagger/OpenAPI specifications.", | ||
"devDependencies": { | ||
"apollo-server-testing": "^2.9.16", | ||
"dotenv": "^8.2.0", | ||
|
@@ -23,32 +46,9 @@ | |
"nodemon": "^2.0.2", | ||
"standard": "^14.3.1" | ||
}, | ||
"homepage": "https://github.com/segpacto/gql-gateway#readme", | ||
"keywords": [ | ||
"graphql", | ||
"gateway", | ||
"swagger" | ||
], | ||
"license": "MIT", | ||
"main": "index.js", | ||
"name": "gql-gateway", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://[email protected]/segpacto/gql-gateway.git" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"helpers" | ||
], | ||
"scripts": { | ||
"lint:fix": "npx standard --fix", | ||
"lint": "npx standard", | ||
"test": "jest --coverage --detectOpenHandles --runInBand --testRegex=test/.*\\.spec\\.js --testPathIgnorePatterns=test/mocks/*.js" | ||
}, | ||
"standard": { | ||
"env": [ | ||
"jest" | ||
] | ||
}, | ||
"version": "1.0.8" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters