# data-gov-uk-graphql

> GraphQL Wraparound data.uk.gov api data

Latest version **0.0.4** (published 2017-01-06) · 0 weekly downloads

## Install

```sh
npm install data-gov-uk-graphql
pnpm add data-gov-uk-graphql
yarn add data-gov-uk-graphql
bun add data-gov-uk-graphql
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2017-01-06 |
| First published | 2017-01-05 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | andyfen |

## Links

- npm: https://www.npmjs.com/package/data-gov-uk-graphql
- Repository: https://github.com/andyfen/data.gov.uk-graphql
- Homepage: https://github.com/andyfen/data.gov.uk-graphql#readme
- Issues: https://github.com/andyfen/data.gov.uk-graphql/issues
- npm.io page: https://npm.io/package/data-gov-uk-graphql

## Dependencies (4)

- [months](https://npm.io/package/months.md) ^1.0.1
- [graphql](https://npm.io/package/graphql.md) 0.7.0
- [request](https://npm.io/package/request.md) ^2.79.0
- [request-promise](https://npm.io/package/request-promise.md) ^4.1.1

## Recent versions

- 0.0.4 (latest) — 2017-01-06
- 0.0.3 — 2017-01-06
- 0.0.2 — 2017-01-05
- 0.0.1 — 2017-01-05

## README

# GraphQL implementation of data.gov.uk API

data source: [https://data.gov.uk/data/api/](https://data.gov.uk/data/api/).

### Overview
A wraparound of various datasets provided by data.gov.uk ranging from crime data, scheduled roadwork's, to hospital information. Associated responses follow close to the raw data and are mapped into the graphql type system.


All requests are generated by relevant query parameters to the data sets such as; post code, longitude / latitude etc.


All queries are modular GraphQLObjectType’s and can be simply bolted on to any existing GraphQL Schema. Resolve data fetching functions are self contained within the modules.


##### Available  Data Sets
* Crime Data (monthly location based street crime stats)
* Hospital Information (location based hospital services)
* Pharmacy Information (local pharmacies info)
* RoadWorks Information (existing and scheduled roadworks based on road)
* Ferry Port Information (information on ferry ports within n miles of location)
* Airports Information (list of airport's and codes)

##### Caveats
Requests are made to the data source api at data.gov.uk/api  response's for some of the data sets can be slow.

### Install
```
npm install data-gov-uk-graphql
```

[Demo Playground](https://data-gov-uk-graphql.herokuapp.com/?query=%7B%0A%20%20crimes(%0A%20%20%20%20lng%3A-1.131592%2C%0A%20%20%20%20lat%3A52.629729%2C%0A%20%20%20%20year%3A2015%2C%0A%20%20%20%20month%3A%22jun%22%2C%0A%20%20)%7B%0A%20%20%20%20id%2C%0A%20%20%20%20category%2C%0A%20%20%20%20outcome_status%7B%0A%20%20%20%20%20%20category%2C%0A%20%20%20%20%20%20date%0A%20%20%20%20%7D%2C%0A%20%20%20%20month%2C%0A%20%20%20%20persistent_id%2C%0A%20%20%20%20location_type%2C%0A%20%20%20%20location%7B%0A%20%20%20%20%20%20latitude%2C%0A%20%20%20%20%20%20longitude%2C%0A%20%20%20%20%20%20street%7B%0A%20%20%20%20%20%20%20%20id%2C%0A%20%20%20%20%20%20%20%20name%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D)



### Usage
import specific required data types
```
import {
    CrimesType,
    HospitalsType,
    PharmacysType,
    RoadWorksType,
    FerrysType,
    AirportsType
} from 'data-gov-uk-graphql'
```



#### Add type's to the schema
```
const QueryType = new GraphQLObjectType({
  name: 'Query',
  description: 'The root query..',
  fields: () => ({
    crimes: CrimesType,
    hospitals: HospitalsType,
    pharmacys: PharmacysType,
    roadworks: RoadWorksType,
    airports: AirportsType,
    ferrys: FerrysType,
  }),
});

