Skip to content

Commit e0cde7c

Browse files
Merge pull request #820 from apollographql/update/codegen
Update CLI to 2.19.1
2 parents 53d3526 + 7c03bf4 commit e0cde7c

12 files changed

Lines changed: 585 additions & 615 deletions

File tree

Apollo.podspec

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ Pod::Spec.new do |s|
2323
s.subspec 'Core' do |ss|
2424
ss.source_files = 'Sources/Apollo/*.swift'
2525
ss.preserve_paths = [
26-
'scripts/check-and-run-apollo-cli.sh',
27-
'scripts/check-and-run-apollo-codegen.sh',
2826
'scripts/run-bundled-codegen.sh',
2927
'scripts/apollo.tar.gz',
3028
]

Apollo.xcodeproj/project.pbxproj

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
9F27D4641D40379500715680 /* JSONStandardTypeConversions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F27D4631D40379500715680 /* JSONStandardTypeConversions.swift */; };
3030
9F295E311E27534800A24949 /* NormalizeQueryResults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F295E301E27534800A24949 /* NormalizeQueryResults.swift */; };
3131
9F295E381E277B2A00A24949 /* GraphQLResultNormalizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F295E371E277B2A00A24949 /* GraphQLResultNormalizer.swift */; };
32-
9F2A74DB2137C21500E63C85 /* check-and-run-apollo-codegen.sh in Resources */ = {isa = PBXBuildFile; fileRef = 9F2A74DA2137C21500E63C85 /* check-and-run-apollo-codegen.sh */; };
3332
9F438D071E6C2FD9007BDC1A /* Apollo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FC750441D2A532C00458D91 /* Apollo.framework */; };
3433
9F438D081E6C30B1007BDC1A /* StarWarsAPI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FCE2CFA1E6C213D00E34457 /* StarWarsAPI.framework */; };
3534
9F533AB31E6C4A4200CBE097 /* BatchedLoadTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F438D0B1E6C494C007BDC1A /* BatchedLoadTests.swift */; };
@@ -97,7 +96,6 @@
9796
9FD637F51E6AD43F001EDBC8 /* Apollo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FC750441D2A532C00458D91 /* Apollo.framework */; };
9897
9FD637F61E6AD43F001EDBC8 /* Apollo.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9FC750441D2A532C00458D91 /* Apollo.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
9998
9FE1C6E71E634C8D00C02284 /* PromiseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FE1C6E61E634C8D00C02284 /* PromiseTests.swift */; };
100-
9FE3F3981DADBD870072078F /* check-and-run-apollo-cli.sh in Resources */ = {isa = PBXBuildFile; fileRef = 9FE3F3971DADBD870072078F /* check-and-run-apollo-cli.sh */; };
10199
9FE941D01E62C771007CDD89 /* Promise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FE941CF1E62C771007CDD89 /* Promise.swift */; };
102100
9FEB050D1DB5732300DA3B44 /* JSONSerializationFormat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FEB050C1DB5732300DA3B44 /* JSONSerializationFormat.swift */; };
103101
9FEC15B41E681DAD00D461B4 /* Collections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FEC15B31E681DAD00D461B4 /* Collections.swift */; };
@@ -286,7 +284,6 @@
286284
9F27D4631D40379500715680 /* JSONStandardTypeConversions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONStandardTypeConversions.swift; sourceTree = "<group>"; };
287285
9F295E301E27534800A24949 /* NormalizeQueryResults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NormalizeQueryResults.swift; sourceTree = "<group>"; };
288286
9F295E371E277B2A00A24949 /* GraphQLResultNormalizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphQLResultNormalizer.swift; sourceTree = "<group>"; };
289-
9F2A74DA2137C21500E63C85 /* check-and-run-apollo-codegen.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; name = "check-and-run-apollo-codegen.sh"; path = "scripts/check-and-run-apollo-codegen.sh"; sourceTree = SOURCE_ROOT; };
290287
9F3750501ECEFD2300C68F5E /* CharacterAndSubTypesFragments.graphql */ = {isa = PBXFileReference; lastKnownFileType = text; path = CharacterAndSubTypesFragments.graphql; sourceTree = "<group>"; };
291288
9F438D0B1E6C494C007BDC1A /* BatchedLoadTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BatchedLoadTests.swift; sourceTree = "<group>"; };
292289
9F4DAF2D1E48B84B00EBFF0B /* HTTPNetworkTransport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPNetworkTransport.swift; sourceTree = "<group>"; };
@@ -372,7 +369,6 @@
372369
9FD637ED1E6ACF88001EDBC8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
373370
9FD637EF1E6ACF88001EDBC8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
374371
9FE1C6E61E634C8D00C02284 /* PromiseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PromiseTests.swift; sourceTree = "<group>"; };
375-
9FE3F3971DADBD870072078F /* check-and-run-apollo-cli.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = "check-and-run-apollo-cli.sh"; path = "scripts/check-and-run-apollo-cli.sh"; sourceTree = SOURCE_ROOT; };
376372
9FE941CF1E62C771007CDD89 /* Promise.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Promise.swift; sourceTree = "<group>"; };
377373
9FEB050C1DB5732300DA3B44 /* JSONSerializationFormat.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONSerializationFormat.swift; sourceTree = "<group>"; };
378374
9FEC15B31E681DAD00D461B4 /* Collections.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Collections.swift; sourceTree = "<group>"; };
@@ -785,8 +781,6 @@
785781
9FC750471D2A532C00458D91 /* Apollo.h */,
786782
9FC750491D2A532C00458D91 /* Info.plist */,
787783
9B74BCBE2333F4ED00508F84 /* run-bundled-codegen.sh */,
788-
9FE3F3971DADBD870072078F /* check-and-run-apollo-cli.sh */,
789-
9F2A74DA2137C21500E63C85 /* check-and-run-apollo-codegen.sh */,
790784
);
791785
name = "Supporting Files";
792786
sourceTree = "<group>";
@@ -1064,8 +1058,6 @@
10641058
isa = PBXResourcesBuildPhase;
10651059
buildActionMask = 2147483647;
10661060
files = (
1067-
9F2A74DB2137C21500E63C85 /* check-and-run-apollo-codegen.sh in Resources */,
1068-
9FE3F3981DADBD870072078F /* check-and-run-apollo-cli.sh in Resources */,
10691061
);
10701062
runOnlyForDeploymentPostprocessing = 0;
10711063
};
@@ -1132,7 +1124,7 @@
11321124
);
11331125
runOnlyForDeploymentPostprocessing = 0;
11341126
shellPath = /bin/sh;
1135-
shellScript = "# Do some magic so we can make sure `FRAMEWORK_SEARCH_PATHS` works correctly when there's a space in the scheme or the folder name.\nQUOTED_FRAMEWORK_SEARCH_PATHS=\\\"$(echo $FRAMEWORK_SEARCH_PATHS | tr -d '\"' | sed -e 's/ \\//\" \"\\//g')\\\"\n\n# Get the first result searching for the framework\nAPOLLO_FRAMEWORK_PATH=\"$(eval find ${QUOTED_FRAMEWORK_SEARCH_PATHS} -name \"Apollo.framework\" -maxdepth 1 -print | head -n 1)\"\n\nif [ -z \"${APOLLO_FRAMEWORK_PATH}\" ]; then\n echo \"error: Couldn't find Apollo.framework in FRAMEWORK_SEARCH_PATHS; make sure to add the framework to your project.\"\n exit 1\nfi\n\ncd ${SRCROOT}/Tests/GitHubAPI\nif [[ $SDK_NAME == *\"macos\"* ]]; then\n # Run the mac script\n \"${APOLLO_FRAMEWORK_PATH}\"/Versions/Current/Resources/check-and-run-apollo-cli.sh codegen:generate --target=swift --includes=./**/*.graphql --localSchemaFile=\"schema.json\" --mergeInFieldsFromFragmentSpreads API.swift\nelse\n # Run the non-mac script\n\"${APOLLO_FRAMEWORK_PATH}\"/check-and-run-apollo-cli.sh codegen:generate --target=swift --includes=./**/*.graphql --localSchemaFile=\"schema.json\" --mergeInFieldsFromFragmentSpreads API.swift\nfi\n";
1127+
shellScript = "SCRIPT_PATH=\"${SRCROOT}/scripts/run-bundled-codegen.sh\"\n\ncd \"${SRCROOT}/Tests/GitHubAPI\"\n\n\"${SCRIPT_PATH}\" codegen:generate --target=swift --localSchemaFile=\"schema.json\" --includes=./**/*.graphql --suppressSwiftMultilineStringLiterals --mergeInFieldsFromFragmentSpreads API.swift\n";
11361128
};
11371129
9FCE2D061E6C251100E34457 /* Generate Apollo Client API */ = {
11381130
isa = PBXShellScriptBuildPhase;

Apollo.xcodeproj/xcshareddata/xcschemes/Apollo.xcscheme

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,25 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "NO"
2930
codeCoverageEnabled = "YES"
30-
onlyGenerateCoverageForSpecifiedTargets = "YES"
31-
shouldUseLaunchSchemeArgsEnv = "NO">
31+
onlyGenerateCoverageForSpecifiedTargets = "YES">
32+
<MacroExpansion>
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "9FC750431D2A532C00458D91"
36+
BuildableName = "Apollo.framework"
37+
BlueprintName = "Apollo"
38+
ReferencedContainer = "container:Apollo.xcodeproj">
39+
</BuildableReference>
40+
</MacroExpansion>
41+
<EnvironmentVariables>
42+
<EnvironmentVariable
43+
key = "APOLLO_TEST_CACHE_PROVIDER"
44+
value = "ApolloTestSupport.InMemoryTestCacheProvider"
45+
isEnabled = "YES">
46+
</EnvironmentVariable>
47+
</EnvironmentVariables>
3248
<CodeCoverageTargets>
3349
<BuildableReference
3450
BuildableIdentifier = "primary"
@@ -60,24 +76,6 @@
6076
</BuildableReference>
6177
</TestableReference>
6278
</Testables>
63-
<MacroExpansion>
64-
<BuildableReference
65-
BuildableIdentifier = "primary"
66-
BlueprintIdentifier = "9FC750431D2A532C00458D91"
67-
BuildableName = "Apollo.framework"
68-
BlueprintName = "Apollo"
69-
ReferencedContainer = "container:Apollo.xcodeproj">
70-
</BuildableReference>
71-
</MacroExpansion>
72-
<EnvironmentVariables>
73-
<EnvironmentVariable
74-
key = "APOLLO_TEST_CACHE_PROVIDER"
75-
value = "ApolloTestSupport.InMemoryTestCacheProvider"
76-
isEnabled = "YES">
77-
</EnvironmentVariable>
78-
</EnvironmentVariables>
79-
<AdditionalOptions>
80-
</AdditionalOptions>
8179
</TestAction>
8280
<LaunchAction
8381
buildConfiguration = "Debug"
@@ -98,8 +96,6 @@
9896
ReferencedContainer = "container:Apollo.xcodeproj">
9997
</BuildableReference>
10098
</MacroExpansion>
101-
<AdditionalOptions>
102-
</AdditionalOptions>
10399
</LaunchAction>
104100
<ProfileAction
105101
buildConfiguration = "Release"

Sources/Apollo/JSONSerialziation+Sorting.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@ extension JSONSerialization {
2020
// presently support, but we should use it where we can in
2121
// order to get stable JSON representations, especially if being
2222
// used in queries.
23-
if #available(iOS 11, macOS 13, watchOS 4, tvOS 11, *) {
23+
if #available(iOS 11, macOS 10.13, watchOS 4, tvOS 11, *) {
2424
return try self.data(withJSONObject: object, options: [.sortedKeys])
2525
} else {
2626
return try self.data(withJSONObject: object)
2727
}
2828
}
29+
30+
/// Wrapper function so we don't have to scatter `if #available` all over the codebase to see if data can be sorted.
31+
static func dataCanBeSorted() -> Bool {
32+
if #available(iOS 11, macOS 10.13, watchOS 4, tvOS 11, *) {
33+
return true
34+
} else {
35+
return false
36+
}
37+
}
2938
}

