Giter VIP home page Giter VIP logo

nest-graphql-newsapi's Introduction

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

nest-graphql-newsapi's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.