Talks

GraphQL

Robert is a Ruby developer at GitHub, focused on the GraphQL API. In his free time, he likes spending time with his family, reading about programming language design, and doing upholstery projects.

Balkan Ruby 2018

00:00:14.740 Hi everyone, thanks! My name is Robert Mosolgo, and today I'm going to talk to you about GraphQL. Before we dive into that, I wanted to introduce myself and share a bit about my recent projects.
00:00:21.439 One of my hobbies is sewing, which might be an unusual pastime for a programmer, but it's genuinely growing on me. I love working with my sewing machine. It's a mechanical device, and when you work with it, you can appreciate all the different buttons and sliders. You can feel the fabric flowing through it.
00:00:35.860 Here are some of my recent projects. Above the window, you can see the curtains I made, which required lining up the pattern. Much like programming languages, sewing requires attention to details and precision. One of my favorite tools is a ruffler attachment, which helps make ruffles in fabric. Every time the machine operates, it creates beautiful folds in the fabric, and I find it fascinating how mechanics work.
00:00:56.930 Here's a chair I got from Craigslist. The fabric was quite hideous, and it had a peculiar smell. I decided to disassemble it and reassemble it after cleaning. While peeling back the layers, I discovered different materials including polyester padding and horse hair. It was quite an experience uncovering the history behind the chair.
00:01:13.650 I appreciate the personal aspect of these sewing projects and how they connect with the craftsmanship of the past. Yesterday, I walked around the city center, visiting beautiful churches and historical ruins. They remind me of how intertwined history and craftsmanship are, whether in sewing or architecture.
00:01:29.990 Now, regarding my sewing machine, I like to use my grandmother's old machine. It’s a connection to her that I cherish. Wrongly I think about all the time I had to learn and appreciate the mechanics behind every stitch. Sharing a machine with someone like that makes the experience even more meaningful.
00:01:54.990 That’s a bit about myself, and now let’s transition to the topic at hand—GraphQL. I am one of the maintainers of GraphQL Ruby, and I’ll be discussing design mistakes we encounter in these systems.
00:02:00.620 First, I will introduce what GraphQL is. GraphQL is an API system that provides an efficient way for clients to request data from a server. Whether it’s a website or a mobile app, GraphQL allows those clients to pull the information they need from different data sources.
00:02:18.859 In GraphQL, when a client sends a request for some data, it uses a query language that enables precise data fetching. The server processes this request, executes the query, and responds with a structured result that the client can easily use. Understanding both parts—query language and runtime—gives us insight into the GraphQL ecosystem.
00:02:44.169 Let’s start with the query language. For example, if you want to find the first five users, you can request their login usernames and repositories. With GraphQL, you can make precise requests, similar to the SELECT statement in SQL. The curly braces you use in GraphQL represent the structure of the data you want to retrieve.
00:03:06.450 After sending a request, if the resulting object has nested fields, you can ask for those, too. This flexibility allows clients to specify exactly what data they need, which minimizes over-fetching and under-fetching.
00:03:34.570 From a runtime perspective, when executing a GraphQL query, we start building our JSON response from the main selection and move through the fields present in the request. Each field corresponds to a key in the returned data, and for more complex fields, you’ll invoke 'resolver functions' that define how to fetch that data from your application.
00:04:02.330 As an example, when querying a repository, you might ask for the repository name along with the programming languages it uses. Each field you request will invoke the associated resolver function, returning the data needed in the structured response.
00:04:25.670 GraphQL also has a schema that defines all the types and fields available in your application. This type system is significant as it checks and validates the requests, ensuring that anything returned from a field is according to expectation. For instance, a repository field might always return a string, whereas the languages field returns a list of objects.
00:04:57.630 The querying also reveals relationships between data. This understanding opens up opportunities for developers to experiment with their application's approach to feeding data and redefining their APIs for efficiency. As we create applications, understanding the schema allows us to maintain clean connections to the data.
00:05:34.750 Lastly, the documentation aspect of GraphQL enables developers to have immediate insight into the possibilities of querying. The graphical interface (GraphiQL) is a powerful tool that lets you visualize the schema, providing valuable documentation and interactivity.
00:06:12.210 Going back to design mistakes, it’s crucial to learn from our early endeavors with GraphQL in Ruby. When integrating concepts from GraphQL, some mistakes can arise due to the differences in paradigms between Ruby and GraphQL’s operational methodologies.
00:06:44.830 For instance, I initially explored how to use anonymous functions in Ruby within our resolver functions. This approach was not only unfamiliar but raised issues such as debugging complexity and performance. Furthermore, the idea of making everything seamless through vague resolutions sometimes hinders code clarity.
00:07:26.310 Moreover, the way I scripted interactions according to GraphQL specifications sometimes backfired. I realized that relying too heavily on extensive scripts could lead to less flexibility in our system as we work towards building efficient and effective APIs.
00:08:05.500 Throughout my journey with designing a Ruby implementation of GraphQL, I recognized the importance of agreeing on standard practices early on. As we addressed issues actively, we could build a more robust framework fostering collaboration and easier maintenance.
00:08:45.650 Indeed, I have learned that thinking of design paradigms as integral components of our work can yield better results. Transitioning Ruby paradigms into GraphQL development has helped foster an organized approach while addressing various dilemmas.
00:09:26.460 As I wrap up, I'd highly recommend exploring GraphQL’s documentation, as it provides foundational support for any developer looking to implement these concepts. Furthermore, it’s crucial to use best practices, as understanding connectivity and code behavior makes for an efficient design.
00:10:00.540 In conclusion, while pursuing the design of systems based on GraphQL principles, always emphasize clarity and familiarity with Ruby’s workflows. An engaged approach, alongside structured methodologies, makes it easier for developers to experiment and innovate.
00:10:35.580 Thank you for your time. If you have any questions, feel free to reach out, and I’m happy to discuss more on these topics. I also brought some stickers with the GraphQL logo. So if you come up to me, even if you just want to chat, feel free! Thanks again!