LAST CHANCE: Save 50% on all my Swift books and bundles! >>

How to integrate GraphQL with your iOS app

Recorded – watch the full episode on YouTube.

Is there anything Apple developers can do that will make integrating GraphQL easier?

Ellen Shapiro: Honestly I think a lot of the stuff that would make integrating GraphQL easier is stuff that applies much more broadly to code generation. I think a lot of the stuff that makes this setup a lot more annoying is basically the absence of Xcode plugins. There's Xcode extensions, which have a very, very limited amount that they can do.

“It's very different from just being able to shove everything into a database, the way that you can from a REST end point where you know exactly what you're getting back.”

Back in the day, I wrote an extension for Xcode called Xcode auto basher, where you could basically say, “okay, watch this directory or watch this file. Any time it changes, run this script.” It was nice because I could use that to automatically regenerate all of my model objects when I had changed the Core Data model, or automatically regenerate this file that had type safe access as to everything in my asset catalog whenever I put something new in the asset catalog or took something out of the asset catalog.

And that's something where, the fact that it’s not super easy to do in iOS without having to do run script build phases and having to do some other weird nonsense, that's really a huge thing that is annoying. I think from a standpoint of general GraphQL, one thing to remember is that this is ultimately something where you are sending a bunch of JSON to the server and the server is sending you a bunch of JSON back. And there's potentially other implementations where you could use other formats. But for right now, the overwhelming majority of GraphQL implementations are using JSON. And I think it's something where if you can remember that, ultimately that's what you're doing. It's much more about trying to wrap your head around, what are the places that I need to ask for stuff? And then particularly once you get into using a library, how has the caching worked on this kind of thing?

It's very different from just being able to shove everything into a database, the way that you can from a REST end point where you know exactly what you're getting back. You can't say, “okay, I'm going to make a user object that has the following: it has a required ID, it's got a required username. It's got a required address.” Well, the ID can be required, but if you didn't ask for it, you're not going to get it. So you can just say, “hey, I want user, username." And that's the only thing it'll give you back.

And so you can't just shove that into a database that says, "your ID and your address are required," because then the database is like, "these required objects aren't here." So there's a lot of stuff around that's really confusing for people, and I completely understand why. There's a lot of stuff about how you have to work to cache that kind of thing that's extremely complicated, but it's definitely something where starting with understanding, "What's the idea here? What is the problem that we're trying to solve?" And then going from there, I think is a big thing.

This transcript was recorded as part of Swiftly Speaking. You can watch the full original episode on YouTube, or subscribe to the audio version on Apple Podcasts.

Listen on Apple Podcasts

Hacking with Swift is sponsored by Essential Developer.

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until July 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.