Switch branches/tags
Find file History
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
README.md Fix incorrect git urls (#184) Feb 21, 2018
index.js add fullstack example Nov 15, 2017
package.json chore(deps): update dependency graphql-yoga to v1.2.0 Jan 15, 2018

README.md

hello-world

This directory contains a simple "Hello World" example based on graphql-yoga.

Get started

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

Testing

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"
  }
}

Implementation

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'))