Skip to content

Commit 0cc333d

Browse files
Merge pull request #767 from apollographql/support_get_apqs
Support Auto-Persisted Queries
2 parents 30eacb1 + e9806cc commit 0cc333d

17 files changed

Lines changed: 1126 additions & 61 deletions

Apollo.xcodeproj/project.pbxproj

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/* Begin PBXBuildFile section */
1010
54DDB0921EA045870009DD99 /* InMemoryNormalizedCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54DDB0911EA045870009DD99 /* InMemoryNormalizedCache.swift */; };
1111
5AC6CA4322AAF7B200B7C94D /* GraphQLHTTPMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AC6CA4222AAF7B200B7C94D /* GraphQLHTTPMethod.swift */; };
12+
9B1A38532332AF6F00325FB4 /* String+SHA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B1A38522332AF6F00325FB4 /* String+SHA.swift */; };
13+
9B64F6762354D219002D1BB5 /* URL+QueryDict.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B64F6752354D219002D1BB5 /* URL+QueryDict.swift */; };
1214
9B708AAD2305884500604A11 /* ApolloClientProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B708AAC2305884500604A11 /* ApolloClientProtocol.swift */; };
1315
9B78C71E2326E86E000C8C32 /* ErrorGenerationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B78C71B2326E859000C8C32 /* ErrorGenerationTests.swift */; };
1416
9B95EDC022CAA0B000702BB2 /* GETTransformerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B95EDBF22CAA0AF00702BB2 /* GETTransformerTests.swift */; };
@@ -117,6 +119,8 @@
117119
C377CCAB22D7992E00572E03 /* MultipartFormData.swift in Sources */ = {isa = PBXBuildFile; fileRef = C377CCAA22D7992E00572E03 /* MultipartFormData.swift */; };
118120
E86D8E05214B32FD0028EFE1 /* JSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E86D8E03214B32DA0028EFE1 /* JSONTests.swift */; };
119121
F16D083C21EF6F7300C458B8 /* QueryFromJSONBuildingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F16D083B21EF6F7300C458B8 /* QueryFromJSONBuildingTests.swift */; };
122+
F82E62E122BCD223000C311B /* AutomaticPersistedQueriesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F82E62E022BCD223000C311B /* AutomaticPersistedQueriesTests.swift */; };
123+
F8AB781B22E1B4BB00A50B81 /* MockURLSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8AB781A22E1B4BB00A50B81 /* MockURLSession.swift */; };
120124
/* End PBXBuildFile section */
121125

122126
/* Begin PBXContainerItemProxy section */
@@ -264,6 +268,8 @@
264268
90690D2322433C5900FC2E54 /* Apollo-Target-CacheDependentTests.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Apollo-Target-CacheDependentTests.xcconfig"; sourceTree = "<group>"; };
265269
90690D2422433C8000FC2E54 /* Apollo-Target-PerformanceTests.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Apollo-Target-PerformanceTests.xcconfig"; sourceTree = "<group>"; };
266270
90690D2522433CAF00FC2E54 /* Apollo-Target-TestSupport.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Apollo-Target-TestSupport.xcconfig"; sourceTree = "<group>"; };
271+
9B1A38522332AF6F00325FB4 /* String+SHA.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+SHA.swift"; sourceTree = "<group>"; };
272+
9B64F6752354D219002D1BB5 /* URL+QueryDict.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+QueryDict.swift"; sourceTree = "<group>"; };
267273
9B708AAC2305884500604A11 /* ApolloClientProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApolloClientProtocol.swift; sourceTree = "<group>"; };
268274
9B74BCBE2333F4ED00508F84 /* run-bundled-codegen.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; name = "run-bundled-codegen.sh"; path = "scripts/run-bundled-codegen.sh"; sourceTree = SOURCE_ROOT; };
269275
9B78C71B2326E859000C8C32 /* ErrorGenerationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorGenerationTests.swift; sourceTree = "<group>"; };
@@ -386,6 +392,9 @@
386392
C377CCAA22D7992E00572E03 /* MultipartFormData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultipartFormData.swift; sourceTree = "<group>"; };
387393
E86D8E03214B32DA0028EFE1 /* JSONTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONTests.swift; sourceTree = "<group>"; };
388394
F16D083B21EF6F7300C458B8 /* QueryFromJSONBuildingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryFromJSONBuildingTests.swift; sourceTree = "<group>"; };
395+
F82E62E022BCD223000C311B /* AutomaticPersistedQueriesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AutomaticPersistedQueriesTests.swift; sourceTree = "<group>"; };
396+
F8AB781A22E1B4BB00A50B81 /* MockURLSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockURLSession.swift; sourceTree = "<group>"; };
397+
F8E9D8AE22B2492C0065DA98 /* schema.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = schema.json; sourceTree = "<group>"; };
389398
/* End PBXFileReference section */
390399

