Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GraphQL endpoint using openapi-to-graphql #47

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,49 @@
# Google Play API

![GitHub tag (latest SemVer pre-release)](https://img.shields.io/github/v/tag/srikanthlogic/google-play-api?include_prereleases&label=version) [![Newman Run](https://github.com/srikanthlogic/google-play-api/actions/workflows/newman.yml/badge.svg)](https://github.com/srikanthlogic/google-play-api/actions/workflows/newman.yml) [![API Documentation](https://img.shields.io/badge/api-documentation-brightgreen)](https://gplayapi.cashlessconsumer.in/) [![Deploy](https://button.deta.dev/1/svg)](https://deta.space/discovery/@cashlessconsumer/googleplayapi)

Google Play API is a REST API wrapper originally built on top of [google-play-scraper](https://github.com/facundoolano/google-play-scraper) by [Facundoolano](https://github.com/facundoolano) to fetch metadata from [Google Play](https://en.wikipedia.org/wiki/Google_Play). This repository extends it and adds additional endpoints.

## API Server

The API Server is built on ExpressJS and self contains API documentation.

To run locally:
* Clone the repository and run
* `npm install`
* `npm run generateoas` - Generates the OpenAPI specification
* `npm start`

- Clone the repository and run
- `npm install`
- `npm run generateoas` - Generates the OpenAPI specification
- `npm start`

### Deployments

The API Server can be installed as a [Deta app](https://deta.space/discovery/@cashlessconsumer/googleplayapi).

### Roadmap
* [ ] Expose more endpoints helping towards archiving.
* [ ] Support Global options
* [X] Deta Support. [#34](https://github.com/srikanthlogic/google-play-api/issues/34)
* [X] Support Lists [#36](https://github.com/srikanthlogic/google-play-api/issues/36)
* [X] Support privacy friendly reviews extraction [#40](https://github.com/srikanthlogic/google-play-api/issues/40)

- [ ] Expose more endpoints helping towards archiving.
- [ ] Support Global options
- [x] Deta Support. [#34](https://github.com/srikanthlogic/google-play-api/issues/34)
- [x] Support Lists [#36](https://github.com/srikanthlogic/google-play-api/issues/36)
- [x] Support privacy friendly reviews extraction [#40](https://github.com/srikanthlogic/google-play-api/issues/40)
- [x] Support GraphQL endpoint. [#45](https://github.com/srikanthlogic/google-play-api/issues/45)

### GraphQL Endpoint

The API now supports a GraphQL endpoint at `/graphql`. This endpoint allows for more flexible queries than the REST API.

To query the GraphQL endpoint, send a POST request with a JSON body containing your GraphQL query. For example:

```json
{
"query": "{ app(id: \"com.example.app\") { title, developer } }"
}
```

This will return the title and developer of the app with the id "com.example.app".

The data available for querying includes all the data available through the REST API, such as app details, reviews, and similar apps.

## Disclaimer
* Google Play data is bound by terms of Google. We believe - the data in the Play Store ecosystem, belong to people (Users) and hence must be available to them in form that will allow them to make best use of.

- Google Play data is bound by terms of Google. We believe - the data in the Play Store ecosystem, belong to people (Users) and hence must be available to them in form that will allow them to make best use of.
20 changes: 20 additions & 0 deletions lib/graphql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import express from 'express';
import { graphqlHTTP } from 'express-graphql';
import { createGraphQLSchema } from 'openapi-to-graphql';
import path from 'path';
import fs from 'fs';

// Load the OpenAPI specification
const openApiSpec = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../openapi/swagger.json'), 'utf8'));

// Generate the GraphQL schema from the OpenAPI specification
const { schema } = createGraphQLSchema(openApiSpec);

// Create a new GraphQL server
const graphqlServer = express();
graphqlServer.use('/graphql', graphqlHTTP({
schema: schema,
graphiql: true,
}));

export default graphqlServer;
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Express from 'express';
import gplay from 'google-play-scraper';
import path from 'path';
import qs from 'querystring';
import graphqlServer from './graphql';

const router = Express.Router();

Expand Down Expand Up @@ -260,4 +261,7 @@ function errorHandler(err, req, res, next) {

router.use(errorHandler);

// Use the GraphQL server as middleware
router.use('/graphql', graphqlServer);

export default router;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"google-play-scraper": "^10.0.0",
"morgan": "^1.10.0",
"postman-to-openapi": "^3.0.1",
"swagger-ui-express": "^5.0.0"
"swagger-ui-express": "^5.0.0",
"openapi-to-graphql": "^2.2.2"
},
"devDependencies": {
"eslint": "^8.50.0",
Expand Down
Loading