From 7f0e0c2cbd1e4ee7c33e7e76ad7b6ae3769bd285 Mon Sep 17 00:00:00 2001 From: segpacto Date: Tue, 10 Mar 2020 15:12:50 +0100 Subject: [PATCH] removing request and request-promise dependencies (#9) Co-authored-by: Ivan Martinez Pupo --- helpers/schema-loader.js | 13 ++++++++----- package.json | 4 +--- test/construct.spec.js | 3 ++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/helpers/schema-loader.js b/helpers/schema-loader.js index 8bd444e..756f488 100644 --- a/helpers/schema-loader.js +++ b/helpers/schema-loader.js @@ -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 @@ -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) diff --git a/package.json b/package.json index 91ee526..d0b8721 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -50,5 +48,5 @@ "standard": { "env": [ "jest" ] }, - "version": "1.0.6" + "version": "1.0.7" } diff --git a/test/construct.spec.js b/test/construct.spec.js index c6032f8..e7fd9a0 100644 --- a/test/construct.spec.js +++ b/test/construct.spec.js @@ -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') } })