- backend implementation location query

This commit is contained in:
Ulf Gebhardt 2021-01-30 00:18:26 +01:00
parent 0d3863fb9a
commit d9e553b800
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD
4 changed files with 31 additions and 0 deletions

View File

@ -121,6 +121,7 @@ export default shield(
userData: isAuthenticated,
MyInviteCodes: isAuthenticated,
isValidInviteCode: allow,
queryLocations: isAuthenticated,
},
Mutation: {
'*': deny,

View File

@ -1,4 +1,6 @@
import { UserInputError } from 'apollo-server'
import Resolver from './helpers/Resolver'
import { queryLocations } from './users/location'
export default {
Location: {
@ -16,4 +18,13 @@ export default {
],
}),
},
Query: {
queryLocations: async (object, args, context, resolveInfo) => {
try {
return queryLocations(args)
} catch (e) {
throw new UserInputError(e.message)
}
},
},
}

View File

@ -137,4 +137,14 @@ const createOrUpdateLocations = async (userId, locationName, session) => {
})
}
export const queryLocations = async ({place, lang}) => {
const res = await fetch(`https://api.mapbox.com/geocoding/v5/mapbox.places/${place}.json?access_token=${CONFIG.MAPBOX_TOKEN}&types=region,place,country&language=${lang}`)
console.log(res)
if (!res || !res.features) {
// Return empty array if no location found or error occurred
return []
}
return res.features
}
export default createOrUpdateLocations

View File

@ -16,3 +16,12 @@ type Location {
parent: Location @cypher(statement: "MATCH (this)-[:IS_IN]->(l:Location) RETURN l")
}
type Location2 {
id: ID!
place_name: String!
}
type Query {
queryLocations(place: String!, lang: String!): [Location2]!
}