Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 25 additions & 28 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,38 @@ jobs:
xcode-version: latest-stable
- uses: actions/checkout@v3
- name: Build and test
run: swift test --parallel --enable-test-discovery
run: swift test --parallel

linux:
name: Test on Linux
name: Test Swift ${{ matrix.swift }}
runs-on: ubuntu-latest
steps:
- uses: swift-actions/setup-swift@v2
- uses: actions/checkout@v3
- name: Test
run: swift test --parallel --enable-code-coverage
- name: Get test coverage html
run: |
llvm-cov show \
$(swift build --show-bin-path)/GraphitiPackageTests.xctest \
--instr-profile $(swift build --show-bin-path)/codecov/default.profdata \
--ignore-filename-regex="\.build|Tests" \
--format html \
--output-dir=.test-coverage
- name: Upload test coverage html
uses: actions/upload-artifact@v3
with:
name: test-coverage-report
path: .test-coverage

backcompat-ubuntu-22_04:
name: Test Swift ${{ matrix.swift }} on Ubuntu 22.04
runs-on: ubuntu-22.04
container:
image: swift:${{ matrix.swift }}
strategy:
matrix:
swift: ["5.8", "5.9", "5.10"]
swift: ["5.8", "5.9", "5.10", "6.0", "6.1"]
steps:
- uses: swift-actions/setup-swift@v2
with:
swift-version: ${{ matrix.swift }}
- uses: actions/checkout@v3
- name: Test
run: swift test --parallel

# TODO: Add test coverage upload but it's currently not working with Swift 6.1.0/Ubuntu-latest
# test-coverage:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - name: Test
# run: swift test --parallel --enable-code-coverage
# - name: Get test coverage html
# run: |
# llvm-cov show \
# $(swift build --show-bin-path)/GraphitiPackageTests.xctest \
# --instr-profile $(swift build --show-bin-path)/codecov/default.profdata \
# --ignore-filename-regex="\.build|Tests" \
# --format html \
# --output-dir=.test-coverage
# - name: Upload test coverage html
# uses: actions/upload-artifact@v4
# with:
# name: test-coverage-report
# path: .test-coverage
20 changes: 10 additions & 10 deletions Sources/Graphiti/Federation/Key/Type+Key.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import GraphQL

