Tag Archives: graphql

Using GraphQL with Mendeley

I was snooping around on GitHub a few weeks back looking for repositories that have used the Mendeley API. I was surprised by how many I found. Unfortunately, some are obsolete and no longer work.  

I did find one gem though called GraphQL-Mendeley. GraphQL is a query language that allows client developers to easily ask for data from a server. It was built by Facebook and came about when they were rewriting their mobile clients. Primarily it allowed product developers to be able to build things quickly and easily by providing a consistent query language. Think about how large the Facebook data lake is. Developers could now be selective in exactly what data they required. You are no longer constrained by some pre-determined server view that an API provides. You can execute one network call and be very precise about what you want or you can or you can be greedy and for multiple unrelated objects in one call.

REST APIs do have overheads in that writing APIs is notoriously difficult and writing a good one that fit your product needs, is easy to evolve and services multiple clients is just downright hard.

GraphQL is independent of platforms and data sources so you can run queries using your favourite languages and platform rather easily. It’s not concerned with preparing data for parsing or having to write lots of code to merge multiple unrelated datasets. It’s almost like an API but for data and a lot less complicated.  

Researchers often work with data that  is flat and unstructured. I could see benefits for organisations who have large datasets (like us) in providing the data via GraphQL so clients can just ask for the data they need.  

Checkout the GitHub example and run it for yourself. Below you will see a screenshot of a query that I ran to find the name of people in the group identified with id ‘e3630413-abd9-3308-8937-c5f119c17a28

 

graphql

If you had to do this using from code and consuming the APIs that we currently have then you would first make a call to Groups such as:  

https://api.mendeley.com/groups/e3630413-abd9-3308-8937-c5f119c17a28/members

This returns the following JSON response.  

[
 {
   “profile_id”: “75375001-76bc-3c41-a0e8-3c88a4829918”,
   “joined”: “2013-01-26T19:36:40.000Z”,
   “role”: “normal”
 },
 {
   “profile_id”: “1c3ac854-1c3c-3202-9753-93b69dd1566f”,
   “joined”: “2012-06-19T15:11:34.000Z”,
   “role”: “normal”
  ]

]

 

Your code would then have to parse the JSON, iterate over the response and for each of the profile ids you would make a call to Profiles to retrieve the id and name details:  

https://api.mendeley.com/profiles/75375001-76bc-3c41-a0e8-3c88a4829918

Writing less code is always a good thing so it’s going to be interesting to see how this gets adopted.  

On a site note we love to see what cool things you build with the Mendeley API. Please get in touch and let me know what you have done. We are working to get external libraries and projects listed on our developer portal – email joyce.stack@mendeley.com.