apollo-datasource-givefood

DataSource interface for GiveFood

Usage no npm install needed!

<script type="module">
  import apolloDatasourceGivefood from 'https://cdn.skypack.dev/apollo-datasource-givefood';
</script>

README

apollo-datasource-givefood

🥫 Apollo data source for GiveFood API.

Donate to Food Banks | Find Nearby Food Banks

Install

npm i apollo-datasource-givefood

Usage

The simplest way to get going is by using the DataSource directly.

import { GiveFoodDataSource } from 'apollo-datasource-givefood';

const server = new ApolloServer({
  typeDefs,
  resolvers,
  dataSources: () => ({
    givefood: new GiveFoodDataSource(),
  }),
});

An alternative is subclassing GiveFoodDataSource.

import { GiveFoodDataSource } from 'apollo-datasource-givefood';

class FoodBanks extends GiveFoodDataSource {
  constructor() {
    super();
    this.baseURL = '...';
  }

  getFoodBankBySlug(slug) {
    return this.getBySlug(slug);
  }
}

API

getAll

Example

const resolvers = {
  Query: {
    organisations: (_source, _args, { dataSoures: { givefood } }) =>
      givefood.getAll(),
  },
};

getBySlug(slug)

Get a food bank by slug, and all their needs and outlets.

Args

  • slug: A slug for an individual food bank. E.g. cramlington

Example

const resolvers = {
  Query: {
    foodbank: (_source, { slug }, { dataSoures: { givefood } }) =>
      givefood.getBySlug(slug),
  },
};

getByLatLng(lat, lng)

Get food banks near the provided lat/lng. Returns needs, along with distance in miles.

Args

  • lat (required): Latitude. E.g. 53.42
  • lng (required): Longitude. E.g. -2.55

Example

const resolvers = {
  Query: {
    search: (_source, { lat, lng }, { dataSoures: { givefood } }) =>
      givefood.getByLatLng(slug),
  },
};

getByAddress(address)

It's recommended you don't use this. Use getByLatLng where possible.

Use with caution, and expect slower response times.

Args

  • address (required): The address, e.g. 66 The Headrow Leeds LS1 8EQ

Example

const resolvers = {
  Query: {
    search: (_source, { address }, { dataSoures: { givefood } }) =>
      givefood.getByAddress(address),
  },
};