public extension Type {
@discardableResult
/// Define and add the federated key to this type.
///
/// For more information, see https://www.apollographql.com/docs/federation/entities
/// - Parameters:
/// - function: The resolver function used to load this entity based on the key value.
/// - _: The key value. The name of this argument must match a Type field.
/// - Returns: Self for chaining.
@discardableResult
func key<Arguments: Codable>(
at function: @escaping AsyncResolve<Resolver, Context, Arguments, ObjectType?>,
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
Expand All @@ -17,14 +17,14 @@ public extension Type {
return self
}

@discardableResult
/// Define and add the federated key to this type.
///
/// For more information, see https://www.apollographql.com/docs/federation/entities
/// - Parameters:
/// - function: The resolver function used to load this entity based on the key value.
/// - _: The key values. The names of these arguments must match Type fields.
/// - Returns: Self for chaining.
@discardableResult
func key<Arguments: Codable>(
at function: @escaping AsyncResolve<Resolver, Context, Arguments, ObjectType?>,
@ArgumentComponentBuilder<Arguments> _ arguments: ()
Expand All @@ -34,14 +34,14 @@ public extension Type {
return self
}

@discardableResult
/// Define and add the federated key to this type.
///
/// For more information, see https://www.apollographql.com/docs/federation/entities
/// - Parameters:
/// - function: The resolver function used to load this entity based on the key value.
/// - _: The key value. The name of this argument must match a Type field.
/// - Returns: Self for chaining.
@discardableResult
func key<Arguments: Codable>(
at function: @escaping SimpleAsyncResolve<Resolver, Context, Arguments, ObjectType?>,
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
Expand All @@ -50,14 +50,14 @@ public extension Type {
return self
}

@discardableResult
/// Define and add the federated key to this type.
///
/// For more information, see https://www.apollographql.com/docs/federation/entities
/// - Parameters:
/// - function: The resolver function used to load this entity based on the key value.
/// - _: The key values. The names of these arguments must match Type fields.
/// - Returns: Self for chaining.
@discardableResult
func key<Arguments: Codable>(
at function: @escaping SimpleAsyncResolve<Resolver, Context, Arguments, ObjectType?>,
@ArgumentComponentBuilder<Arguments> _ arguments: ()
Expand All @@ -67,14 +67,14 @@ public extension Type {
return self
}

@discardableResult
/// Define and add the federated key to this type.
///
/// For more information, see https://www.apollographql.com/docs/federation/entities
/// - Parameters:
/// - function: The resolver function used to load this entity based on the key value.
/// - _: The key value. The name of this argument must match a Type field.
/// - Returns: Self for chaining.
@discardableResult
func key<Arguments: Codable>(
at function: @escaping SyncResolve<Resolver, Context, Arguments, ObjectType?>,
@ArgumentComponentBuilder<Arguments> _ arguments: ()
Expand All @@ -84,14 +84,14 @@ public extension Type {
return self
}

@discardableResult
/// Define and add the federated key to this type.
///
/// For more information, see https://www.apollographql.com/docs/federation/entities
/// - Parameters:
/// - function: The resolver function used to load this entity based on the key value.
/// - _: The key values. The names of these arguments must match Type fields.
/// - Returns: Self for chaining.
@discardableResult
func key<Arguments: Codable>(
at function: @escaping SyncResolve<Resolver, Context, Arguments, ObjectType?>,
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
Expand All @@ -102,15 +102,15 @@ public extension Type {
}

public extension Type {
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
@discardableResult
/// Define and add the federated key to this type.
///
/// For more information, see https://www.apollographql.com/docs/federation/entities
/// - Parameters:
/// - function: The resolver function used to load this entity based on the key value.
/// - _: The key value. The name of this argument must match a Type field.
/// - Returns: Self for chaining.
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
@discardableResult
func key<Arguments: Codable>(
at function: @escaping ConcurrentResolve<Resolver, Context, Arguments, ObjectType?>,
@ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments>
Expand All @@ -119,15 +119,15 @@ public extension Type {
return self
}

@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
@discardableResult
/// Define and add the federated key to this type.
///
/// For more information, see https://www.apollographql.com/docs/federation/entities
/// - Parameters:
/// - function: The resolver function used to load this entity based on the key value.
/// - _: The key values. The names of these arguments must match Type fields.
/// - Returns: Self for chaining.
@available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *)
@discardableResult
func key<Arguments: Codable>(
at function: @escaping ConcurrentResolve<Resolver, Context, Arguments, ObjectType?>,
@ArgumentComponentBuilder<Arguments> _ arguments: () -> [ArgumentComponent<Arguments>]
Expand Down
13 changes: 10 additions & 3 deletions Sources/Graphiti/Schema/Schema.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import GraphQL
import NIO

public struct SchemaError: Error, Equatable {
let description: String
}

public final class Schema<Resolver, Context> {
public let schema: GraphQLSchema

Expand All @@ -16,11 +20,14 @@ public final class Schema<Resolver, Context> {
try component.update(typeProvider: typeProvider, coders: coders)
}

guard let query = typeProvider.query else {
fatalError("Query type is required.")
guard typeProvider.query != nil || !typeProvider.federatedResolvers.isEmpty else {
throw SchemaError(
description: "Schema must contain at least 1 query or federated resolver"
)
}

schema = try GraphQLSchema(
query: query,
query: typeProvider.query,
mutation: typeProvider.mutation,
subscription: typeProvider.subscription,
types: typeProvider.types,
Expand Down
14 changes: 7 additions & 7 deletions Sources/Graphiti/SchemaBuilders/SchemaBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ public final class SchemaBuilder<Resolver, Context> {
subscriptionFields = []
}

@discardableResult
/// Allows for setting API encoders and decoders with customized settings.
/// - Parameter newCoders: The new coders to use
/// - Returns: This object for method chaining
@discardableResult
public func setCoders(to newCoders: Coders) -> Self {
coders = newCoders
return self
}

@discardableResult
/// Allows for setting SDL for federated subgraphs.
/// - Parameter newSDL: The new SDL to use
/// - Returns: This object for method chaining
@discardableResult
public func setFederatedSDL(to newSDL: String) -> Self {
federatedSDL = newSDL
return self
Expand All @@ -63,10 +63,10 @@ public final class SchemaBuilder<Resolver, Context> {
return self
}

@discardableResult
/// Adds multiple query operation definitions to the schema.
/// - Parameter component: The query operations to add
/// - Returns: This object for method chaining
@discardableResult
public func add(
@TypeComponentBuilder<Resolver, Context> _ components: ()
-> [TypeComponent<Resolver, Context>]
Expand All @@ -77,10 +77,10 @@ public final class SchemaBuilder<Resolver, Context> {
return self
}

@discardableResult
/// Adds multiple query operation definitions to the schema.
/// - Parameter component: The query operations to add
/// - Returns: This object for method chaining
@discardableResult
public func addQuery(
@FieldComponentBuilder<Resolver, Context> _ fields: ()
-> [FieldComponent<Resolver, Context>]
Expand All @@ -91,10 +91,10 @@ public final class SchemaBuilder<Resolver, Context> {
return self
}

@discardableResult
/// Adds multiple mutation operation definitions to the schema.
/// - Parameter component: The query operations to add
/// - Returns: This object for method chaining
@discardableResult
public func addMutation(
@FieldComponentBuilder<Resolver, Context> _ fields: ()
-> [FieldComponent<Resolver, Context>]
Expand All @@ -105,10 +105,10 @@ public final class SchemaBuilder<Resolver, Context> {
return self
}

@discardableResult
/// Adds multiple subscription operation definitions to the schema.
/// - Parameter component: The query operations to add
/// - Returns: This object for method chaining
@discardableResult
public func addSubscription(
@FieldComponentBuilder<Resolver, Context> _ fields: ()
-> [FieldComponent<Resolver, Context>]
Expand All @@ -119,10 +119,10 @@ public final class SchemaBuilder<Resolver, Context> {
return self
}

@discardableResult
/// Adds multiple type, query, mutation, and subscription definitions using partial schemas to the schema.
/// - Parameter partials: Partial schemas that declare types, query, mutation, and/or subscription definiton
/// - Returns: Thie object for method chaining
@discardableResult
public func use(partials: [PartialSchema<Resolver, Context>]) -> Self {
for type in partials.flatMap({ $0.types }) {
typeComponents.append(type)
Expand Down
Loading