Skip to content

Files

Latest commit

b3b59e5 · Apr 23, 2022

History

History
This branch is 293 commits ahead of, 12 commits behind prismake/typegql:master.

basic-express-server

Basic apollo-server example

Example of basic graphql api able to resolve such query

query {
  hello(name: "Bob") # will resolve to 'Hello, Bob!'
}

Here is all the server code required:

import { SchemaRoot, Query, compileSchema } from 'decapi'
import ApolloServer from 'apollo-server'

@SchemaRoot()
class SuperSchema {
  @Query()
  hello(name: string): string {
    return `Hello, ${name}!`
  }
}

const compiledSchema = compileSchema(SuperSchema)

const server = new ApolloServer({ schema, graphiql: true })

server.listen(3000, () =>
  console.log('Graphql API ready on http://localhost:3000/graphql')
)

To start this example, in this folder run yarn install and yarn start. Server will be running under http://localhost:3000/graphql