Skip to content

Instantly share code, notes, and snippets.

@Wonder2210
Last active May 29, 2020 03:21
Show Gist options
  • Save Wonder2210/e1195083396b3d8c52d0b0ea95f71010 to your computer and use it in GitHub Desktop.
Save Wonder2210/e1195083396b3d8c52d0b0ea95f71010 to your computer and use it in GitHub Desktop.
Postgresql + Graphql + Typescript server Hello world
import express, { Application } from 'express';
import { ApolloServer , Config } from 'apollo-server-express';
const app: Application = express();
const schema = `
type User{
name: String
}
type Query {
user:User
}
`
const config : Config = {
typeDefs:schema,
resolvers : {
Query:{
user:(parent,args,ctx)=>{
return { name:"WOnder"}
}
}
},
introspection: true,//these lines are required to use the gui
playground: true,// of playground
}
const server : ApolloServer = new ApolloServer(config);
server.applyMiddleware({
app,
path: '/graphql'
});
app.listen(3000,()=>{
console.log("We are running on http://localhost:3000/graphql")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment