diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3ac542a0..57c92760 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,14 +14,14 @@ jobs: name: Lint for correct formatting runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: swift-actions/setup-swift@v1 - with: - swift-version: "5.7.1" - - name: GitHub Action for SwiftFormat - uses: CassiusPacheco/action-swiftformat@v0.1.0 - with: - swiftformat-version: '0.50.6' + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Pull formatting docker image + run: docker pull ghcr.io/nicklockwood/swiftformat:latest + - name: Run format linting + run: docker run --rm -v ${{ github.workspace }}:/repo ghcr.io/nicklockwood/swiftformat:latest /repo --lint macos: name: Build and test on macos-latest diff --git a/Sources/GraphQL/Execution/Execute.swift b/Sources/GraphQL/Execution/Execute.swift index d50abcec..00c28e25 100644 --- a/Sources/GraphQL/Execution/Execute.swift +++ b/Sources/GraphQL/Execution/Execute.swift @@ -933,8 +933,8 @@ func completeValue( // If field type is a leaf type, Scalar or Enum, serialize to a valid value, // returning .null if serialization is not possible. if let returnType = returnType as? GraphQLLeafType { - return exeContext.eventLoopGroup.next() - .makeSucceededFuture(try completeLeafValue(returnType: returnType, result: r)) + return try exeContext.eventLoopGroup.next() + .makeSucceededFuture(completeLeafValue(returnType: returnType, result: r)) } // If field type is an abstract type, Interface or Union, determine the diff --git a/Sources/GraphQL/Language/Parser.swift b/Sources/GraphQL/Language/Parser.swift index da263553..bc2cbe0f 100644 --- a/Sources/GraphQL/Language/Parser.swift +++ b/Sources/GraphQL/Language/Parser.swift @@ -153,7 +153,7 @@ func parseDocument(lexer: Lexer) throws -> Document { var definitions: [Definition] = [] repeat { - definitions.append(try parseDefinition(lexer: lexer)) + try definitions.append(parseDefinition(lexer: lexer)) } while try !skip(lexer: lexer, kind: .eof) return Document( @@ -207,13 +207,13 @@ func parseOperationDefinition(lexer: Lexer) throws -> OperationDefinition { let start = lexer.token if peek(lexer: lexer, kind: .openingBrace) { - return OperationDefinition( + return try OperationDefinition( loc: loc(lexer: lexer, startToken: start), operation: .query, name: nil, variableDefinitions: [], // nil directives: [], - selectionSet: try parseSelectionSet(lexer: lexer) + selectionSet: parseSelectionSet(lexer: lexer) ) } @@ -225,13 +225,13 @@ func parseOperationDefinition(lexer: Lexer) throws -> OperationDefinition { name = try parseName(lexer: lexer) } - return OperationDefinition( + return try OperationDefinition( loc: loc(lexer: lexer, startToken: start), operation: operation, name: name, - variableDefinitions: try parseVariableDefinitions(lexer: lexer), - directives: try parseDirectives(lexer: lexer), - selectionSet: try parseSelectionSet(lexer: lexer) + variableDefinitions: parseVariableDefinitions(lexer: lexer), + directives: parseDirectives(lexer: lexer), + selectionSet: parseSelectionSet(lexer: lexer) ) } @@ -271,11 +271,11 @@ func parseVariableDefinitions(lexer: Lexer) throws -> [VariableDefinition] { */ func parseVariableDefinition(lexer: Lexer) throws -> VariableDefinition { let start = lexer.token - return VariableDefinition( + return try VariableDefinition( loc: loc(lexer: lexer, startToken: start), - variable: try parseVariable(lexer: lexer), - type: (try expect(lexer: lexer, kind: .colon), try parseTypeReference(lexer: lexer)).1, - defaultValue: try skip(lexer: lexer, kind: .equals) ? + variable: parseVariable(lexer: lexer), + type: (expect(lexer: lexer, kind: .colon), parseTypeReference(lexer: lexer)).1, + defaultValue: skip(lexer: lexer, kind: .equals) ? parseValueLiteral(lexer: lexer, isConst: true) : nil ) } @@ -286,9 +286,9 @@ func parseVariableDefinition(lexer: Lexer) throws -> VariableDefinition { func parseVariable(lexer: Lexer) throws -> Variable { let start = lexer.token try expect(lexer: lexer, kind: .dollar) - return Variable( + return try Variable( loc: loc(lexer: lexer, startToken: start), - name: try parseName(lexer: lexer) + name: parseName(lexer: lexer) ) } @@ -297,9 +297,9 @@ func parseVariable(lexer: Lexer) throws -> Variable { */ func parseSelectionSet(lexer: Lexer) throws -> SelectionSet { let start = lexer.token - return SelectionSet( + return try SelectionSet( loc: loc(lexer: lexer, startToken: start), - selections: try many( + selections: many( lexer: lexer, openKind: .openingBrace, closeKind: .closingBrace, @@ -340,14 +340,14 @@ func parseField(lexer: Lexer) throws -> Field { name = nameOrAlias } - return Field( + return try Field( loc: loc(lexer: lexer, startToken: start), alias: alias, name: name, - arguments: try parseArguments(lexer: lexer), - directives: try parseDirectives(lexer: lexer), + arguments: parseArguments(lexer: lexer), + directives: parseDirectives(lexer: lexer), selectionSet: peek(lexer: lexer, kind: .openingBrace) ? - try parseSelectionSet(lexer: lexer) : + parseSelectionSet(lexer: lexer) : nil ) } @@ -370,12 +370,12 @@ func parseArguments(lexer: Lexer) throws -> [Argument] { */ func parseArgument(lexer: Lexer) throws -> Argument { let start = lexer.token - return Argument( + return try Argument( loc: loc(lexer: lexer, startToken: start), - name: try parseName(lexer: lexer), + name: parseName(lexer: lexer), value: ( - try expect(lexer: lexer, kind: .colon), - try parseValueLiteral(lexer: lexer, isConst: false) + expect(lexer: lexer, kind: .colon), + parseValueLiteral(lexer: lexer, isConst: false) ).1 ) } @@ -393,10 +393,10 @@ func parseFragment(lexer: Lexer) throws -> Fragment { let start = lexer.token try expect(lexer: lexer, kind: .spread) if peek(lexer: lexer, kind: .name), lexer.token.value != "on" { - return FragmentSpread( + return try FragmentSpread( loc: loc(lexer: lexer, startToken: start), - name: try parseFragmentName(lexer: lexer), - directives: try parseDirectives(lexer: lexer) + name: parseFragmentName(lexer: lexer), + directives: parseDirectives(lexer: lexer) ) } @@ -406,11 +406,11 @@ func parseFragment(lexer: Lexer) throws -> Fragment { try lexer.advance() typeCondition = try parseNamedType(lexer: lexer) } - return InlineFragment( + return try InlineFragment( loc: loc(lexer: lexer, startToken: start), typeCondition: typeCondition, - directives: try parseDirectives(lexer: lexer), - selectionSet: try parseSelectionSet(lexer: lexer) + directives: parseDirectives(lexer: lexer), + selectionSet: parseSelectionSet(lexer: lexer) ) } @@ -423,15 +423,15 @@ func parseFragment(lexer: Lexer) throws -> Fragment { func parseFragmentDefinition(lexer: Lexer) throws -> FragmentDefinition { let start = lexer.token try expectKeyword(lexer: lexer, value: "fragment") - return FragmentDefinition( + return try FragmentDefinition( loc: loc(lexer: lexer, startToken: start), - name: try parseFragmentName(lexer: lexer), + name: parseFragmentName(lexer: lexer), typeCondition: ( - try expectKeyword(lexer: lexer, value: "on"), - try parseNamedType(lexer: lexer) + expectKeyword(lexer: lexer, value: "on"), + parseNamedType(lexer: lexer) ).1, - directives: try parseDirectives(lexer: lexer), - selectionSet: try parseSelectionSet(lexer: lexer) + directives: parseDirectives(lexer: lexer), + selectionSet: parseSelectionSet(lexer: lexer) ) } @@ -538,9 +538,9 @@ func parseValueValue(lexer: Lexer) throws -> Value { func parseList(lexer: Lexer, isConst: Bool) throws -> ListValue { let start = lexer.token let item = isConst ? parseConstValue : parseValueValue - return ListValue( + return try ListValue( loc: loc(lexer: lexer, startToken: start), - values: try any( + values: any( lexer: lexer, openKind: .openingBracket, closeKind: .closingBracket, @@ -560,7 +560,7 @@ func parseObject(lexer: Lexer, isConst: Bool) throws -> ObjectValue { var fields: [ObjectField] = [] while try !skip(lexer: lexer, kind: .closingBrace) { - fields.append(try parseObjectField(lexer: lexer, isConst: isConst)) + try fields.append(parseObjectField(lexer: lexer, isConst: isConst)) } return ObjectValue( @@ -574,12 +574,12 @@ func parseObject(lexer: Lexer, isConst: Bool) throws -> ObjectValue { */ func parseObjectField(lexer: Lexer, isConst: Bool) throws -> ObjectField { let start = lexer.token - return ObjectField( + return try ObjectField( loc: loc(lexer: lexer, startToken: start), - name: try parseName(lexer: lexer), + name: parseName(lexer: lexer), value: ( - try expect(lexer: lexer, kind: .colon), - try parseValueLiteral(lexer: lexer, isConst: isConst) + expect(lexer: lexer, kind: .colon), + parseValueLiteral(lexer: lexer, isConst: isConst) ).1 ) } @@ -609,7 +609,7 @@ func parseDirectives(lexer: Lexer) throws -> [Directive] { var directives: [Directive] = [] while peek(lexer: lexer, kind: .at) { - directives.append(try parseDirective(lexer: lexer)) + try directives.append(parseDirective(lexer: lexer)) } return directives @@ -621,10 +621,10 @@ func parseDirectives(lexer: Lexer) throws -> [Directive] { func parseDirective(lexer: Lexer) throws -> Directive { let start = lexer.token try expect(lexer: lexer, kind: .at) - return Directive( + return try Directive( loc: loc(lexer: lexer, startToken: start), - name: try parseName(lexer: lexer), - arguments: try parseArguments(lexer: lexer) + name: parseName(lexer: lexer), + arguments: parseArguments(lexer: lexer) ) } @@ -666,9 +666,9 @@ func parseTypeReference(lexer: Lexer) throws -> Type { */ func parseNamedType(lexer: Lexer) throws -> NamedType { let start = lexer.token - return NamedType( + return try NamedType( loc: loc(lexer: lexer, startToken: start), - name: try parseName(lexer: lexer) + name: parseName(lexer: lexer) ) } @@ -909,12 +909,12 @@ func parseUnionTypeDefinition(lexer: Lexer) throws -> UnionTypeDefinition { try expectKeyword(lexer: lexer, value: "union") let name = try parseName(lexer: lexer) let directives = try parseDirectives(lexer: lexer) - return UnionTypeDefinition( + return try UnionTypeDefinition( loc: loc(lexer: lexer, startToken: start), description: description, name: name, directives: directives, - types: try parseUnionMembers(lexer: lexer) + types: parseUnionMembers(lexer: lexer) ) } @@ -1290,7 +1290,7 @@ func any( var nodes: [T] = [] while try !skip(lexer: lexer, kind: closeKind) { - nodes.append(try parse(lexer)) + try nodes.append(parse(lexer)) } return nodes @@ -1313,7 +1313,7 @@ func optionalMany( } var nodes: [T] = [] while try !skip(lexer: lexer, kind: closeKind) { - nodes.append(try parse(lexer)) + try nodes.append(parse(lexer)) } return nodes } @@ -1333,7 +1333,7 @@ func many( try expect(lexer: lexer, kind: openKind) var nodes = [try parse(lexer)] while try !skip(lexer: lexer, kind: closeKind) { - nodes.append(try parse(lexer)) + try nodes.append(parse(lexer)) } return nodes } diff --git a/Sources/GraphQL/Type/Definition.swift b/Sources/GraphQL/Type/Definition.swift index 1faf3e88..0daabd51 100644 --- a/Sources/GraphQL/Type/Definition.swift +++ b/Sources/GraphQL/Type/Definition.swift @@ -393,12 +393,12 @@ func defineFieldMap(name: String, fields: GraphQLFieldMap) throws -> GraphQLFiel for (name, config) in fields { try assertValid(name: name) - let field = GraphQLFieldDefinition( + let field = try GraphQLFieldDefinition( name: name, type: config.type, description: config.description, deprecationReason: config.deprecationReason, - args: try defineArgumentMap(args: config.args), + args: defineArgumentMap(args: config.args), resolve: config.resolve, subscribe: config.subscribe ) diff --git a/Sources/GraphQL/Utilities/NIO+Extensions.swift b/Sources/GraphQL/Utilities/NIO+Extensions.swift index 78d1b633..84d01be4 100644 --- a/Sources/GraphQL/Utilities/NIO+Extensions.swift +++ b/Sources/GraphQL/Utilities/NIO+Extensions.swift @@ -118,7 +118,8 @@ public extension EventLoopFuture { /// /// The key difference between this method and the regular `flatMap` is error handling. /// - /// With `tryFlatMap`, the provided callback _may_ throw Errors, causing the returned `EventLoopFuture` + /// With `tryFlatMap`, the provided callback _may_ throw Errors, causing the returned + /// `EventLoopFuture` /// to report failure immediately after the completion of the original `EventLoopFuture`. flatMap { [eventLoop] value in do { diff --git a/Tests/GraphQLTests/FieldExecutionStrategyTests/FieldExecutionStrategyTests.swift b/Tests/GraphQLTests/FieldExecutionStrategyTests/FieldExecutionStrategyTests.swift index 8f74565c..03d1e5c2 100644 --- a/Tests/GraphQLTests/FieldExecutionStrategyTests/FieldExecutionStrategyTests.swift +++ b/Tests/GraphQLTests/FieldExecutionStrategyTests/FieldExecutionStrategyTests.swift @@ -206,7 +206,7 @@ class FieldExecutionStrategyTests: XCTestCase { } func testSerialFieldExecutionStrategyWithSingleField() throws { - let result = try timing(try graphql( + let result = try timing(graphql( queryStrategy: SerialFieldExecutionStrategy(), schema: schema, request: singleQuery, @@ -217,7 +217,7 @@ class FieldExecutionStrategyTests: XCTestCase { } func testSerialFieldExecutionStrategyWithSingleFieldError() throws { - let result = try timing(try graphql( + let result = try timing(graphql( queryStrategy: SerialFieldExecutionStrategy(), schema: schema, request: singleThrowsQuery, @@ -228,7 +228,7 @@ class FieldExecutionStrategyTests: XCTestCase { } func testSerialFieldExecutionStrategyWithSingleFieldFailedFuture() throws { - let result = try timing(try graphql( + let result = try timing(graphql( queryStrategy: SerialFieldExecutionStrategy(), schema: schema, request: singleFailedFutureQuery, @@ -239,7 +239,7 @@ class FieldExecutionStrategyTests: XCTestCase { } func testSerialFieldExecutionStrategyWithMultipleFields() throws { - let result = try timing(try graphql( + let result = try timing(graphql( queryStrategy: SerialFieldExecutionStrategy(), schema: schema, request: multiQuery, @@ -250,7 +250,7 @@ class FieldExecutionStrategyTests: XCTestCase { } func testSerialFieldExecutionStrategyWithMultipleFieldErrors() throws { - let result = try timing(try graphql( + let result = try timing(graphql( queryStrategy: SerialFieldExecutionStrategy(), schema: schema, request: multiThrowsQuery, @@ -266,7 +266,7 @@ class FieldExecutionStrategyTests: XCTestCase { } func testConcurrentDispatchFieldExecutionStrategyWithSingleField() throws { - let result = try timing(try graphql( + let result = try timing(graphql( queryStrategy: ConcurrentDispatchFieldExecutionStrategy(), schema: schema, request: singleQuery, @@ -277,7 +277,7 @@ class FieldExecutionStrategyTests: XCTestCase { } func testConcurrentDispatchFieldExecutionStrategyWithSingleFieldError() throws { - let result = try timing(try graphql( + let result = try timing(graphql( queryStrategy: ConcurrentDispatchFieldExecutionStrategy(), schema: schema, request: singleThrowsQuery, @@ -288,7 +288,7 @@ class FieldExecutionStrategyTests: XCTestCase { } func testConcurrentDispatchFieldExecutionStrategyWithMultipleFields() throws { - let result = try timing(try graphql( + let result = try timing(graphql( queryStrategy: ConcurrentDispatchFieldExecutionStrategy(), schema: schema, request: multiQuery, @@ -299,7 +299,7 @@ class FieldExecutionStrategyTests: XCTestCase { } func testConcurrentDispatchFieldExecutionStrategyWithMultipleFieldErrors() throws { - let result = try timing(try graphql( + let result = try timing(graphql( queryStrategy: ConcurrentDispatchFieldExecutionStrategy(), schema: schema, request: multiThrowsQuery, diff --git a/Tests/GraphQLTests/InputTests/InputTests.swift b/Tests/GraphQLTests/InputTests/InputTests.swift index 23fb6c9b..fe66d461 100644 --- a/Tests/GraphQLTests/InputTests/InputTests.swift +++ b/Tests/GraphQLTests/InputTests/InputTests.swift @@ -26,7 +26,7 @@ class InputTests: XCTestCase { ) let schema = try GraphQLSchema( - query: try GraphQLObjectType( + query: GraphQLObjectType( name: "Query", fields: [ "echo": GraphQLField( @@ -192,7 +192,7 @@ class InputTests: XCTestCase { ) let schema = try GraphQLSchema( - query: try GraphQLObjectType( + query: GraphQLObjectType( name: "Query", fields: [ "echo": GraphQLField( @@ -374,7 +374,7 @@ class InputTests: XCTestCase { ) let schema = try GraphQLSchema( - query: try GraphQLObjectType( + query: GraphQLObjectType( name: "Query", fields: [ "echo": GraphQLField( @@ -568,7 +568,7 @@ class InputTests: XCTestCase { ) let schema = try GraphQLSchema( - query: try GraphQLObjectType( + query: GraphQLObjectType( name: "Query", fields: [ "echo": GraphQLField( @@ -804,7 +804,7 @@ class InputTests: XCTestCase { ) let schema = try GraphQLSchema( - query: try GraphQLObjectType( + query: GraphQLObjectType( name: "Query", fields: [ "echo": GraphQLField( @@ -939,7 +939,7 @@ class InputTests: XCTestCase { ) let schema = try GraphQLSchema( - query: try GraphQLObjectType( + query: GraphQLObjectType( name: "Query", fields: [ "echo": GraphQLField( @@ -1079,7 +1079,7 @@ class InputTests: XCTestCase { ) let schema = try GraphQLSchema( - query: try GraphQLObjectType( + query: GraphQLObjectType( name: "Query", fields: [ "echo": GraphQLField( @@ -1213,7 +1213,7 @@ class InputTests: XCTestCase { ) let schema = try GraphQLSchema( - query: try GraphQLObjectType( + query: GraphQLObjectType( name: "Query", fields: [ "echo": GraphQLField( diff --git a/Tests/GraphQLTests/MapTests/MapTests.swift b/Tests/GraphQLTests/MapTests/MapTests.swift index 696dbbe8..5f5e5236 100644 --- a/Tests/GraphQLTests/MapTests/MapTests.swift +++ b/Tests/GraphQLTests/MapTests/MapTests.swift @@ -155,8 +155,8 @@ class MapTests: XCTestCase { func testMapEncodingOrderPreserved() throws { // Test top level XCTAssertEqual( - String( - data: try GraphQLJSONEncoder().encode( + try String( + data: GraphQLJSONEncoder().encode( Map.dictionary([ "1": .number(1), "2": .number(2), @@ -177,8 +177,8 @@ class MapTests: XCTestCase { // Test embedded XCTAssertEqual( - String( - data: try GraphQLJSONEncoder().encode( + try String( + data: GraphQLJSONEncoder().encode( Map.array([ Map.dictionary([ "1": .number(1), diff --git a/Tests/GraphQLTests/ValidationTests/ValidationTests.swift b/Tests/GraphQLTests/ValidationTests/ValidationTests.swift index 89ff46f1..fa960664 100644 --- a/Tests/GraphQLTests/ValidationTests/ValidationTests.swift +++ b/Tests/GraphQLTests/ValidationTests/ValidationTests.swift @@ -7,9 +7,9 @@ class ValidationTestCase: XCTestCase { var rule: Rule! private func validate(body request: String) throws -> [GraphQLError] { - return GraphQL.validate( + return try GraphQL.validate( schema: ValidationExampleSchema, - ast: try parse(source: Source(body: request, name: "GraphQL request")), + ast: parse(source: Source(body: request, name: "GraphQL request")), rules: [rule] ) }