Swiftpack.co - JanGorman/Chester as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Chester is a Swift GraphQL query builder.
.package(url: "https://github.com/JanGorman/Chester.git", from: "0.16.0")


CI codecov.io SwiftPM Compatible Carthage compatible Version License Platform

Sort of Experimental: @resultBuilder Support

@resultBuilder seems like a natural match for this kind of task. There's a separate GraphQLBuilderTests test suite that shows the supported cases. In its basic form you can construct a query like this:

import Chester

let query = GraphQLQuery {
  Fields("id", "title")

Nested queries can be defined in their logical order now:

let query = GraphQLQuery {
  Fields("id", "title")
  SubQuery {
    SubQuery {

Known Issues

  • Queries with multiple root fields and arguments produce a compiler error (e.g. 'Int' is not convertible to 'Any')


Chester uses the builder pattern to construct GraphQL queries. In its basic form use it like this:

import Chester

let query = QueryBuilder()
  .with(arguments: Argument(key: "id", value: "20"), Argument(key: "author", value: "Chester"))
  .with(fields: "id", "title", "content")

// For cases with dynamic input, probably best to use a do-catch:

do {
  let queryString = try query.build
} catch {
  // Can specify which errors to catch

// Or if you're sure of your query

guard let queryString = try? query.build else { return }

You can add subqueries. Add as many as needed. You can nest them as well.

let commentsQuery = QueryBuilder()
  .with(fields: "id", content)
let postsQuery = QueryBuilder()
  .with(fields: "id", "title")
  .with(subQuery: commentsQuery)

You can search on multiple collections at once

let search = QueryBuilder()
  .with(arguments: Argument(key: "text", value: "an"))
  .on("Human", "Droid")
  .with(fields: "name")

Check the included unit tests for further examples.


  • Swift 5
  • Xcode 12.5+
  • iOS 8


Chester is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Chester"

Or Carthage. Add Chester to your Cartfile:

github "JanGorman/Chester"

Or Swift Package Manager. To install it, simply go to File > Swift Package > Add Swift Package Dependency and add "https://github.com/JanGorman/Chester.git" as Swift Package URL. Or add the following line to Package.swift:

dependencies: [
    .package(url: "https://github.com/JanGorman/Chester.git", from: "0.14.0")


Jan Gorman


Chester is available under the MIT license. See the LICENSE file for more info.


Stars: 93
Last commit: 2 days ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

22 weeks ago
  • Replace @_functionBuilder with the officially sanctioned @resultBuilder

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics