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

Support Auto-Persisted Queries #767

Merged
merged 24 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2c8da2e
Fix codegen fail for StarWarsAPI and GitHubAPI, add operationIdentifi…
Jun 13, 2019
9fa6349
Fix codegen fail for StarWarsAPI and GitHubAPI, add operationIdentifi…
Jun 13, 2019
48315cd
added apqs with get support
Jul 2, 2019
8698e81
refactor for fetchOption
Jul 2, 2019
55bb400
throw GraphQLHTTPRequestError for JSON serialization error handling
Jul 3, 2019
6f25277
1. add sorting logic in GraphQLGETTransformer
Jul 16, 2019
3216c59
rename HttpNetworkTransportTests to AutomaticPersistedQueriesTests
Jul 16, 2019
2e66ece
removed force unwrap in test cases
Jul 17, 2019
6d7af3d
use url.queryItems to test urlQuery against 2d GraphQLMap in GETTrans…
Jul 17, 2019
8c6b303
splited MockURLSession to single file
Jul 19, 2019
d51c67a
update to use XCTAssertEqual in GETTransformerTests
Jul 19, 2019
ef9db78
Merge branch 'master' into support_get_apqs + fix merge conflicts
designatednerd Sep 16, 2019
32c3544
definitely legal for variables to have a null value
designatednerd Sep 16, 2019
93c36db
better error handling
designatednerd Sep 16, 2019
8298ef2
add ability to grab SHA256Hash of an operation if needed.
designatednerd Sep 18, 2019
9799592
use the pre-calculated hash if possible but do it live if necessary
designatednerd Sep 18, 2019
815d5a3
update API with pending version of CLI
designatednerd Sep 19, 2019
2827e00
update tests to account for multiline strings
designatednerd Sep 19, 2019
ece84b7
Merge branch 'master' into support_get_apqs + fix merge conflicts
designatednerd Sep 25, 2019
a70ccd6
Merge branch 'master' into support_get_apqs
designatednerd Oct 2, 2019
f6abc2d
Merge branch 'master' into support_get_apqs + fix merge conflicts
designatednerd Oct 10, 2019
8c170b8
Merge branch 'master' into support_get_apqs
designatednerd Oct 10, 2019
4ab4184
move APQ tests to correct folder, pull URL extension into its own file
designatednerd Oct 14, 2019
e9806cc
Merge branch 'master' into support_get_apqs
designatednerd Oct 14, 2019
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
22 changes: 20 additions & 2 deletions Apollo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/* Begin PBXBuildFile section */
54DDB0921EA045870009DD99 /* InMemoryNormalizedCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54DDB0911EA045870009DD99 /* InMemoryNormalizedCache.swift */; };
5AC6CA4322AAF7B200B7C94D /* GraphQLHTTPMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AC6CA4222AAF7B200B7C94D /* GraphQLHTTPMethod.swift */; };
9B1A38532332AF6F00325FB4 /* String+SHA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B1A38522332AF6F00325FB4 /* String+SHA.swift */; };
9B64F6762354D219002D1BB5 /* URL+QueryDict.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B64F6752354D219002D1BB5 /* URL+QueryDict.swift */; };
9B708AAD2305884500604A11 /* ApolloClientProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B708AAC2305884500604A11 /* ApolloClientProtocol.swift */; };
9B78C71E2326E86E000C8C32 /* ErrorGenerationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B78C71B2326E859000C8C32 /* ErrorGenerationTests.swift */; };
9B95EDC022CAA0B000702BB2 /* GETTransformerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B95EDBF22CAA0AF00702BB2 /* GETTransformerTests.swift */; };
Expand Down Expand Up @@ -117,6 +119,8 @@
C377CCAB22D7992E00572E03 /* MultipartFormData.swift in Sources */ = {isa = PBXBuildFile; fileRef = C377CCAA22D7992E00572E03 /* MultipartFormData.swift */; };
E86D8E05214B32FD0028EFE1 /* JSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E86D8E03214B32DA0028EFE1 /* JSONTests.swift */; };
F16D083C21EF6F7300C458B8 /* QueryFromJSONBuildingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F16D083B21EF6F7300C458B8 /* QueryFromJSONBuildingTests.swift */; };
F82E62E122BCD223000C311B /* AutomaticPersistedQueriesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F82E62E022BCD223000C311B /* AutomaticPersistedQueriesTests.swift */; };
F8AB781B22E1B4BB00A50B81 /* MockURLSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8AB781A22E1B4BB00A50B81 /* MockURLSession.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -264,6 +268,8 @@
90690D2322433C5900FC2E54 /* Apollo-Target-CacheDependentTests.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Apollo-Target-CacheDependentTests.xcconfig"; sourceTree = "<group>"; };
90690D2422433C8000FC2E54 /* Apollo-Target-PerformanceTests.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Apollo-Target-PerformanceTests.xcconfig"; sourceTree = "<group>"; };
90690D2522433CAF00FC2E54 /* Apollo-Target-TestSupport.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Apollo-Target-TestSupport.xcconfig"; sourceTree = "<group>"; };
9B1A38522332AF6F00325FB4 /* String+SHA.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+SHA.swift"; sourceTree = "<group>"; };
9B64F6752354D219002D1BB5 /* URL+QueryDict.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+QueryDict.swift"; sourceTree = "<group>"; };
9B708AAC2305884500604A11 /* ApolloClientProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApolloClientProtocol.swift; sourceTree = "<group>"; };
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; };
9B78C71B2326E859000C8C32 /* ErrorGenerationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorGenerationTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -386,6 +392,9 @@
C377CCAA22D7992E00572E03 /* MultipartFormData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultipartFormData.swift; sourceTree = "<group>"; };
E86D8E03214B32DA0028EFE1 /* JSONTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONTests.swift; sourceTree = "<group>"; };
F16D083B21EF6F7300C458B8 /* QueryFromJSONBuildingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryFromJSONBuildingTests.swift; sourceTree = "<group>"; };
F82E62E022BCD223000C311B /* AutomaticPersistedQueriesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AutomaticPersistedQueriesTests.swift; sourceTree = "<group>"; };
F8AB781A22E1B4BB00A50B81 /* MockURLSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockURLSession.swift; sourceTree = "<group>"; };
F8E9D8AE22B2492C0065DA98 /* schema.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = schema.json; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -546,6 +555,7 @@
9F8A95811EC0FD3300304A2D /* XCTAssertHelpers.swift */,
9F8A95831EC0FD6100304A2D /* XCTestCase+Promise.swift */,
9F10A51D1EC1BA0F0045E62B /* MockNetworkTransport.swift */,
F8AB781A22E1B4BB00A50B81 /* MockURLSession.swift */,
9F8A95851EC0FD9800304A2D /* TestCacheProvider.swift */,
9F8A957A1EC0FC1200304A2D /* ApolloTestSupport.h */,
9F8A957B1EC0FC1200304A2D /* Info.plist */,
Expand Down Expand Up @@ -653,6 +663,7 @@
isa = PBXGroup;
children = (
9FC750551D2A532D00458D91 /* Info.plist */,
F82E62E022BCD223000C311B /* AutomaticPersistedQueriesTests.swift */,
9F438D0B1E6C494C007BDC1A /* BatchedLoadTests.swift */,
9FC9A9C71E2EFE6E0023C4D5 /* CacheKeyForFieldTests.swift */,
9FADC8531E6B86D900C677E6 /* DataLoaderTests.swift */,
Expand All @@ -671,6 +682,7 @@
C338DF1622DD9DE9006AF33E /* RequestCreatorTests.swift */,
9F19D8451EED8D3B00C57247 /* ResultOrPromiseTests.swift */,
C3279FC52345233000224790 /* TestCustomRequestCreator.swift */,
9B64F6752354D219002D1BB5 /* URL+QueryDict.swift */,
C304EBD322DDC7B200748F72 /* a.txt */,
C35D43BE22DDD3C100BCBABE /* b.txt */,
C35D43BF22DDD3C100BCBABE /* c.txt */,
Expand Down Expand Up @@ -719,6 +731,7 @@
9F19D8431EED568200C57247 /* ResultOrPromise.swift */,
9FEC15B31E681DAD00D461B4 /* Collections.swift */,
9FADC8491E6B0B2300C677E6 /* Locking.swift */,
9B1A38522332AF6F00325FB4 /* String+SHA.swift */,
);
name = Utilities;
sourceTree = "<group>";
Expand Down Expand Up @@ -756,6 +769,7 @@
9FCE2D171E6C259B00E34457 /* Starship.graphql */,
9FCE2D0C1E6C259B00E34457 /* CreateReviewForEpisode.graphql */,
9FCE2D0A1E6C258A00E34457 /* API.swift */,
F8E9D8AE22B2492C0065DA98 /* schema.json */,
9FCE2CFC1E6C213D00E34457 /* StarWarsAPI.h */,
9FCE2CFD1E6C213D00E34457 /* Info.plist */,
);
Expand Down Expand Up @@ -1124,7 +1138,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
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";
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";
};
9FCE2D061E6C251100E34457 /* Generate Apollo Client API */ = {
isa = PBXShellScriptBuildPhase;
Expand All @@ -1138,7 +1152,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
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";
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";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
Expand All @@ -1151,6 +1165,7 @@
9F8A95841EC0FD6100304A2D /* XCTestCase+Promise.swift in Sources */,
9F8A95821EC0FD3300304A2D /* XCTAssertHelpers.swift in Sources */,
9F10A51E1EC1BA0F0045E62B /* MockNetworkTransport.swift in Sources */,
F8AB781B22E1B4BB00A50B81 /* MockURLSession.swift in Sources */,
9F8A95861EC0FD9800304A2D /* TestCacheProvider.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1222,6 +1237,7 @@
9FADC84F1E6B865E00C677E6 /* DataLoader.swift in Sources */,
9FF90A611DDDEB100034C3B6 /* GraphQLResponse.swift in Sources */,
9F27D4641D40379500715680 /* JSONStandardTypeConversions.swift in Sources */,
9B1A38532332AF6F00325FB4 /* String+SHA.swift in Sources */,
9BEDC79E22E5D2CF00549BF6 /* RequestCreator.swift in Sources */,
9FA6F3681E65DF4700BF8D73 /* GraphQLResultAccumulator.swift in Sources */,
9FF90A651DDDEB100034C3B6 /* GraphQLExecutor.swift in Sources */,
Expand All @@ -1244,12 +1260,14 @@
9B78C71E2326E86E000C8C32 /* ErrorGenerationTests.swift in Sources */,
9FC9A9C81E2EFE6E0023C4D5 /* CacheKeyForFieldTests.swift in Sources */,
9F91CF8F1F6C0DB2008DD0BE /* MutatingResultsTests.swift in Sources */,
F82E62E122BCD223000C311B /* AutomaticPersistedQueriesTests.swift in Sources */,
9F19D8461EED8D3B00C57247 /* ResultOrPromiseTests.swift in Sources */,
9F533AB31E6C4A4200CBE097 /* BatchedLoadTests.swift in Sources */,
C3279FC72345234D00224790 /* TestCustomRequestCreator.swift in Sources */,
9B95EDC022CAA0B000702BB2 /* GETTransformerTests.swift in Sources */,
9FF90A6F1DDDEB420034C3B6 /* InputValueEncodingTests.swift in Sources */,
9FE1C6E71E634C8D00C02284 /* PromiseTests.swift in Sources */,
9B64F6762354D219002D1BB5 /* URL+QueryDict.swift in Sources */,
9FADC8541E6B86D900C677E6 /* DataLoaderTests.swift in Sources */,
E86D8E05214B32FD0028EFE1 /* JSONTests.swift in Sources */,
9F8622FA1EC2117C00C38162 /* FragmentConstructionAndConversionTests.swift in Sources */,
Expand Down
8 changes: 3 additions & 5 deletions Sources/Apollo/GraphQLGETTransformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ struct GraphQLGETTransformer {
let body: GraphQLMap
let url: URL

private let variablesKey = "variables"
private let queryKey = "query"

/// A helper for transforming a GraphQLMap that can be sent with a `POST` request into a URL with query parameters for a `GET` request.
///
/// - Parameters:
Expand Down Expand Up @@ -46,15 +43,16 @@ struct GraphQLGETTransformer {
}
} else if let string = arg.value as? String {
queryItems.append(URLQueryItem(name: arg.key, value: string))
} else {
} else if (arg.key != "variables") {
assertionFailure()
}
})
} catch {
return nil
}

components.queryItems = queryItems

return components.url
}
}
Expand Down
6 changes: 6 additions & 0 deletions Sources/Apollo/GraphQLHTTPResponseError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ public struct GraphQLHTTPResponseError: Error, LocalizedError {
public enum ErrorKind {
case errorResponse
case invalidResponse
case persistedQueryNotFound
case persistedQueryNotSupported

var description: String {
switch self {
case .errorResponse:
return "Received error response"
case .invalidResponse:
return "Received invalid response"
case .persistedQueryNotFound:
return "Persisted query not found"
case .persistedQueryNotSupported:
return "Persisted query not supported"
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions Sources/Apollo/GraphQLResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ public final class GraphQLResponse<Operation: GraphQLOperation> {
}
}

func parseResultFast() throws -> GraphQLResult<Operation.Data> {
let errors: [GraphQLError]?

if let errorsEntry = body["errors"] as? [JSONObject] {
errors = errorsEntry.map(GraphQLError.init)
} else {
errors = nil
func parseErrorsOnlyFast() -> [GraphQLError]? {
guard let errorsEntry = self.body["errors"] as? [JSONObject] else {
return nil
}

return errorsEntry.map(GraphQLError.init)
}

func parseResultFast() throws -> GraphQLResult<Operation.Data> {
let errors = self.parseErrorsOnlyFast()

if let dataEntry = body["data"] as? JSONObject {
let data = try decode(selectionSet: Operation.Data.self, from: dataEntry, variables: operation.variables)
return GraphQLResult(data: data, errors: errors, source: .server, dependentKeys: nil)
Expand Down
Loading