391400
/* Begin PBXFrameworksBuildPhase section */
@@ -546,6 +555,7 @@
546555
9F8A95811EC0FD3300304A2D /* XCTAssertHelpers.swift */,
547556
9F8A95831EC0FD6100304A2D /* XCTestCase+Promise.swift */,
548557
9F10A51D1EC1BA0F0045E62B /* MockNetworkTransport.swift */,
558+
F8AB781A22E1B4BB00A50B81 /* MockURLSession.swift */,
549559
9F8A95851EC0FD9800304A2D /* TestCacheProvider.swift */,
550560
9F8A957A1EC0FC1200304A2D /* ApolloTestSupport.h */,
551561
9F8A957B1EC0FC1200304A2D /* Info.plist */,
@@ -653,6 +663,7 @@
653663
isa = PBXGroup;
654664
children = (
655665
9FC750551D2A532D00458D91 /* Info.plist */,
666+
F82E62E022BCD223000C311B /* AutomaticPersistedQueriesTests.swift */,
656667
9F438D0B1E6C494C007BDC1A /* BatchedLoadTests.swift */,
657668
9FC9A9C71E2EFE6E0023C4D5 /* CacheKeyForFieldTests.swift */,
658669
9FADC8531E6B86D900C677E6 /* DataLoaderTests.swift */,
@@ -671,6 +682,7 @@
671682
C338DF1622DD9DE9006AF33E /* RequestCreatorTests.swift */,
672683
9F19D8451EED8D3B00C57247 /* ResultOrPromiseTests.swift */,
673684
C3279FC52345233000224790 /* TestCustomRequestCreator.swift */,
685+
9B64F6752354D219002D1BB5 /* URL+QueryDict.swift */,
674686
C304EBD322DDC7B200748F72 /* a.txt */,
675687
C35D43BE22DDD3C100BCBABE /* b.txt */,
676688
C35D43BF22DDD3C100BCBABE /* c.txt */,
@@ -719,6 +731,7 @@
719731
9F19D8431EED568200C57247 /* ResultOrPromise.swift */,
720732
9FEC15B31E681DAD00D461B4 /* Collections.swift */,
721733
9FADC8491E6B0B2300C677E6 /* Locking.swift */,
734+
9B1A38522332AF6F00325FB4 /* String+SHA.swift */,
722735
);
723736
name = Utilities;
724737
sourceTree = "<group>";
@@ -756,6 +769,7 @@
756769
9FCE2D171E6C259B00E34457 /* Starship.graphql */,
757770
9FCE2D0C1E6C259B00E34457 /* CreateReviewForEpisode.graphql */,
758771
9FCE2D0A1E6C258A00E34457 /* API.swift */,
772+
F8E9D8AE22B2492C0065DA98 /* schema.json */,
759773
9FCE2CFC1E6C213D00E34457 /* StarWarsAPI.h */,
760774
9FCE2CFD1E6C213D00E34457 /* Info.plist */,
761775
);
@@ -1124,7 +1138,7 @@
11241138
);
11251139
runOnlyForDeploymentPostprocessing = 0;
11261140
shellPath = /bin/sh;
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";
1141+
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 --operationIdsPath=operationIdsPath.json --suppressSwiftMultilineStringLiterals --mergeInFieldsFromFragmentSpreads API.swift\n";
11281142
};
11291143
9FCE2D061E6C251100E34457 /* Generate Apollo Client API */ = {
11301144
isa = PBXShellScriptBuildPhase;
@@ -1138,7 +1152,7 @@
11381152
);
11391153
runOnlyForDeploymentPostprocessing = 0;
11401154
shellPath = /bin/sh;
1141-
shellScript = "SCRIPT_PATH=\"${SRCROOT}/scripts/run-bundled-codegen.sh\"\n\ncd \"${SRCROOT}/Tests/StarWarsAPI\"\n\n\"${SCRIPT_PATH}\" codegen:generate --target=swift --localSchemaFile=\"schema.json\" --includes=./**/*.graphql --mergeInFieldsFromFragmentSpreads API.swift\n";
1155+
shellScript = "SCRIPT_PATH=\"${SRCROOT}/scripts/run-bundled-codegen.sh\"\n\ncd \"${SRCROOT}/Tests/StarWarsAPI\"\n\n\"${SCRIPT_PATH}\" codegen:generate --target=swift --localSchemaFile=\"schema.json\" --includes=./**/*.graphql --operationIdsPath=operationIdsPath.json --mergeInFieldsFromFragmentSpreads API.swift\n";
11421156
showEnvVarsInLog = 0;
11431157
};
11441158
/* End PBXShellScriptBuildPhase section */
@@ -1151,6 +1165,7 @@
11511165
9F8A95841EC0FD6100304A2D /* XCTestCase+Promise.swift in Sources */,
11521166
9F8A95821EC0FD3300304A2D /* XCTAssertHelpers.swift in Sources */,
11531167
9F10A51E1EC1BA0F0045E62B /* MockNetworkTransport.swift in Sources */,
1168+
F8AB781B22E1B4BB00A50B81 /* MockURLSession.swift in Sources */,
11541169
9F8A95861EC0FD9800304A2D /* TestCacheProvider.swift in Sources */,
11551170
);
11561171
runOnlyForDeploymentPostprocessing = 0;
@@ -1222,6 +1237,7 @@
12221237
9FADC84F1E6B865E00C677E6 /* DataLoader.swift in Sources */,
12231238
9FF90A611DDDEB100034C3B6 /* GraphQLResponse.swift in Sources */,
12241239
9F27D4641D40379500715680 /* JSONStandardTypeConversions.swift in Sources */,
1240+
9B1A38532332AF6F00325FB4 /* String+SHA.swift in Sources */,
12251241
9BEDC79E22E5D2CF00549BF6 /* RequestCreator.swift in Sources */,
12261242
9FA6F3681E65DF4700BF8D73 /* GraphQLResultAccumulator.swift in Sources */,
12271243
9FF90A651DDDEB100034C3B6 /* GraphQLExecutor.swift in Sources */,
@@ -1244,12 +1260,14 @@
12441260
9B78C71E2326E86E000C8C32 /* ErrorGenerationTests.swift in Sources */,
12451261
9FC9A9C81E2EFE6E0023C4D5 /* CacheKeyForFieldTests.swift in Sources */,
12461262
9F91CF8F1F6C0DB2008DD0BE /* MutatingResultsTests.swift in Sources */,
1263+
F82E62E122BCD223000C311B /* AutomaticPersistedQueriesTests.swift in Sources */,
12471264
9F19D8461EED8D3B00C57247 /* ResultOrPromiseTests.swift in Sources */,
12481265
9F533AB31E6C4A4200CBE097 /* BatchedLoadTests.swift in Sources */,
12491266
C3279FC72345234D00224790 /* TestCustomRequestCreator.swift in Sources */,
12501267
9B95EDC022CAA0B000702BB2 /* GETTransformerTests.swift in Sources */,
12511268
9FF90A6F1DDDEB420034C3B6 /* InputValueEncodingTests.swift in Sources */,
12521269
9FE1C6E71E634C8D00C02284 /* PromiseTests.swift in Sources */,
1270+
9B64F6762354D219002D1BB5 /* URL+QueryDict.swift in Sources */,
12531271
9FADC8541E6B86D900C677E6 /* DataLoaderTests.swift in Sources */,
12541272
E86D8E05214B32FD0028EFE1 /* JSONTests.swift in Sources */,
12551273
9F8622FA1EC2117C00C38162 /* FragmentConstructionAndConversionTests.swift in Sources */,

