Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mathieucaroff/derpibooru-graphql

A GraphQL overlay on the Derpibooru REST API
https://github.com/mathieucaroff/derpibooru-graphql

Last synced: 5 days ago
JSON representation

A GraphQL overlay on the Derpibooru REST API

Awesome Lists containing this project

README

        

# Derpibooru GraphQL API

Built on top of the Rest API

## Trying out the library

These steps will allow you to run graphql in the GraphQL Playground.

1. Clone the repository

```bash
git clone ...
cd ...
```

2. Install dependencies

With yarn:

```bash
yarn install
yarn tsc
yarn playground
```

With npm:

```bash
npm install
npm run compile
npm run playground
```

3. Go to `localhost:4000/playground`

4. Enjoy ^^

## Using the library in your project

/!\ WIP /!\ Package not yet published

Install with `npm install --save derpiboru-graphql node-fetch`
or `yarn add derpiboru-graphql node-fetch`

Then use:

```js
import * as fetch from 'node-fetch'
import { DerpibooruGraphql } from 'derpibooru-graphql'

let { gql, query } = new DerpibooruGraphql({ fetch })

// The recommanded way: use the gql tag //
let variables = {}
let result = await gql`
query {
search(query: "cute", per_page: 50) {
total
search {
faves
file_name
score
representations {
full
}
}
}
}
`(varialbles)

console.log(result)

// If you like to have your queries in separate files, use the query function //
// let graphqlQueryText = await fs.promises.readFile('derpiboru-query.gql', 'utf-8')
let graphqlQueryText = `
query {
search(query: "cute", per_page: 50) {
total
search {
faves
file_name
score
representations {
full
}
}
}
}
`

expect(await query(graphqlQueryText)).toEqual(result)
```