Automatically generate GraphQL queries and decode results into Swift objects, and also interact with arbitrary GitHub API endpoints

Overview

GitHub API and GraphQL Client

This package provides a generic GitHub API client (GithubApiClient) as well as Codable-like GitHub GraphQL querying and decoding based on an object's properties.

These two targets automatically handle:

The GraphQL interface is handled by defining your query using a simple Result Builder interface:

static let query = Node(type: "ProjectV2") {
	Field("title")
	Field("url")
}

Using this tree, the actual GraphQL query string can be automatically generated, as can the translation from the JSON result into an instance of your type.

GraphQL functionality is currently designed only for GitHub's GraphQL API and may not function correctly with any other GraphQL server. Additionally, this is still in extremely early development and may not yet support even all GitHub GraphQL querying operations.

The GitHub API client has explicit helper methods for a limited subset of the full API, currently including:

  • Basic app authentication
  • GraphQL queries
  • Posting issue comments and reactions

However, any arbitrary API call may be made, with authentication automatically injected.

Quick Start

Pre-built examples:

  • GitHub Actions Webhook example: command-line utility that invokes an Actions webhook on a configured repository as a GitHub App (does not use any GraphQL functionality, only the GitHub API client)
  • GitHub Projects GraphQL example: command-line utility that fetches information about a GitHub Projects (V2) item given an input node ID, authenticating as a GitHub App

Add to your Package.Swift:

...
	dependencies: [
		...
		.package(url: "https://github.com/MPLew-is/github-graphql-client", branch: "main"),
	],
	targets: [
		...
		.target(
			...
			dependencies: [
				...
				.product(name: "GithubApiClient", package: "github-graphql-client"),
				.product(name: "GithubGraphqlQueryable", package: "github-graphql-client"),
			]
		),
		...
	]
]

Query a test object from the GitHub GraphQL API:

import GithubGraphqlClient
import GithubGraphqlQueryable

@main struct GithubGraphqlExample {
	struct ProjectV2 {
		static let query = Node(type: "ProjectV2") {
			Field("title")
		}

		@Value var title: String
	}

	static func main() async throws{
		let privateKey: String = """
			-----BEGIN RSA PRIVATE KEY-----
			...
			-----END RSA PRIVATE KEY-----
			""" // Replace with your GitHub App's private key
		let client: GithubApiClient = try await .init(
			appId: "123456", // Replace with your GitHub App ID
			privateKey: privateKey
		)

		let item = try await client.graphqlQuery(
			ProjectV2.self,
			id: "PVT_...", // Replace with the unique node ID for your GitHub Project (V2)
			for: "MPLew-is" // Replace with the user on which your app has been installed)
		)
	}
}

(See the GraphQL client example for more detailed instructions on how to set up a GitHub app and get the required authentication/configuration values)

Targets provided

  • GithubGraphqlQueryable: a protocol and associated types for automatic query generation and decoding from a GraphQL JSON response

  • GithubApiClient: an abstraction layer around supported GitHub API endpoints (including the GraphQL one), automatically handling the authentication needed for a GitHub App

You might also like...
Queues, timers, and task groups in Swift
Queues, timers, and task groups in Swift

Dispatcher eases the pain of using Grand Central Dispatch by introducing 4 new Swift classes. Dispatcher Queue Group Timer Requirements Swift 2.0+ Ins

Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch (iOS7+ and OS X 10.9+ compatible)

Async.legacy Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch (GCD) Async rewritten for iOS7 and OS X 10.9 Compatibility

A Swift DSL that allows concise and effective concurrency manipulation
A Swift DSL that allows concise and effective concurrency manipulation

NOTE Brisk is being mothballed due to general incompatibilities with modern version of Swift. I recommend checking out ReactiveSwift, which solves man

⚡️ Fast async task based Swift framework with focus on type safety, concurrency and multi threading
⚡️ Fast async task based Swift framework with focus on type safety, concurrency and multi threading

