@keystone-next/fields-location-google-legacy

3.3.4 • Public • Published

LocationGoogle

The LocationGoogle Field Type enables storing data from the Google Maps API.

Usage

const { LocationGoogle } = require('@keystone-next/fields-location-google-legacy');
const { Keystone } = require('@keystone-next/keystone-legacy');

const keystone = new Keystone({...});

keystone.createList('Event', {
  fields: {
    venue: {
      type: LocationGoogle,
      googleMapsKey: 'GOOGLE_MAPS_KEY',
    },
  },
});

GraphQL

query {
  allEvents {
    venue {
      id
      googlePlaceID
      formattedAddress
      lat
      lng
    }
  }
}

Will yield:

{
  "data": {
    "allEvents": [
      {
        "venue": {
          "id": "1",
          "googlePlaceID": "ChIJOza7MD-uEmsRrf4t12uji6Y",
          "formattedAddress": "10/191 Clarence St, Sydney NSW 2000, Australia",
          "lat": -33.869374,
          "lng": 151.205097
        }
      }
    ]
  }
}

Mutations

To create a Location, pass the Google place_id for the desired field path.

mutation {
  createEvent(data: { venue: "ChIJOza7MD-uEmsRrf4t12uji6Y" }) {
    venue {
      id
      googlePlaceID
      formattedAddress
      lat
      lng
    }
  }
}

Results in:

{
  "createEvent": {
    "venue": {
      "id": "1",
      "googlePlaceID": "ChIJOza7MD-uEmsRrf4t12uji6Y",
      "formattedAddress": "10/191 Clarence St, Sydney NSW 2000, Australia",
      "lat": -33.869374,
      "lng": 151.205097
    }
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @keystone-next/fields-location-google-legacy

Weekly Downloads

1

Version

3.3.4

License

MIT

Unpacked Size

70.5 kB

Total Files

29

Last publish

Collaborators

  • emmatown
  • jedwatson
  • bladey