Skip to content

A GraphQL REST api wrapper example using NestJS and the News API

License

Notifications You must be signed in to change notification settings

Novvum/nest-graphql-newsapi

 
 

Repository files navigation

Nest Logo

A GraphQL REST wrapper example using the NewsAPI build with the NestJS Framework

Check out the repo's wiki for more information!

Demos



Edit nest-graphql-example

Background

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

Prerequisites

If you don't have a NewsAPI account or api token available, please follow the steps in order to get the app running!

Step 1:

Login or Sign Up for NewsAPI

Step 2:

Go to your account page and copy your API Token

Step 3:

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

Installation

Clone the repo!

git clone https://github.com/rajinwonderland/nest-graphql-newsapi

Install dependencies

yarn

OR

npm install

Start the App

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

Example

Top Headlines Example

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

Built With

  • 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).

Here to Help!

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

About

A GraphQL REST api wrapper example using NestJS and the News API

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%