This directory contains a simple "Hello World" example based on graphql-yoga
.
Clone the repository:
git clone https://github.com/graphcool/graphql-yoga.git
cd graphql-yoga/examples/hello-world
Install dependencies and run the app:
yarn install # or npm install
yarn start # or npm start
Open your browser at http://localhost:4000 and start sending queries.
Query without name
argument:
query {
hello
}
The server returns the following response:
{
"data": {
"hello": "Hello World"
}
}
Query with name
argument:
query {
hello(name: "Sarah")
}
The server returns the following response:
{
"data": {
"hello": "Hello Sarah"
}
}
This is what the implementation looks like:
import { GraphQLServer } from './graphql-yoga'
// ... or using `require()`
// const { GraphQLServer } = require('graphql-yoga')
const typeDefs = `
type Query {
hello(name: String): String!
}
`
const resolvers = {
Query: {
hello: (_, { name }) => `Hello ${name || 'World'}`,
},
}
const server = new GraphQLServer({ typeDefs, resolvers })
server.start(() => console.log('Server is running on localhost:4000'))