Sources/Apollo/GraphQLGETTransformer.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ struct GraphQLGETTransformer {
1313
let body: GraphQLMap
1414
let url: URL
1515

16-
private let variablesKey = "variables"
17-
private let queryKey = "query"
18-
1916
/// A helper for transforming a GraphQLMap that can be sent with a `POST` request into a URL with query parameters for a `GET` request.
2017
///
2118
/// - Parameters:
@@ -46,15 +43,16 @@ struct GraphQLGETTransformer {
4643
}
4744
} else if let string = arg.value as? String {
4845
queryItems.append(URLQueryItem(name: arg.key, value: string))
49-
} else {
46+
} else if (arg.key != "variables") {
5047
assertionFailure()
5148
}
5249
})
5350
} catch {
5451
return nil
5552
}
56-
53+
5754
components.queryItems = queryItems
55+
5856
return components.url
5957
}
6058
}

Sources/Apollo/GraphQLHTTPResponseError.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ public struct GraphQLHTTPResponseError: Error, LocalizedError {
55
public enum ErrorKind {
66
case errorResponse
77
case invalidResponse
8+
case persistedQueryNotFound
9+
case persistedQueryNotSupported
810

911
var description: String {
1012
switch self {
1113
case .errorResponse:
1214
return "Received error response"
1315
case .invalidResponse:
1416
return "Received invalid response"
17+
case .persistedQueryNotFound:
18+
return "Persisted query not found"
19+
case .persistedQueryNotSupported:
20+
return "Persisted query not supported"
1521
}
1622
}
1723
}

Sources/Apollo/GraphQLResponse.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ public final class GraphQLResponse<Operation: GraphQLOperation> {
3838
}
3939
}
4040

41-
func parseResultFast() throws -> GraphQLResult<Operation.Data> {
42-
let errors: [GraphQLError]?
43-
44-
if let errorsEntry = body["errors"] as? [JSONObject] {
45-
errors = errorsEntry.map(GraphQLError.init)
46-
} else {
47-
errors = nil
41+
func parseErrorsOnlyFast() -> [GraphQLError]? {
42+
guard let errorsEntry = self.body["errors"] as? [JSONObject] else {
43+
return nil
4844
}
4945

46+
return errorsEntry.map(GraphQLError.init)
47+
}
48+
49+
func parseResultFast() throws -> GraphQLResult<Operation.Data> {
50+
let errors = self.parseErrorsOnlyFast()
51+
5052
if let dataEntry = body["data"] as? JSONObject {
5153
let data = try decode(selectionSet: Operation.Data.self, from: dataEntry, variables: operation.variables)
5254
return GraphQLResult(data: data, errors: errors, source: .server, dependentKeys: nil)

0 commit comments

Comments
 (0)