- add new endpoint /countries which should represent the data from the
countries
collection
Done.
- add new endpoint /countries which should represent the data from the
countries
collection
Done.
- add
countries
to /graphql endpoint
Done.
- add
country
tolocations.graphql.schema
as a representative ofcountry
information
Done. Please, check out the countries
service.
- add functionality to use
limit
andskip
as a parameters to fetch data through/graphql
endpoint
Done. Please, take a look at graphql.resolvers.queries.js.
- If you run the following query, location will always be
null
. Please figure out why this is happening. After you found out how this happens, please describe the reason and how you found the issue.
apartments(owner: $owner) {
items {
location {
title
}
}
}
}
This query is working now.
I had to go through dozens of publications on StackOverflow to solve this. It is in this post that I found the solution. The code below had query
spelled in lowercase, whereas it needed to be capitalized, like this:
location: apartment => {
return Locations.find({ **Query**: { _id: apartment.location } }).then(result => result);
}
To be honest with you this looks like a bug to me. Other than this assumption I really have no idea why capitalized Query
happened to solve the problem. I also assume we'd be better off using MongoDB's automatically created ObjectIds
instead of plain strings for _ids
in our collections.
- I took the liberty to see if I could create a GraphQL search functionality. So I:
- modified the schema
- added this package
feathers-mongodb-fuzzy-search
to implement Mongo's native search. - added text index for the
title
field in the locations, apartments and countries models.
You may use the query example below to test it.
{
search(title: "Studio") {
locations{
title
}
apartments{
title
}
countries{
title
}
}
}
###run
- edit /config/default.json
- provide mongodb connection path [mongodb://localhost:27017/assignment by default]
- npm install
- npm start
###current endpoints
/users
/apartments
/locations
/graphql
/graphiql
##What to do - for backend engineers
- add new endpoint /countries which should represent the data from the
countries
collection - add
countries
to /graphql endpoint - add
country
tolocations.graphql.schema
as a representative ofcountry
information - add functionality to use
limit
andskip
as a parameters to fetch data through/graphql
endpoint - If you run the following query, location will always be
null
. Please figure out why this is happening. After you found out how this happens, please describe the reason and how you found the issue.
apartments(owner: $owner) {
items {
location {
title
}
}
}
}