From 1068793f798e90c3892fb50ac0ee6a704bb6f1ce Mon Sep 17 00:00:00 2001 From: Evans Hauser Date: Wed, 9 May 2018 11:10:55 -0700 Subject: [PATCH 1/3] docs: add code examples for whats-new and new features --- docs/source/whats-new.md | 98 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 5 deletions(-) diff --git a/docs/source/whats-new.md b/docs/source/whats-new.md index 97b79a2a..403261c6 100644 --- a/docs/source/whats-new.md +++ b/docs/source/whats-new.md @@ -2,21 +2,45 @@ title: What's new? --- -This section of the ApolloServer docs is an announcement page where it is easy to find and share big changes to the ApolloServer package, or the Apollo server side ecosystem. For a more detailed list of changes, check out the [Changelog](). +This section of the ApolloServer docs is an announcement page where it is easy to find and share big changes to the ApolloServer package, or the Apollo server side ecosystem. For a more detailed list of changes, check out the [Changelog](https://github.com/apollographql/apollo-server/blob/version-2/CHANGELOG.md). ## 2.0 ApolloServer 2.0 is a new effort targeted in making the most powerful and production ready GraphQL app easier than ever to build. Instead of providing all of the tools to figure out how to make a great GraphQL backend, the 2.0 brings everything together that we think you should be doing when building a GraphQL app. It is an opinionated, production focused, GraphQL server that works with any backend. -TODO code example +```js +const { ApolloServer, gql } = require('apollo-server'); -This is just the beginning. We have published a [roadmap]() for all of the features we will be bringing to ApolloServer soon and we would love your help! If you have any interest, you can get involved on [Github]() or by joining the [Apollo Slack]() and going to the #apollo-server channel. +// The GraphQL schema +const typeDefs = gql` + type Query { + hello: String + mockedString: String + } +`; -## Errors +// A map of functions which return data for the schema. +const resolvers = { + Query: { + hello: () => fetch('https://fourtonfish.com/hellosalut/?mode=auto').then(res => res.json()).then(data => data.hello) + } +}; + +const server = new ApolloServer({ + typeDefs, + resolvers, + mocks: true, + onHealthCheck: () => fetch('https://fourtonfish.com/hellosalut/?mode=auto'), +}); +``` + +This is just the beginning. We have published a [roadmap](https://github.com/apollographql/apollo-server/blob/master/ROADMAP.md) for all of the features we will be bringing to ApolloServer soon and we would love your help! If you have any interest, you can get involved on [Github](https://github.com/apollographql/apollo-server) or by joining the [Apollo Slack](https://www.apollographql.com/slack) and going to the #apollo-server channel. + +## [Errors](./features/errors.html) Apollo Server provides the ability to add error codes to categorize errors that occur within resolvers. In addition to an error code, Apollo Server 2 passes error stack traces in development mode to enable a smoother getting started experience. -This code snippet shows how the new error could be used. For more information, take a look at [this section]() +This code snippet shows how the new error could be used. ```js const { ApolloError, ForbiddenError, AuthenticationError } = require("apollo-server"); @@ -46,3 +70,67 @@ const resolvers = { } }; ``` + +## [Mocking](features/mocking.html) + +Apollo Server 2 allows mocking of a schema with the `mocks` parameter in the constructor. The `mocks` parameter can be a boolean to enable the default mocking functions or an object to define custom mock functions by type. + +```js +const { ApolloServer } = require('apollo-server'); + +const typeDefs = ` +type Query { + hello: String + resolved: String +} +`; + +const resolvers = { + Query: { + resolved: () => 'Resolved', + }, +}; + +const mocks = { + Int: () => 6, + Float: () => 22.1, + String: () => 'Hello', +}; + +const server = new ApolloServer({ + typeDefs, + resolvers, + mocks, +}); + +server.listen().then(({ url }) => { + console.log(`🚀 Server ready at ${url}`) +}); +``` + +## Health Checks + +The default Apollo server provides a health check endpoint at `/.well-known/apollo/server-health` hat returns a 200 status code by default. If `onHealthCheck` is defined, the promise returned from the callback determines the status code. A successful resolution causes a 200 and rejection causes a 503. Health checks are often used by load balancers to determine if a server is available. + +```js +const { ApolloServer, gql } = require('apollo-server'); + +const typeDefs = gql``; +const resolvers = {}; + +const server = new ApolloServer({ + typeDefs, + resolvers, + //optional parameter + onHealthCheck: () => new Promise((resolve, reject) => { + //database check or other asynchronous action + }), +}); + + +server.listen().then(({ url }) => { + console.log(`🚀 Server ready at ${url}`); + console.log(`Try your health check at: ${url}/.well-known/apollo/server-health`); +}); +``` + From 0a552374c7f1368819a15570437aded84200b5e7 Mon Sep 17 00:00:00 2001 From: Evans Hauser Date: Wed, 9 May 2018 11:12:00 -0700 Subject: [PATCH 2/3] docs: add api reference link to delegateSchema in schema-delegation --- docs/source/features/schema-delegation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/features/schema-delegation.md b/docs/source/features/schema-delegation.md index 05defaf0..b59272f6 100644 --- a/docs/source/features/schema-delegation.md +++ b/docs/source/features/schema-delegation.md @@ -158,4 +158,4 @@ Delegation preserves aliases that are passed from the parent query. However that ## API -TODO point to the `delegateToSchema` api reference +Under the hood, Apollo server uses the `graphql-tools` library, which includes [`delegateToSchema`](../api/graphql-tools#delegateToSchema) by default. From 260061301c316dcc4afcdfd7fe693299133b9842 Mon Sep 17 00:00:00 2001 From: Evans Hauser Date: Wed, 9 May 2018 11:12:21 -0700 Subject: [PATCH 3/3] docs: add mls and nytimes blogs as case studies --- docs/source/why-apollo-server.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/source/why-apollo-server.md b/docs/source/why-apollo-server.md index 0bd629d4..91aa517d 100644 --- a/docs/source/why-apollo-server.md +++ b/docs/source/why-apollo-server.md @@ -54,6 +54,7 @@ Learning and implementing a new way to manage your data can be scary and risky. Companies ranging from enterprise to startups trust Apollo Server to power their most critical applications. If you'd like to learn more about how transitioning to GraphQL And Apollo improved their engineer's workflows and improved their products, check out these case studies: -TODO INSERT CASE STUDIES HERE +[Implementing GraphQL at Major League Soccer](https://labs.mlssoccer.com/implementing-graphql-at-major-league-soccer-ff0a002b20ca) +[The New York Times Now on Apollo](https://open.nytimes.com/the-new-york-times-now-on-apollo-b9a78a5038c) -If your company is using Apollo Server in production, we'd love to feature a case study on the Apollo blog! Please get in touch via Slack so we can learn more about how you're using Apollo. Alternatively, if you already have a blog post or a conference talk that you'd like to feature here, please send a [Pull Request](https://github.com/apollographql/apollo-server/pulls) \ No newline at end of file +If your company is using Apollo Server in production, we'd love to feature a case study on the Apollo blog! Please get in touch via Slack so we can learn more about how you're using Apollo. Alternatively, if you already have a blog post or a conference talk that you'd like to feature here, please send a [Pull Request](https://github.com/apollographql/apollo-server/pulls)