Our apps constantly do work. The faster you react to user input and produce an output, the more likely is that the user will continue to use your appl

A lightweight swift network layer with Combine, Async-Await, and a traditional completion block.

CombineNetwork A simple light-weight network library to make network requesting simpler. It supports newer techonology such as async/await as well as

The projects and materials that accompany the Modern Concurrency in Swift book

Modern Concurrency in Swift: Materials This repo contains all the downloadable materials and projects associated with the Modern Concurrency in Swift

Tools for using Swift Concurrency on macOS 10.15 Catalina, iOS 13, tvOS 13, and watchOS 6.

ConcurrencyCompatibility Tools for using Swift Concurrency on macOS 10.15 Catalina, iOS 13, tvOS 13, and watchOS 6. Xcode 13.2 adds backwards deployme

Egg-Timer - Intermediate Swift Programming - Control Flow and Optionals

Egg-Timer Intermediate Swift Programming - Control Flow and Optionals What I lea

OTOperations - Useful Swift NSOperation and NSOperationQueue subclasses

OTOperations Useful Swift NSOperation (Operation) and NSOperationQueue (Operatio

Owner
Mike Lewis
Mike Lewis
Slack message generator and API client, written in Swift with Result Builders and Concurrency

Slack Message Client This package provides a Swift object model for a Slack Block Kit message, as well as a Result Builder convenience interface for e

Mike Lewis 2 Jul 30, 2022
Schedule timing task in Swift using a fluent API. (A friendly alternative to Timer)

Schedule(简体中文) Schedule is a timing tasks scheduler written in Swift. It allows you run timing tasks with elegant and intuitive syntax. Features Elega

Luo Xiu 1.8k Jan 7, 2023
Swift TableView pagination with async API request.

SwiftTableViewPagination Swift TableView pagination with async API request. Output UML Create puml file. $ cd SwiftTableViewPagination/scripts/swiftum

y-okudera 1 Dec 26, 2021
Throttle massive number of inputs in a single drop of one line API.

Icon credits: Lorc, Delapouite & contributors Throttler Throttler is a library that throttles unnecessarily repeated and massive inputs until the last

Jang Seoksoon 73 Nov 16, 2022
PixabayImageSearchSample - SwiftUI + LazyVGrid + Pixabay API + Codable + sync/async Sample

PixabayImageSearchSample SwiftUI + LazyVGrid + Pixabay API + Codable + sync/asyn

null 3 Nov 23, 2022
Venice - Coroutines, structured concurrency and CSP for Swift on macOS and Linux.

Venice provides structured concurrency and CSP for Swift. Features Coroutines Coroutine cancelation Coroutine groups Channels Receive-only chan

Zewo 1.5k Dec 22, 2022
Async and concurrent versions of Swift’s forEach, map, flatMap, and compactMap APIs.

CollectionConcurrencyKit Welcome to CollectionConcurrencyKit, a lightweight Swift package that adds asynchronous and concurrent versions of the standa

John Sundell 684 Jan 9, 2023
A complete set of primitives for concurrency and reactive programming on Swift

A complete set of primitives for concurrency and reactive programming on Swift 1.4.0 is the latest and greatest, but only for Swift 4.2 and 5.0 use 1.

AsyncNinja 156 Aug 31, 2022
GroupWork is an easy to use Swift framework that helps you orchestrate your concurrent, asynchronous functions in a clean and organized way

GroupWork is an easy to use Swift framework that helps you orchestrate your concurrent, asynchronous functions in a clean and organized way. This help

Quan Vo 42 Oct 5, 2022
SwiftCoroutine - Swift coroutines for iOS, macOS and Linux.

Many languages, such as Kotlin, Go, JavaScript, Python, Rust, C#, C++ and others, already have coroutines support that makes the async/await pattern i

Alex Belozierov 808 Dec 1, 2022