Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow quotes in query document string #2701

Merged
merged 3 commits into from
Dec 7, 2022
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
2 changes: 1 addition & 1 deletion Sources/AnimalKingdomAPI/AnimalKingdomAPI/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.7

import PackageDescription

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ fileprivate extension String {
switch format {
case .multiline:
return """
""\"
#""\"
\(self)
""\"
""\"#
"""

case .singleLine:
return "\"\(components(separatedBy: .newlines).joined(separator: ""))\""
return "#\"\(components(separatedBy: .newlines).joined(separator: ""))\"#"
}
}
}
2 changes: 1 addition & 1 deletion Sources/GitHubAPI/GitHubAPI/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.7

import PackageDescription

Expand Down
2 changes: 1 addition & 1 deletion Sources/StarWarsAPI/StarWarsAPI/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.7

import PackageDescription

Expand Down
2 changes: 1 addition & 1 deletion Sources/SubscriptionAPI/SubscriptionAPI/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.7

import PackageDescription

Expand Down
2 changes: 1 addition & 1 deletion Sources/UploadAPI/UploadAPI/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.7

import PackageDescription

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class OperationDefinitionTemplateTests: XCTestCase {
public static let operationName: String = "lowercaseOperation"
public static let document: ApolloAPI.DocumentType = .notPersisted(
definition: .init(
\"\"\"
#\"\"\"
query lowercaseOperation($variable: String = "TestVar") {
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase {
).description
}

// MARK: Query string formatting tests

func test__generate__givenMultilineFormat_generatesWithOperationDefinition_asMultiline() throws {
// given
definition.source =
Expand All @@ -54,11 +56,11 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase {
"""
public static let document: ApolloAPI.DocumentType = .notPersisted(
definition: .init(
""\"
#""\"
query NameQuery {
name
}
""\"
""\"#
))
"""
expect(actual).to(equalLineByLine(expected))
Expand All @@ -85,7 +87,65 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase {
"""
public static let document: ApolloAPI.DocumentType = .notPersisted(
definition: .init(
"query NameQuery { name}"
#"query NameQuery { name}"#
))
"""
expect(actual).to(equalLineByLine(expected))
}

func test__generate__givenMultilineFormat_withInLineQuotes_generatesWithOperationDefinitionAsMultiline_withInlineQuotes() throws {
// given
definition.source =
"""
query NameQuery($filter: String = "MyName") {
name
}
"""
config = .mock(options: .init(
queryStringLiteralFormat: .multiline,
apqs: .disabled
))

// when
let actual = try renderDocumentType()

// then
let expected =
"""
public static let document: ApolloAPI.DocumentType = .notPersisted(
definition: .init(
#""\"
query NameQuery($filter: String = "MyName") {
name
}
""\"#
))
"""
expect(actual).to(equalLineByLine(expected))
}

func test__generate__givenSingleLineFormat_withInLineQuotes_generatesWithOperationDefinitionAsSingleLine_withInLineQuotes() throws {
// given
definition.source =
"""
query NameQuery($filter: String = "MyName") {
name
}
"""
config = .mock(options: .init(
queryStringLiteralFormat: .singleLine,
apqs: .disabled
))

// when
let actual = try renderDocumentType()

// then
let expected =
"""
public static let document: ApolloAPI.DocumentType = .notPersisted(
definition: .init(
#"query NameQuery($filter: String = "MyName") { name}"#
))
"""
expect(actual).to(equalLineByLine(expected))
Expand Down Expand Up @@ -117,11 +177,11 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase {
"""
public static let document: ApolloAPI.DocumentType = .notPersisted(
definition: .init(
""\"
#""\"
query NameQuery {
...NameFragment
}
""\",
""\"#,
fragments: [NameFragment.self]
))
"""
Expand Down Expand Up @@ -154,7 +214,7 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase {
"""
public static let document: ApolloAPI.DocumentType = .notPersisted(
definition: .init(
"query NameQuery { ...NameFragment}",
#"query NameQuery { ...NameFragment}"#,
fragments: [NameFragment.self]
))
"""
Expand Down Expand Up @@ -187,7 +247,7 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase {
"""
public static let document: ApolloAPI.DocumentType = .notPersisted(
definition: .init(
"query NameQuery { ...nameFragment}",
#"query NameQuery { ...nameFragment}"#,
fragments: [NameFragment.self]
))
"""
Expand Down Expand Up @@ -228,15 +288,15 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase {
"""
public static let document: ApolloAPI.DocumentType = .notPersisted(
definition: .init(
""\"
#""\"
query NameQuery {
...Fragment1
...Fragment2
...Fragment3
...Fragment4
...FragmentWithLongName1234123412341234123412341234
}
""\",
""\"#,
fragments: [Fragment1.self, Fragment2.self, Fragment3.self, Fragment4.self, FragmentWithLongName1234123412341234123412341234.self]
))
"""
Expand Down Expand Up @@ -277,7 +337,7 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase {
"""
public static let document: ApolloAPI.DocumentType = .notPersisted(
definition: .init(
"query NameQuery { ...Fragment1 ...Fragment2 ...Fragment3 ...Fragment4 ...FragmentWithLongName1234123412341234123412341234}",
#"query NameQuery { ...Fragment1 ...Fragment2 ...Fragment3 ...Fragment4 ...FragmentWithLongName1234123412341234123412341234}"#,
fragments: [Fragment1.self, Fragment2.self, Fragment3.self, Fragment4.self, FragmentWithLongName1234123412341234123412341234.self]
))
"""
Expand Down Expand Up @@ -308,11 +368,11 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase {
public static let document: ApolloAPI.DocumentType = .automaticallyPersisted(
operationIdentifier: "1ec89997a185c50bacc5f62ad41f27f3070f4a950d72e4a1510a4c64160812d5",
definition: .init(
""\"
#""\"
query NameQuery {
name
}
""\"
""\"#
))
"""
expect(actual).to(equalLineByLine(expected))
Expand Down Expand Up @@ -346,6 +406,8 @@ class OperationDefinitionTemplate_DocumentType_Tests: XCTestCase {
expect(actual).to(equalLineByLine(expected))
}

// MARK: Namespacing tests

func test__generate__givenCocoapodsCompatibleImportStatements_true_shouldUseCorrectNamespace() throws {
// given
definition.source =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.7

import PackageDescription

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"pins" : [
{
"identity" : "apollo-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apollographql/apollo-ios.git",
"state" : {
"revision" : "4b13a927b581c40d06f2c65f593f672a52c0c812",
"version" : "1.0.3"
}
},
{
"identity" : "inflectorkit",
"kind" : "remoteSourceControl",
Expand All @@ -23,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/stephencelis/SQLite.swift.git",
"state" : {
"revision" : "4d543d811ee644fa4cc4bfa0be996b4dd6ba0f54",
"version" : "0.13.3"
"revision" : "7a2e3cd27de56f6d396e84f63beefd0267b55ccb",
"version" : "0.14.1"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.7

import PackageDescription

Expand All @@ -15,7 +15,7 @@ let package = Package(
.library(name: "GraphQLSchemaNameTestMocks", targets: ["GraphQLSchemaNameTestMocks"]),
],
dependencies: [
.package(url: "https://github.com/apollographql/apollo-ios.git", from: "1.0.0"),
.package(name: "apollo-ios", path: "../../.."),
],
targets: [
.target(
Expand Down