GraphQL implementation of data.gov.uk API
data source: 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
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
{
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 |
{
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 |
{
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 |
{
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 |
{
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 |
{
ferrys(postcode: "L1 0AA", distance:10){
name,
ospoint {
type
coordinates
}
latlong {
type
coordinates
},
distance,
ferrycode,
atcocode
}
}
Airports Information
list of airport's and codes
{
airports{
name,
iatacode,
atcocode
}
}