Skip to content

Commit

Permalink
document the way to use ApolloServer with a GraphQLSchema object (#1502)
Browse files Browse the repository at this point in the history
* document the way to use ApolloServer with a GraphQLSchema object

* Add recommendation to use SDL
  • Loading branch information
cahnory authored and evans committed Aug 14, 2018
1 parent 9225426 commit 4d67c1c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,33 @@ const server = new ApolloServer({
});
```

While we recommend the use [schema-definition language (SDL)](https://www.apollographql.com/docs/apollo-server/essentials/schema.html#sdl) for defining a GraphQL schema since we feel it's more human-readable and language-agnostic, Apollo Server can be configured with a `GraphQLSchema` object:

```js
const { ApolloServer, gql } = require('apollo-server');
const { GraphQLSchema, GraphQLObjectType, GraphQLString } = require('graphql');

// The GraphQL schema
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
hello: {
type: GraphQLString,
description: 'A simple type for getting started!',
resolve: () => 'world',
},
},
}),
});

const server = new ApolloServer({ schema });

server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
```

## Integrations

Often times, Apollo Server needs to be run with a particular integration. To start, run `npm install --save apollo-server-<integration>` where `<integration>` is one of the following:
Expand Down

0 comments on commit 4d67c1c

Please sign in to comment.