Tests/ApolloTests/GETTransformerTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class GETTransformerTests: XCTestCase {
2222

2323
let url = transformer.createGetURL()
2424

25-
XCTAssertEqual(url?.absoluteString, "http://localhost:8080/graphql?operationName=HeroName&query=query%20HeroName($episode:%20Episode)%20%7B%20hero(episode:%20$episode)%20%7B%20__typename%20name%20%7D%20%7D&variables=%7B%22episode%22:%22EMPIRE%22%7D")
25+
XCTAssertEqual(url?.absoluteString, "http://localhost:8080/graphql?operationName=HeroName&query=query%20HeroName($episode:%20Episode)%20%7B%0A%20%20hero(episode:%20$episode)%20%7B%0A%20%20%20%20__typename%0A%20%20%20%20name%0A%20%20%7D%0A%7D&variables=%7B%22episode%22:%22EMPIRE%22%7D")
2626
}
2727

2828
func testEncodingQueryWithMoreThanOneParameterIncludingNonHashableValue() {
@@ -33,10 +33,10 @@ class GETTransformerTests: XCTestCase {
3333

3434
let url = transformer.createGetURL()
3535

36-
if #available(iOS 11, macOS 13, tvOS 11, watchOS 4, *) {
36+
if JSONSerialization.dataCanBeSorted() {
3737
// Here, we know that everything should be encoded in a stable order,
3838
// and we can check the encoded URL string directly.
39-
XCTAssertEqual(url?.absoluteString, "http://localhost:8080/graphql?operationName=HeroNameTypeSpecificConditionalInclusion&query=query%20HeroNameTypeSpecificConditionalInclusion($episode:%20Episode,%20$includeName:%20Boolean!)%20%7B%20hero(episode:%20$episode)%20%7B%20__typename%20name%20@include(if:%20$includeName)%20...%20on%20Droid%20%7B%20name%20%7D%20%7D%20%7D&variables=%7B%22episode%22:%22JEDI%22,%22includeName%22:true%7D")
39+
XCTAssertEqual(url?.absoluteString, "http://localhost:8080/graphql?operationName=HeroNameTypeSpecificConditionalInclusion&query=query%20HeroNameTypeSpecificConditionalInclusion($episode:%20Episode,%20$includeName:%20Boolean!)%20%7B%0A%20%20hero(episode:%20$episode)%20%7B%0A%20%20%20%20__typename%0A%20%20%20%20name%20@include(if:%20$includeName)%0A%20%20%20%20...%20on%20Droid%20%7B%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D&variables=%7B%22episode%22:%22JEDI%22,%22includeName%22:true%7D")
4040
} else {
4141
// We can't guarantee order of encoding, so we need to pull the JSON back
4242
// out and check that it has the correct and correctly typed properties.
@@ -96,6 +96,6 @@ class GETTransformerTests: XCTestCase {
9696

9797
let url = transformer.createGetURL()
9898

99-
XCTAssertEqual(url?.absoluteString, "http://localhost:8080/graphql?operationName=HeroName&query=query%20HeroName($episode:%20Episode)%20%7B%20hero(episode:%20$episode)%20%7B%20__typename%20name%20%7D%20%7D&variables=%7B%22episode%22:null%7D")
99+
XCTAssertEqual(url?.absoluteString, "http://localhost:8080/graphql?operationName=HeroName&query=query%20HeroName($episode:%20Episode)%20%7B%0A%20%20hero(episode:%20$episode)%20%7B%0A%20%20%20%20__typename%0A%20%20%20%20name%0A%20%20%7D%0A%7D&variables=%7B%22episode%22:null%7D")
100100
}
101101
}

Tests/ApolloTests/RequestCreatorTests.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@ Charlie file content.
177177

178178
let stringToCompare = try self.string(from: data)
179179

180-
if #available(iOS 11, macOS 13, tvOS 11, watchOS 4, *) {
180+
if JSONSerialization.dataCanBeSorted() {
181181
let expectedString = """
182182
--TEST.BOUNDARY
183183
Content-Disposition: form-data; name="operations"
184184
185-
{"operationName":"HeroName","query":"query HeroName($episode: Episode) { hero(episode: $episode) { __typename name } }","variables":{"episode":null,\"upload\":null}}
185+
{"operationName":"HeroName","query":"query HeroName($episode: Episode) {\\n hero(episode: $episode) {\\n __typename\\n name\\n }\\n}","variables":{"episode":null,"upload":null}}
186186
--TEST.BOUNDARY
187187
Content-Disposition: form-data; name="map"
188188
@@ -239,12 +239,12 @@ Alpha file content.
239239

240240
let stringToCompare = try self.string(from: data)
241241

242-
if #available(iOS 11, macOS 13, tvOS 11, watchOS 4, *) {
242+
if JSONSerialization.dataCanBeSorted() {
243243
let expectedString = """
244244
--TEST.BOUNDARY
245245
Content-Disposition: form-data; name="operations"
246246
247-
{"operationName":"HeroName","query":"query HeroName($episode: Episode) { hero(episode: $episode) { __typename name } }","variables":{"episode":null,\"uploads\":null}}
247+
{"operationName":"HeroName","query":"query HeroName($episode: Episode) {\\n hero(episode: $episode) {\\n __typename\\n name\\n }\\n}","variables":{"episode":null,\"uploads\":null}}
248248
--TEST.BOUNDARY
249249
Content-Disposition: form-data; name="map"
250250
@@ -327,7 +327,12 @@ Alpha file content.
327327
--TEST.BOUNDARY
328328
Content-Disposition: form-data; name="test_query"
329329
330-
query HeroName($episode: Episode) { hero(episode: $episode) { __typename name } }
330+
query HeroName($episode: Episode) {
331+
hero(episode: $episode) {
332+
__typename
333+
name
334+
}
335+
}
331336
"""
332337
self.checkString(stringToCompare, includes: expectedEndString)
333338
self.checkString(stringToCompare, includes: expectedQueryString)

Tests/GitHubAPI/API.swift

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,10 @@
11
// This file was automatically generated and should not be edited.
22

33
import Apollo
4+
import Foundation
45

56
public final class RepositoryQuery: GraphQLQuery {
6-
/// query Repository {
7-
/// repository(owner: "apollographql", name: "apollo-ios") {
8-
/// __typename
9-
/// issueOrPullRequest(number: 13) {
10-
/// __typename
11-
/// ... on Issue {
12-
/// body
13-
/// ... on UniformResourceLocatable {
14-
/// url
15-
/// }
16-
/// author {
17-
/// __typename
18-
/// avatarUrl
19-
/// }
20-
/// }
21-
/// ... on Reactable {
22-
/// viewerCanReact
23-
/// ... on Comment {
24-
/// author {
25-
/// __typename
26-
/// login
27-
/// }
28-
/// }
29-
/// }
30-
/// }
31-
/// }
32-
/// }
7+
/// The raw GraphQL definition of this operation.
338
public let operationDefinition =
349
"query Repository { repository(owner: \"apollographql\", name: \"apollo-ios\") { __typename issueOrPullRequest(number: 13) { __typename ... on Issue { body ... on UniformResourceLocatable { url } author { __typename avatarUrl } } ... on Reactable { viewerCanReact ... on Comment { author { __typename login } } } } } }"
3510

@@ -351,12 +326,7 @@ public final class RepositoryQuery: GraphQLQuery {
351326
}
352327

353328
public final class RepoUrlQuery: GraphQLQuery {
354-
/// query RepoURL {
355-
/// repository(owner: "apollographql", name: "apollo-ios") {
356-
/// __typename
357-
/// url
358-
/// }
359-
/// }
329+
/// The raw GraphQL definition of this operation.
360330
public let operationDefinition =
361331
"query RepoURL { repository(owner: \"apollographql\", name: \"apollo-ios\") { __typename url } }"
362332

0 commit comments

Comments
 (0)