Last active
July 9, 2020 15:45
-
-
Save meerasndr/f0fc824d12d9970c3e81eb56291df362 to your computer and use it in GitHub Desktop.
Proxy for GraphQL server
This file contains hidden or 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
const { importSchema } = require('graphql-tools') | |
const { makeExecutableSchema } = require('graphql-tools') | |
const gql = require('graphql-tag') | |
const proxy = require('express-http-proxy'); | |
const app = require('express')() | |
const http = require('http') | |
const { graphqlHTTP } = require('express-graphql'); | |
const typeDefs = gql` | |
type Query { | |
hello: String | |
} | |
`; // If you're importing the typedefs file : const typeDefs = importSchema('[filename].graphql') | |
const resolvers = { | |
Query: { | |
hello: () => 'Helloww world!' | |
}, | |
}; | |
const mygraphqlschema = makeExecutableSchema({typeDefs, resolvers}) | |
app.post('/proxy', proxy('https://countries-274616.ew.r.appspot.com/',{ | |
proxyReqPathResolver: function(req, res){ | |
console.log(res); | |
} | |
} | |
) | |
) | |
app.use( | |
'/graphql', | |
graphqlHTTP({ | |
schema: mygraphqlschema, | |
graphiql: true, | |
}), | |
function(req,res){ | |
return mygraphqlschema | |
} | |
); | |
app.listen(4000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment