The server that is used for the examples on dev.apollodata.com.
This is a really simple GraphQL server that uses Apollo Server and GraphQL Tools to serve a simple schema.
It uses a very simple in-memory database, so if you restart the server or change the code, the data will reset.
Redis pub/sub subscriptions has been added. So you need to install and run a Redis DB server.
koa2 server support has been added (see koa2-server.js
)
Clone the repository and run npm install
git clone https://github.com/apollostack/frontpage-server
cd frontpage-server
npm install
Start the Redis server redis-server
Connect to server redis-cli monitor
Express 4.0
npm start
Koa 2
npm run start-koa
The server will run on port 8080. You can change this by editing server.js
.
Apollo Server accepts only JSON-encoded POST requests. A valid request must contain either a query or an operationName (or both, in case of a named query), and may include variables.
{
"query": "query aTest{ test(who: $arg1) }",
"operationName": "aTest",
"variables": { "arg1": "me" }
}
can be sent by simply sending a JSON-encoded array of queries, e.g.
[
{ "query": "{ testString }" },
{ "query": "query q2{ test(who: \"you\" ) }" }
]
If your schema gets large, you may want to define parts of it in different files and import them to create the full schema.
Mock your GraphQL data based on a schema
addMockFunctionsToSchema({schema, mocks = {}, preserveResolvers = false})
addMockFunctionsToSchema
is the function that mockServer uses under the hood. Given an instance of GraphQLSchema
and a mock
object, it modifies the schema in place to return mock data for any valid query that is sent to the server.
import { forbidUndefinedInResolve } from 'graphql-tools';
forbidUndefinedInResolve(schema);
Logging
import { addErrorLoggingToSchema } from 'graphql-tools';
const logger = { log: (e) => console.error(e.stack) };
addErrorLoggingToSchema(mySchema, logger);
graphiql is an in-browser IDE for exploring GraphQL. Apollo comes with graphiql which has been configured in this project at the route /graphiql
.
See a graphql live demo