Skip to content

Commit

Permalink
Updating to current main (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobaFetters authored and runner committed Sep 12, 2023
1 parent a017929 commit 4b81024
Show file tree
Hide file tree
Showing 15 changed files with 181 additions and 113 deletions.
9 changes: 1 addition & 8 deletions SwiftScripts/Sources/TargetConfig/Target.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,7 @@ public enum Target: CaseIterable {
moduleType: moduleType
),
operations: .inSchemaModule,
testMocks: includeTestMocks ? .swiftPackage() : .none,
operationManifest: includeOperationIdentifiers ?
.init(
path: try graphQLFolder(fromTargetRoot: targetRootURL)
.childFileURL(fileName: "operationIDs.json")
.path
)
: nil
testMocks: includeTestMocks ? .swiftPackage() : .none
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
enumCases: .none,
fieldAccessors: .camelCase
),
pruneGeneratedFiles: false
pruneGeneratedFiles: false,
markOperationDefinitionsAsFinal: true
),
experimentalFeatures: .init(
clientControlledNullability: true,
Expand Down Expand Up @@ -98,6 +99,7 @@ class ApolloCodegenConfigurationCodableTests: XCTestCase {
"fieldAccessors" : "camelCase"
},
"deprecatedEnumCases" : "exclude",
"markOperationDefinitionsAsFinal" : true,
"operationDocumentFormat" : [
"definition"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,26 @@ class LocalCacheMutationDefinitionTemplateTests: XCTestCase {
expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true))
}

func test__generate_givenQuery_configIncludesMarkOperationDefinitionsAsFinal_generatesFinalLocalCacheMutation() throws {
// given
let expected =
"""
final class TestOperationLocalCacheMutation: LocalCacheMutation {
static let operationType: GraphQLOperationType = .query
"""

config = .mock(options: .init(markOperationDefinitionsAsFinal: true))

// when
try buildSubjectAndOperation()

let actual = renderSubject()

// then
expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true))
}


func test__generate__givenQueryWithLowercasing_generatesCorrectlyCasedLocalCacheMutation() throws {
// given
schemaSDL = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ class OperationDefinitionTemplateTests: XCTestCase {
expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true))
}

func test__generate_givenQuery_configIncludesMarkOperationDefinitionsAsFinal_generatesFinalQueryDefinitions() throws {
// given
let expected =
"""
final class TestOperationQuery: GraphQLQuery {
static let operationName: String = "TestOperation"
"""

config = .mock(options: .init(markOperationDefinitionsAsFinal: true))

// when
try buildSubjectAndOperation()

let actual = renderSubject()

// then
expect(actual).to(equalLineByLine(expected, ignoringExtraLines: true))
}

