Create Basic GraphQL Server

NOTE: The crux of the implementation is to define a schema for your data that defines the Query type AND to use the GraphQL.js to respond to the client’s GraphQL Query. To use GraphQL for an API server over HTTP, check out Running an Express GraphQL Server. Once server is ready, The next step is to learn how to issue GraphQL queries from client code.

The GraphQL module contains the GraphQL technical preview, which allows us to compose our server schema and process GraphQL requests against it. Body-parser is a simple Express middleware that we use to grab the GraphQL request being sent.

Any POST requests to /graphql will now be executed against our GraphQL schema. We enforce a new content type for these requests — this isn’t part of the GraphQL spec, but may be a good pattern for servers that mix GraphQL with existing code.

ref: https://medium.com/the-graphqlhub/your-first-graphql-server-3c766ab4f0a2#.bu5rizg3j

You can view the source (each commit is a new step) here: https://github.com/clayallsopp/graphql-intro

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s