A GraphQL server exposes a GraphQL API, defines its schema, resolves client queries, and connects those resolvers to one or more data sources. A practical service can separate a REST-backed MovieAPI from the main server entry point. section 7.2.1
A small movie service divides the server into these responsibilities:
- The data source extends RESTDataSource and provides getMovies and getMovieById methods for the movies API. section 7.2.1
- The SDL declares Movie fields and Query operations, including movies and movie(movieId: Int!). section 7.2.1
- Resolvers map those operations to data-source methods, while server context makes MovieAPI available to each request. section 7.2.1
Starting a GraphQL movie service
Install dependencies and run the start:graphql:server script. The script starts both the movies API provider on port 3001 and the GraphQL server, which reports readiness at http://localhost:4000/. GraphQL Playground then provides an interactive browser interface for trying queries. section 7.2.2
Figure 7.3 GraphQL API at a glance with all the relevant files
Use the architecture figure to trace the consumer request through the GraphQL server, resolvers, and underlying data source. section 7.2.1
The server can also act as a contract-testing boundary. A consumer contract may verify the GraphQL endpoint directly while the movies API runs underneath; Pact verification publishes the provider result. section 7.4
