Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

apollo-engine

This directory contains the "Hello World" example based on graphql-yoga, extended with Apollo Engine.

Get started

Clone the repository:

git clone https://github.com/graphcool/graphql-yoga.git
cd graphql-yoga/examples/apollo-engine

Install dependencies

yarn install # or npm install
yarn start   # or npm start

Set the APOLLO_ENGINE_KEY environment variable

export APOLLO_ENGINE_KEY=.... # on Linux/Mac
set APOLLO_ENGINE_KEY=....    # on Windows

Run the app

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'
import { Engine } from 'apollo-engine'
// ... or using `require()`
// const { GraphQLServer } = require('graphql-yoga')
// const { Engine } = require('apollo-engine')

const typeDefs = `
  type Query {
    hello(name: String): String!
  }
`

const resolvers = {
  Query: {
    hello: (_, { name }) => `Hello ${name || 'World'}`,
  },
}

const server = new GraphQLServer({ typeDefs, resolvers })

const engine = new Engine({
  engineConfig: { apiKey: process.env.APOLLO_ENGINE_KEY },
  endpoint: '/',
  graphqlPort: parseInt(process.env.Port, 10) || 4000,
})
engine.start();

server.express.use(engine.expressMiddleware())

server.start(() => console.log('Server is running on localhost:4000'))

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages