Skip to content

Commit

Permalink
removing request and request-promise dependencies (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan Martinez Pupo <[email protected]>
  • Loading branch information
segpacto and Ivan Martinez Pupo authored Mar 10, 2020
1 parent 6ff8b5c commit 7f0e0c2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
13 changes: 8 additions & 5 deletions helpers/schema-loader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { createSchema } = require('swagger-to-graphql')
const callBackend = require('./callbackend')
const request = require('request-promise')
const fetch = require('node-fetch')

/**
* @param {GraqhQLSchema} localSchema
Expand All @@ -9,11 +9,14 @@ const request = require('request-promise')
*/
module.exports = async ({ localSchema, remoteRestServices }) => {
const schemasAvailable = remoteRestServices.map(async service => {
const swaggerResponse = await request({
uri: service.url,
headers: service.headers
const swaggerResponse = await fetch(service.url, {
headers: {
'Content-Type': 'application/json',
...service.headers
}
})
let swaggerSchema = JSON.parse(swaggerResponse)

let swaggerSchema = await swaggerResponse.json()

if (service.onLoaded) {
swaggerSchema = service.onLoaded(swaggerSchema, service)
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
"graphql": "^14.5.8",
"graphql-tag": "^2.10.1",
"graphql-tools": "^4.0.6",
"request": "^2.88.0",
"request-promise": "^4.2.5",
"swagger-to-graphql": "^4.0.2",
"node-fetch": "^2.6.0"
},
Expand Down Expand Up @@ -50,5 +48,5 @@
"standard": {
"env": [ "jest" ]
},
"version": "1.0.6"
"version": "1.0.7"
}
3 changes: 2 additions & 1 deletion test/construct.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ describe('Server construct', () => {
const endpointsList = [{ name: 'petstore_service', url: 'https://no-existent-endpoint/swagger.json' }]
await gateway({ endpointsList })
} catch (err) {
expect(err.message).toBe('Error: getaddrinfo ENOTFOUND no-existent-endpoint no-existent-endpoint:443')
expect(err.code).toBe('ENOTFOUND')
expect(err.message).toBe('request to https://no-existent-endpoint/swagger.json failed, reason: getaddrinfo ENOTFOUND no-existent-endpoint no-existent-endpoint:443')
}
})

Expand Down

0 comments on commit 7f0e0c2

Please sign in to comment.