This project is a GraphQL API wrapper for the Wikipedia API.
Author: Jordan Levesque - @KotaHusky
License: MIT
- Project Requirements
- Usage
- GraphQL
- Nx
- Future Improvements and Production Considerations
- References & Resources

yarn install
yarn serve
yarn serve:docker
or
make -f apps/Makefile docker-all
Once the server is running, you can explore the GraphQL API using the Sandbox at http://localhost:4000/
.
The Sandbox allows you to:
- View and reference the GraphQL schema
- Create, run, and manage GraphQL queries
- View schema diff (if logged in and enabled on Apollo Studio)
Here's an example query for the getWikipediaPageByMonth GraphQL query:
query GetWikipediaPageByMonth($title: String!, $targetMonth: String!) {
getWikipediaPageByMonth(title: $title, targetMonth: $targetMonth) {
title
totalViews
}
}
In this example, the query takes two variables: title
and targetMonth
. The getWikipediaPageByMonth
field returns the title
and totalViews
fields for a given Wikipedia page.
Using curl, you can query the server like so:
curl --request POST \
--url http://localhost:4000/ \
--header 'Content-Type: application/json' \
--header 'User-Agent: insomnia/8.2.0' \
--data '{"query":"query GetWikipediaPageByMonth($title: String!, $targetMonth: String!) {\n getWikipediaPageByMonth(title: $title, targetMonth: $targetMonth) {\n title\n totalViews\n }\n}","operationName":"GetWikipediaPageByMonth","variables":{"title":"Husky","targetMonth":"2023-09"}}'
GraphQL is a query language for APIs that allows clients to request exactly the data they need, while enabling the server to aggregate data from multiple sources with a strongly-typed schema. See here for more information.
- Self-Documenting via strong types, docstrings, and Introspection
- No over- or under-fetching
- Easily extensible schema
TypeDefs in GraphQL are similar to interfaces in TypeScript. They define the shape of the data that can be queried from the GraphQL API.
Resolvers in GraphQL are functions that return data for a given field in the GraphQL schema.
TypeDefs and Resolvers for a given schema subject are stored in .type.ts
files in the src/graphql/types
directory. The GraphQL schema is generated on server start using the makeExecutableSchema
function from @graphql-tools/schema
.
Nx is a set of extensible dev tools for monorepos and standalone projects. See here for more information.
- Create new projects, apps, libraries, and components with generators like
nx g @nrwl/react:component my-component
- Run tasks only for affected projects with
nx affected:test
- Cache results and run tasks in parallel for faster execution
- Enforce and visualize boundaries between projects with
nx dep-graph
Perform a dry-run of a generating command with --dry-run
Create a new Nx workspace:
yarn create nx-workspace grow-therapy --package-manager=yarn --workspaceType=integrated --nx-cloud=false --preset=apps
Create a new Nx application:
yarn nx g @nx/node:application --name=api --bundler=esbuild --directory=apps --framework=express --docker=true --projectNameAndRootFormat=as-provided
Handle cases where:
- the Wikipedia API returns an empty result for a given page, month, or both.
- the Wikipedia API returns an error.
- the Wikipedia API returns a result with a different schema than expected.
- the Wikipedia API enforces a rate limit.
- the GraphQL API recieves a request with an invalid query or variables.
- Add a cache layer to reduce the number of requests to the Wikipedia API. See here.
- Add a load balancer to handle multiple requests to the GraphQL API.
- Add query complexity analysis to prevent expensive queries from being executed. See here.
- Add authentication and authorization for role-based access to GQL operations. See here.
- Add SSL termination to the GraphQL API. See here.
- Use organization docker images instead of public images.
- Add logging to the GraphQL API. See here.
- Add full validation suite (lint, test, build) using Apollo Server's executeOperation and Nx's affected.
- Add CICD pipeline to build and deploy the GraphQL API via GitHub Actions.
- Add monitoring to the GraphQL API. See here.
- Integrate with other data sources as needed.
- Share ownership by federating into a supergraph. See here.
- Familiarize team with the Principles of GraphQL. See here.