Lightweight GraphQL API client based on Apollo iOS. Developed to simplify Futured in-house development of applications, that work with GraphQL APIs.
Currently there is no support for some Apollo's features:
- Apollo built-in cache
- GraphQL subscriptions
- Custom interceptors
Install or add following line to your dependencies:
.package(url: "https://github.com/futuredapp/GraphQLAPIKit.git", from: "1.0.0")
Make sure that GraphQLAPIKit
is added as a package dependency to your project
Add apollo-codegen-config.json
file and add it to GraphQLGenerated
folder.
Copy and paste json configuration to the newly created file:
{
"schemaName" : "GraphQLGenerated",
"input" : {
"operationSearchPaths" : [
"**/*.graphql"
],
"schemaSearchPaths" : [
"./schema.json"
]
},
"output" : {
"schemaTypes" : {
"path" : "./",
"moduleType" : {
"swiftPackageManager": {}
}
},
"operations" : {
"inSchemaModule" : {}
},
"testMocks" : {
"swiftPackage": {
"targetName": "GraphQLGeneratedMocks"
}
}
}
}
Add GraphQL JSON schema to the GraphQLGenerated
folder and name it schema.json
.
Add Queries
and Mutations
folders to GraphQLGenerated
folder.
Add your first Query or Mutation and save it with .graphql
extension to Queries
or Mutations
folders.
At your main app's target add a new build phase named Generate GraphQL Operations
.
Move your newly created build phase above the Compile Sources
phase.
Add script:
SDKROOT=$(/usr/bin/xcrun --sdk macosx --show-sdk-path)
SWIFT_PACKAGES="${BUILD_DIR%/Build/*}/SourcePackages/checkouts"
${SWIFT_PACKAGES}/GraphQLAPIKit/Resources/apollo-ios-cli generate --path ./GraphQLGenerated/apollo-codegen-config.json
Go to your application main target's Build Settings and set User Script Sandboxing
to NO
- Go to Xcode -> File -> Add Package Dependencies..
- Choose
Add Local...
- Add
GraphQLGenerated
as local Swift Package. Make sure, thatGraphQLGenerated
library was added to your main's targetFrameworks, Libraries, and Embedded Content
list. For your project's test target addGraphQLGeneratedMocks
library if necessary.
Add *.graphql.swift
to your repository's git ignore file to ignore Apollo generated code.
Content of generated Schema
folder has to be commited to the repository
import GraphQLAPIKit
import GraphQLGenerated
let query = MyExampleQuery()
let mutation = MyExampleMutation()
import GraphQLAPIKit
import GraphQLGenerated
let apiAdapter = GraphQLAPIAdapter(url: URL(string: "https://MyAPIUrl.com")!)
let queryResult = await apiAdapter.fetch(query: query)
let mutationResult = await apiAdapter.perform(mutation: mutation)
GraphQLAPIKit is available under the MIT license. See the LICENSE file for more information.