Last active
May 29, 2020 03:21
-
-
Save Wonder2210/e1195083396b3d8c52d0b0ea95f71010 to your computer and use it in GitHub Desktop.
Postgresql + Graphql + Typescript server Hello world
This file contains 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
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