Skip to content

Commit

Permalink
Fix reference to fragment with lowercase name (#2443)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyMDev authored Aug 16, 2022
1 parent 5b9fe74 commit 595140a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct OperationDefinitionTemplate: OperationTemplateRenderer {
definition: .init(
\(operation.source.formatted(for: queryStringLiteralFormat))\(if: includeFragments, ",")
\(if: includeFragments,
"fragments: [\(fragments.map { "\($0.name).self" }, separator: ", ")]")
"fragments: [\(fragments.map { "\($0.name.firstUppercased).self" }, separator: ", ")]")
))
""",
else: """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,39 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase {
expect(actual).to(equalLineByLine(expected))
}

func test__generate__givenIncludesFragment_fragmentNameStartsWithLowercase_generatesWithOperationDefinitionAndFragment_withFirstUppercased() throws {
// given
referencedFragments = [
.mock("nameFragment"),
]

definition.source =
"""
query NameQuery {
...nameFragment
}
"""

config = .mock(options: .init(
queryStringLiteralFormat: .singleLine,
apqs: .disabled
))

// when
let actual = try renderDocumentType()

// then
let expected =
"""
public static let document: DocumentType = .notPersisted(
definition: .init(
"query NameQuery { ...nameFragment}",
fragments: [NameFragment.self]
))
"""
expect(actual).to(equalLineByLine(expected))
}

func test__generate__givenIncludesManyFragments_formatMultiline_generatesWithOperationDefinitionAndFragment_asMultiline() throws {
// given
referencedFragments = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fragment DogFragment on Dog {
fragment dogFragment on Dog {
species
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PackageTwo

struct DogFragment: MySchemaModule.SelectionSet, Fragment {
public static var fragmentDefinition: StaticString { """
fragment DogFragment on Dog {
fragment dogFragment on Dog {
__typename
species
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query DogQuery {
dog {
... DogFragment
... dogFragment
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DogQuery: GraphQLQuery {
query DogQuery {
dog {
__typename
...DogFragment
...dogFragment
}
}
""",
Expand Down

0 comments on commit 595140a

Please sign in to comment.