parent
0e3707f656
commit
ffb09ba73b
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,7 @@ |
||||
import { ObjectType, Field } from "type-graphql" |
||||
|
||||
@ObjectType() |
||||
export class User { |
||||
@Field() |
||||
id: string |
||||
} |
@ -0,0 +1,13 @@ |
||||
import "reflect-metadata" |
||||
import { Resolver, Query } from "type-graphql" |
||||
import { User } from "../User" |
||||
|
||||
@Resolver() |
||||
export class UserResolver { |
||||
private recipesCollection: User[] = [] |
||||
|
||||
@Query(returns => [User]) |
||||
async users() { |
||||
return await this.recipesCollection |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
import { ApolloServer } from "apollo-server" |
||||
import { buildSchema } from "type-graphql" |
||||
import { UserResolver } from "./User/UserResolver" |
||||
|
||||
const PORT = process.env.PORT || 4000 |
||||
|
||||
async function bootstrap() { |
||||
// ... Building schema here
|
||||
const schema = await buildSchema({ |
||||
resolvers: [UserResolver], |
||||
}) |
||||
|
||||
// Create the GraphQL server
|
||||
const server = new ApolloServer({ |
||||
schema, |
||||
playground: true, |
||||
}) |
||||
|
||||
// Start the server
|
||||
const { url } = await server.listen(PORT) |
||||
console.log(`Server is running, GraphQL Playground available at ${url}`) |
||||
} |
||||
|
||||
bootstrap() |
Loading…
Reference in new issue