• Stars
    star
    100
  • Rank 340,703 (Top 7 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 8 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Chester is a Swift GraphQL query builder.

Chester

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 {
  From("posts")
  Fields("id", "title")
}

Nested queries can be defined in their logical order now:

let query = GraphQLQuery {
  From("posts")
  Fields("id", "title")
  SubQuery {
    From("comments")
    Fields("body")
    SubQuery {
      From("author")
      Fields("firstname")
    }
  }
}

Known Issues

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

Usage

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

import Chester

let query = QueryBuilder()
  .from("posts")
  .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()
  .from("comments")
  .with(fields: "id", content)
let postsQuery = QueryBuilder()
  .from("posts")
  .with(fields: "id", "title")
  .with(subQuery: commentsQuery)

You can search on multiple collections at once

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

Check the included unit tests for further examples.

Requirements

  • Swift 5
  • Xcode 12.5+
  • iOS 8

Installation

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")
]

Author

Jan Gorman

License

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

More Repositories

1

Agrume

🍋 A lemony fresh iOS image viewer written in Swift.
Swift
790
star
2

MapleBacon

🍁🥓 Lightweight and fast Swift library for image downloading, caching and transformations
Swift
342
star
3

Hippolyte

HTTP Stubbing in Swift
Swift
111
star
4

Table

CLI tables in Swift
Swift
55
star
5

SwiftMessageBar

An iOS message bar, written in Swift
Swift
52
star
6

uppercrust

Convert your JSON schema files to Mantle compatible Objective-C models
Ruby
24
star
7

JGORegExpBuilder

A delightful regular expressions DSL
Objective-C
12
star
8

node-table

node.js Text Table Renderer. No longer maintained. Development has moved to https://github.com/gajus/table
CoffeeScript
10
star
9

AVContentProposal-Sample

How to use AVContentProposalViewController
Swift
10
star
10

Waxwing

iOS version migrations 🦤
Swift
7
star
11

jersey-passbook

A Java implementation of the Apple Passbook REST API running on Jersey
Java
7
star
12

Swift-Design-Patterns

Design patterns applied in Swift. Swift 1 in 2014.
Swift
6
star
13

CRDT

A toy implementation of conflict-free replicated data types in Swift
Swift
4
star
14

Bling

An Open Exchange Rates API wrapper written in Swift
Swift
4
star
15

Zoetrope

Animated gif image view with support for varying frame lengths written in Swift.
Swift
3
star
16

ClosureTask

A Closure Task for phing
PHP
3
star
17

Personal-Jira

Your personal Jira search
CoffeeScript
2
star
18

my-boxen

My boxen
Ruby
1
star
19

VerbalExpressions

Objective-C Verbal Expressions
Objective-C
1
star
20

swiftlint

JavaScript
1
star
21

SwiftlintTestRunner

Test project to execute https://github.com/JanGorman/swiftlint
Swift
1
star
22

ember-by-example

Ember.js integration with Dropwizard
JavaScript
1
star
23

ChampagneBrunch

Swift
1
star
24

HARParser

A Swift .har parser
Swift
1
star
25

Sorte

Sort a directory of mp3s into folders base on their tags
Ruby
1
star
26

SwiftMosaicLayout

A mosaic UICollectionViewLayout written in Swift
Swift
1
star
27

puppet-simpholders

SimPholders Puppet Module for Boxen
Ruby
1
star