You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
import GithubGraphqlClient
import GithubGraphqlQueryable
@mainstructGithubGraphqlExample{structProjectV2{staticletquery=Node(type:"ProjectV2"){Field("title")}@Valuevartitle:String}staticfunc main()asyncthrows{letprivateKey:String=""" -----BEGIN RSA PRIVATE KEY----- ... -----END RSA PRIVATE KEY-----""" // Replace with your GitHub App's private key
letclient:GithubApiClient=tryawait.init(
appId:"123456", // Replace with your GitHub App ID
privateKey: privateKey
)letitem=tryawait 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
About
Automatically generate GraphQL queries and decode results into Swift objects, and also interact with arbitrary GitHub API endpoints