export const Schema = new GraphQLSchema({
  query: QueryType,
});
```



#### Basic Example Query
Get local pharmacy information based on a partial post code

[Demo](https://data-gov-uk-graphql.herokuapp.com/?query=%7B%0A%20%20pharmacys(partial_postcode%3A%22m21%22)%7B%0A%20%20%20%20name%2C%0A%20%20%20%20address1%2C%0A%20%20%20%20city%2C%0A%20%20%20%20postcode%0A%20%20%7D%0A%7D)


```
{
  pharmacys(partial_postcode:"m21"){
    name,
    address1,
    city,
    postcode
  }
}
```



.
# API Documentation




### Crime Data

##### Required Request Variables

| Variable | Type | Description |
| :------| :-----------| :-----------|
| month   | String | Shorthand month jan, feb |
| lat  | Float | latitude |
| lng   | Float | longitude |
| year   | Int | year  |


[Demo](https://data-gov-uk-graphql.herokuapp.com/?query=%7B%0A%20%20crimes(%0A%20%20%20%20lng%3A-1.131592%2C%0A%20%20%20%20lat%3A52.629729%2C%0A%20%20%20%20year%3A2015%2C%0A%20%20%20%20month%3A%22jun%22%2C%0A%20%20)%7B%0A%20%20%20%20id%2C%0A%20%20%20%20category%2C%0A%20%20%20%20outcome_status%7B%0A%20%20%20%20%20%20category%2C%0A%20%20%20%20%20%20date%0A%20%20%20%20%7D%2C%0A%20%20%20%20month%2C%0A%20%20%20%20persistent_id%2C%0A%20%20%20%20location_type%2C%0A%20%20%20%20location%7B%0A%20%20%20%20%20%20latitude%2C%0A%20%20%20%20%20%20longitude%2C%0A%20%20%20%20%20%20street%7B%0A%20%20%20%20%20%20%20%20id%2C%0A%20%20%20%20%20%20%20%20name%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D)

```
{
  crimes(
    lng:-1.131592,
    lat:52.629729,
    year:2015,
    month:"jun",
  ){
    id,
    category,
    outcome_status{
      category,
      date
    },
    month,
    persistent_id,
    location_type,
    location{
      latitude,
      longitude,
      street{
        id,
        name
      }
    }
  }
}
```

### Hospital Information
location based hospital services
##### Required Request Variables

| Variable | Type | Description |
| :------| :-----------| :-----------|
| lat  | Float | latitude |
| lng   | Float | longitude |


[Demo](https://data-gov-uk-graphql.herokuapp.com/?query=%7B%0A%09hospitals(lat%3A53.1%2C%20lon%3A3.0)%7B%0A%20%20%20%20%20%20%20%20postcode%2C%0A%20%20%20%20%20%20%20%20name%2C%0A%20%20%20%20%20%20%20%20phone%2C%0A%20%20%20%20%20%20%20%20organisation_code%2C%0A%20%20%20%20%20%20%20%20website%0A%20%20%20%20%7D%0A%7D)

```
{
	hospitals(lat:53.1, lon:3.0){
        postcode,
        name,
        phone,
        organisation_code,
        website
    }
}
```


### Pharmacy Information
local pharmacies info
##### Required Request Variables

| Variable | Type | Description |
| :------| :-----------| :-----------|
| partial_postcode  | String | partial postcode first half |


[Demo](https://data-gov-uk-graphql.herokuapp.com/?query=%7B%0A%20%20pharmacys(partial_postcode%3A%22m1%22)%7B%0A%20%20%20%20name%2C%0A%20%20%20%20address1%2C%0A%20%20%20%20city%2C%0A%20%20%20%20postcode%2C%0A%20%20%7D%0A%7D)
```
{
  pharmacys(partial_postcode:"m1"){
    name,
    address1,
    city,
    postcode,
  }
}
```



### RoadWorks Information
existing and scheduled roadworks based on road
##### Required Request Variables

| Variable | Type | Description |
| :------| :-----------| :-----------|
| road  | String | road / motorway  |


[Demo](https://data-gov-uk-graphql.herokuapp.com/?query=%7B%0A%20%20roadworks(road%3A%22M1%22)%7B%0A%20%20%20%20traffic_management%2C%0A%20%20%20%20status%2C%0A%20%20%20%20start_date%2C%0A%20%20%20%20road%2C%0A%20%20%20%20location%2C%0A%20%20%20%20local_authority%2C%0A%20%20%20%20expected_delay%2C%0A%20%20%20%20end_date%2C%0A%20%20%20%20description%0A%20%20%7D%0A%7D)
```
{
  roadworks(road:"M1"){
    traffic_management,
    status,
    start_date,
    road,
    location,
    local_authority,
    expected_delay,
    end_date,
    description
  }
}
```



### Ferry Port Information
information on ferry ports within n miles of location
##### Required Request Variables

| Variable | Type | Description |
| :------| :-----------| :-----------|
| postcode  | String | full postcode  |
| distance  | Int | within n miles from postcode location  |


[Demo](https://data-gov-uk-graphql.herokuapp.com/?query=%7B%0A%20%20ferrys(postcode%3A%20%22L1%200AA%22%2C%20distance%3A10)%7B%0A%20%20%20%20name%2C%0A%20%20%20%20ospoint%20%7B%0A%20%20%20%20%20%20type%0A%20%20%20%20%20%20coordinates%0A%20%20%20%20%7D%0A%20%20%20%20latlong%20%7B%0A%20%20%20%20%20%20type%0A%20%20%20%20%20%20coordinates%0A%20%20%20%20%7D%2C%0A%20%20%20%20distance%2C%0A%20%20%20%20ferrycode%2C%0A%20%20%20%20atcocode%0A%20%20%7D%0A%7D)
```
{
  ferrys(postcode: "L1 0AA", distance:10){
    name,
    ospoint {
      type
      coordinates
    }
    latlong {
      type
      coordinates
    },
    distance,
    ferrycode,
    atcocode
  }
}
```




### Airports Information
list of airport's and codes


[Demo](https://data-gov-uk-graphql.herokuapp.com/?query=%7B%0A%20%20airports%7B%0A%20%20%20%20name%2C%0A%20%20%20%20iatacode%2C%0A%20%20%20%20atcocode%0A%20%20%7D%0A%7D)
```
{
  airports{
    name,
    iatacode,
    atcocode
  }
}
```

---
_Source: https://npm.io/package/data-gov-uk-graphql · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
