A GraphQL REST api wrapper example using NestJS and the News API
MIT License
Recently updated with nestjs
v6.11
Check out the repo's wiki for more information!
Came across the NestJS while experimenting with different Typescript based frameworks for GraphQL specific use cases.
If you don't have a NewsAPI account or api token available, please follow the steps in order to get the app running!
Go to your account page and copy your API Token
Create a new .env
file and add the following environment variable
echo export NEWS_API_KEY="CANTYOUSEEIMSELFAWAREWITHDIGITS3030" >> .env
Note: you can also just rename the
.env.sample
to.env
and replace the key there
NEWS_API_KEY="SOMEONEPLEASEHELPMEWITHDIGITS3030"
PORT=3000 # or your preferred port
git clone https://github.com/rajinwonderland/nest-graphql-newsapi
yarn
OR
npm i
yarn dev
The browser should then open automatically on to the graphql-playground page
Note: Default playground should be available 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": "API Keys",
"options": {
"pageSize": 5,
"page": 1
}
}
Results should end up showing in this sort of format
{
"data": {
"topHeadlines": {
"status": "ok",
"totalResults": 3,
"articles": [
{
"title": "Did you know API Keys are Self Aware?!",
"description": "Secure and treat your API Keys with respect",
"author": "YOUR API KEY... WITHDIGITS3030"
}
]
}
}
}
See the example on GraphQLBin
The updated version of this api uses a workaround to deploy using
zeit/now
. This is due to a downstream dependency issue on@nestjs/graphql
see zeit/now #3115 and TrilonIO/zeit-now-nestjs #2)
Feel free to reach out with via Issues, Twitter and/or PRs with a tag @rajinwonderland