func test__generate__givenQueryWithNameEndingInQuery_generatesQueryOperationWithoutDoubledTypeSuffix() throws {
// given
document = """
Expand Down Expand Up @@ -301,9 +320,9 @@ class OperationDefinitionTemplateTests: XCTestCase {

// MARK: - Selection Set Initializers

func test__generate_givenOperationSelectionSet_configIncludesOperations_rendersInitializer() throws {
// given
schemaSDL = """
func test__generate_givenOperationSelectionSet_configIncludesOperations_rendersInitializer() throws {
// given
schemaSDL = """
type Query {
allAnimals: [Animal!]
}
Expand All @@ -313,15 +332,15 @@ class OperationDefinitionTemplateTests: XCTestCase {
}
"""

document = """
document = """
query TestOperation {
allAnimals {
species
}
}
"""

let expected =
let expected =
"""
init(
species: String
Expand All @@ -338,20 +357,20 @@ class OperationDefinitionTemplateTests: XCTestCase {
}
"""

config = .mock(options: .init(selectionSetInitializers: [.operations]))
config = .mock(options: .init(selectionSetInitializers: [.operations]))

// when
try buildSubjectAndOperation()
// when
try buildSubjectAndOperation()

let actual = renderSubject()
let actual = renderSubject()

// then
expect(actual).to(equalLineByLine(expected, atLine: 50, ignoringExtraLines: true))
}
// then
expect(actual).to(equalLineByLine(expected, atLine: 50, ignoringExtraLines: true))
}

func test__generate_givenOperationSelectionSet_configIncludesSpecificOperation_rendersInitializer() throws {
// given
schemaSDL = """
func test__generate_givenOperationSelectionSet_configIncludesSpecificOperation_rendersInitializer() throws {
// given
schemaSDL = """
type Query {
allAnimals: [Animal!]
}
Expand All @@ -361,15 +380,15 @@ class OperationDefinitionTemplateTests: XCTestCase {
}
"""

document = """
document = """
query TestOperation {
allAnimals {
species
}
}
"""

let expected =
let expected =
"""
init(
species: String
Expand All @@ -386,22 +405,22 @@ class OperationDefinitionTemplateTests: XCTestCase {
}
"""

config = .mock(options: .init(selectionSetInitializers: [
.operation(named: "TestOperation")
]))
config = .mock(options: .init(selectionSetInitializers: [
.operation(named: "TestOperation")
]))

// when
try buildSubjectAndOperation()
// when
try buildSubjectAndOperation()

let actual = renderSubject()
let actual = renderSubject()

// then
expect(actual).to(equalLineByLine(expected, atLine: 50, ignoringExtraLines: true))
}
// then
expect(actual).to(equalLineByLine(expected, atLine: 50, ignoringExtraLines: true))
}

func test__render_givenOperationSelectionSet_configDoesNotIncludeOperations_doesNotRenderInitializer() throws {
// given
schemaSDL = """
func test__render_givenOperationSelectionSet_configDoesNotIncludeOperations_doesNotRenderInitializer() throws {
// given
schemaSDL = """
type Query {
allAnimals: [Animal!]
}
Expand All @@ -411,28 +430,28 @@ class OperationDefinitionTemplateTests: XCTestCase {
}
"""

document = """
document = """
query TestOperation {
allAnimals {
species
}
}
"""

config = .mock(options: .init(selectionSetInitializers: [.namedFragments]))
config = .mock(options: .init(selectionSetInitializers: [.namedFragments]))

// when
try buildSubjectAndOperation()
// when
try buildSubjectAndOperation()

let actual = renderSubject()
let actual = renderSubject()

// then
expect(actual).to(equalLineByLine(" }", atLine: 35, ignoringExtraLines: true))
}
// then
expect(actual).to(equalLineByLine(" }", atLine: 35, ignoringExtraLines: true))
}

func test__render_givenOperationSelectionSet_configIncludeSpecificOperationWithOtherName_doesNotRenderInitializer() throws {
// given
schemaSDL = """
func test__render_givenOperationSelectionSet_configIncludeSpecificOperationWithOtherName_doesNotRenderInitializer() throws {
// given
schemaSDL = """
type Query {
allAnimals: [Animal!]
}
Expand All @@ -442,69 +461,68 @@ class OperationDefinitionTemplateTests: XCTestCase {
}
"""

document = """
document = """
query TestOperation {
allAnimals {
species
}
}
"""

config = .mock(options: .init(selectionSetInitializers: [
.operation(named: "OtherOperation")
]))
config = .mock(options: .init(selectionSetInitializers: [
.operation(named: "OtherOperation")
]))

// when
try buildSubjectAndOperation()

let actual = renderSubject()
// when
try buildSubjectAndOperation()

// then
expect(actual).to(equalLineByLine(" }", atLine: 35, ignoringExtraLines: true))
}
let actual = renderSubject()

// then
expect(actual).to(equalLineByLine(" }", atLine: 35, ignoringExtraLines: true))
}

// MARK: - Variables

func test__generate__givenQueryWithScalarVariable_generatesQueryOperationWithVariable() throws {
// given
schemaSDL = """
type Query {
allAnimals: [Animal!]
}
func test__generate__givenQueryWithScalarVariable_generatesQueryOperationWithVariable() throws {
// given
schemaSDL = """
type Query {
allAnimals: [Animal!]
}
type Animal {
species: String!
}
"""
type Animal {
species: String!
}
"""

document = """
query TestOperation($variable: String!) {
allAnimals {
species
}
}
"""
document = """
query TestOperation($variable: String!) {
allAnimals {
species
}
}
"""

let expected =
"""
public var variable: String
let expected =
"""
public var variable: String
public init(variable: String) {
self.variable = variable
}
public init(variable: String) {
self.variable = variable
}
public var __variables: Variables? { ["variable": variable] }
"""
public var __variables: Variables? { ["variable": variable] }
"""

// when
try buildSubjectAndOperation()
// when
try buildSubjectAndOperation()

let actual = renderSubject()
let actual = renderSubject()

// then
expect(actual).to(equalLineByLine(expected, atLine: 8, ignoringExtraLines: true))
}
// then
expect(actual).to(equalLineByLine(expected, atLine: 8, ignoringExtraLines: true))
}

func test__generate__givenQueryWithMutlipleScalarVariables_generatesQueryOperationWithVariables() throws {
// given
Expand Down Expand Up @@ -977,5 +995,4 @@ class OperationDefinitionTemplateTests: XCTestCase {
expect(actual).to(equalLineByLine(expectedOne, atLine: 8, ignoringExtraLines: true))
expect(actual).to(equalLineByLine(expectedTwo, atLine: 10, ignoringExtraLines: true))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ class GraphQLExecutor_SelectionSetMapper_FromResponse_Tests: XCTestCase {
let data = try readValues(GivenSelectionSet.self, from: object)

// then
expect(data.name).to(beNil())
expect(data.hasNullValue(forKey: "name")).to(beTrue())
XCTAssertNil(data.name)
}

func test__optional_scalar__givenDataWithTypeConvertibleToFieldType_getsConvertedValue() throws {
Expand Down Expand Up @@ -690,8 +689,7 @@ class GraphQLExecutor_SelectionSetMapper_FromResponse_Tests: XCTestCase {
let data = try readValues(GivenSelectionSet.self, from: object)

// then
expect(data.favorites! as [String?]).to(equal(["Red", nil, "Bird"]))
expect((data._rawData["favorites"] as? [AnyHashable])?[1]).to(equal(DataDict.NullValue))
XCTAssertEqual(data.favorites! as [String?], ["Red", nil, "Bird"])
}

// MARK: Optional List Of Optional Scalar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public class ApolloCodegen {

let ir = IR(compilationResult: compilationResult)

if itemsToGenerate == .operationManifest {
if itemsToGenerate.contains(.operationManifest) {
var operationIDsFileGenerator = OperationManifestFileGenerator(config: configContext)

for operation in compilationResult.operations {
Expand Down
Loading

0 comments on commit 4b81024

Please sign in to comment.