Skip to content

Instantly share code, notes, and snippets.

@meerasndr
Last active July 9, 2020 15:45
Show Gist options
  • Save meerasndr/f0fc824d12d9970c3e81eb56291df362 to your computer and use it in GitHub Desktop.
Save meerasndr/f0fc824d12d9970c3e81eb56291df362 to your computer and use it in GitHub Desktop.
Proxy for GraphQL server
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