A GraphQL REST wrapper example using the NewsAPI build with the NestJS Framework
Check out the repo's wiki for more information!
Recently came across the NestJS while experimenting with different Typescript based frameworks for GraphQL specific use cases.
Official NestJS Documentation for use with GraphQL
Official NestJS GraphQL example
If you don't have a NewsAPI account or api token available, please follow the steps in order to get the app running!
Login or Sign Up for NewsAPI
Go to your account page and copy your API Token
Create a new .env
file and add the following environment variable
Note: you can rename the
.env.sample
to.env
for the same results
NEWS_API_KEY="YOURAPIKEYHERE"
PORT=3000 # or your preferred port
git clone https://github.com/rajinwonderland/nest-graphql-newsapi
yarn
OR
npm install
yarn dev
OR
npm run dev
The browser should then open automatically on to the graphql-playground page
Note: Default playground should be avaialble at http://localhost:3000/graphql
Unless you changed the
PORT
environment variable in which case your playground should be hosted at http://localhost:${YOUR_PORT}/graphql
Query for returning TopHeadlines
query TopHeadlines($query: String!, $options: HeadlineInput) {
topHeadlines(q: $query, options: $options) {
status
totalResults
articles {
title
description
author
}
}
}
Variables for our TopHeadlines
Query
{
"query": "Starbucks",
"options": {
"pageSize": 5,
"page": 1
}
}
Results should end up showing in this sort of format
{
"data": {
"topHeadlines": {
"status": "ok",
"totalResults": 3,
"articles": [
{
"title": "Starbucks to report earnings after the bell",
"description": "Starbucks will report its first-quarter earnings and revenue after the bell Thursday.",
"author": "Amelia Lucas"
}
]
}
}
}
See the example on GraphQLBin
- NestJS - A progressive Node.js framework for building efficient, reliable and scalable server-side applications.
- NewsAPI - Up-to-date news headlines and metadata in JSON from 70+ popular news sites.
- newsapi- A node interface for NewsAPI.
- GraphQL a query language for your API
- Typescript a superset of JavaScript that compiles to clean JavaScript output
- CodeSandbox is an online code editor with a focus on creating and sharing web application projects.
- Apollo Server 2 the best way to quickly build a production-ready, self-documenting API for GraphQL clients, using data from any source.
- GraphQL-Playground a GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration).
If anyone is looking for some support (i.e either an example, or an open-source project) feel free to reach out to me and I'll do my best to help!
Powered by NewsAPI.org
Made with ❤️ by Novvum