Skip to content
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: 0 additions & 2 deletions Apollo.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ Pod::Spec.new do |s|
s.subspec 'Core' do |ss|
ss.source_files = 'Sources/Apollo/*.swift'
ss.preserve_paths = [
'scripts/check-and-run-apollo-cli.sh',
'scripts/check-and-run-apollo-codegen.sh',
'scripts/run-bundled-codegen.sh',
'scripts/apollo.tar.gz',
]
Expand Down
10 changes: 1 addition & 9 deletions Apollo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
9F27D4641D40379500715680 /* JSONStandardTypeConversions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F27D4631D40379500715680 /* JSONStandardTypeConversions.swift */; };
9F295E311E27534800A24949 /* NormalizeQueryResults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F295E301E27534800A24949 /* NormalizeQueryResults.swift */; };
9F295E381E277B2A00A24949 /* GraphQLResultNormalizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F295E371E277B2A00A24949 /* GraphQLResultNormalizer.swift */; };
9F2A74DB2137C21500E63C85 /* check-and-run-apollo-codegen.sh in Resources */ = {isa = PBXBuildFile; fileRef = 9F2A74DA2137C21500E63C85 /* check-and-run-apollo-codegen.sh */; };
9F438D071E6C2FD9007BDC1A /* Apollo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FC750441D2A532C00458D91 /* Apollo.framework */; };
9F438D081E6C30B1007BDC1A /* StarWarsAPI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FCE2CFA1E6C213D00E34457 /* StarWarsAPI.framework */; };
9F533AB31E6C4A4200CBE097 /* BatchedLoadTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F438D0B1E6C494C007BDC1A /* BatchedLoadTests.swift */; };
Expand Down Expand Up @@ -97,7 +96,6 @@
9FD637F51E6AD43F001EDBC8 /* Apollo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FC750441D2A532C00458D91 /* Apollo.framework */; };
9FD637F61E6AD43F001EDBC8 /* Apollo.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9FC750441D2A532C00458D91 /* Apollo.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
9FE1C6E71E634C8D00C02284 /* PromiseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FE1C6E61E634C8D00C02284 /* PromiseTests.swift */; };
9FE3F3981DADBD870072078F /* check-and-run-apollo-cli.sh in Resources */ = {isa = PBXBuildFile; fileRef = 9FE3F3971DADBD870072078F /* check-and-run-apollo-cli.sh */; };
9FE941D01E62C771007CDD89 /* Promise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FE941CF1E62C771007CDD89 /* Promise.swift */; };
9FEB050D1DB5732300DA3B44 /* JSONSerializationFormat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FEB050C1DB5732300DA3B44 /* JSONSerializationFormat.swift */; };
9FEC15B41E681DAD00D461B4 /* Collections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FEC15B31E681DAD00D461B4 /* Collections.swift */; };
Expand Down Expand Up @@ -286,7 +284,6 @@
9F27D4631D40379500715680 /* JSONStandardTypeConversions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONStandardTypeConversions.swift; sourceTree = "<group>"; };
9F295E301E27534800A24949 /* NormalizeQueryResults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NormalizeQueryResults.swift; sourceTree = "<group>"; };
9F295E371E277B2A00A24949 /* GraphQLResultNormalizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphQLResultNormalizer.swift; sourceTree = "<group>"; };
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; };
9F3750501ECEFD2300C68F5E /* CharacterAndSubTypesFragments.graphql */ = {isa = PBXFileReference; lastKnownFileType = text; path = CharacterAndSubTypesFragments.graphql; sourceTree = "<group>"; };
9F438D0B1E6C494C007BDC1A /* BatchedLoadTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BatchedLoadTests.swift; sourceTree = "<group>"; };
9F4DAF2D1E48B84B00EBFF0B /* HTTPNetworkTransport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPNetworkTransport.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -372,7 +369,6 @@
9FD637ED1E6ACF88001EDBC8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
9FD637EF1E6ACF88001EDBC8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9FE1C6E61E634C8D00C02284 /* PromiseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PromiseTests.swift; sourceTree = "<group>"; };
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; };
9FE941CF1E62C771007CDD89 /* Promise.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Promise.swift; sourceTree = "<group>"; };
9FEB050C1DB5732300DA3B44 /* JSONSerializationFormat.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONSerializationFormat.swift; sourceTree = "<group>"; };
9FEC15B31E681DAD00D461B4 /* Collections.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Collections.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -785,8 +781,6 @@
9FC750471D2A532C00458D91 /* Apollo.h */,
9FC750491D2A532C00458D91 /* Info.plist */,
9B74BCBE2333F4ED00508F84 /* run-bundled-codegen.sh */,
9FE3F3971DADBD870072078F /* check-and-run-apollo-cli.sh */,
9F2A74DA2137C21500E63C85 /* check-and-run-apollo-codegen.sh */,
);
name = "Supporting Files";
sourceTree = "<group>";
Expand Down Expand Up @@ -1064,8 +1058,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9F2A74DB2137C21500E63C85 /* check-and-run-apollo-codegen.sh in Resources */,
9FE3F3981DADBD870072078F /* check-and-run-apollo-cli.sh in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1132,7 +1124,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
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";
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";
};
9FCE2D061E6C251100E34457 /* Generate Apollo Client API */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
40 changes: 18 additions & 22 deletions Apollo.xcodeproj/xcshareddata/xcschemes/Apollo.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,25 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "NO"
codeCoverageEnabled = "YES"
onlyGenerateCoverageForSpecifiedTargets = "YES"
shouldUseLaunchSchemeArgsEnv = "NO">
onlyGenerateCoverageForSpecifiedTargets = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9FC750431D2A532C00458D91"
BuildableName = "Apollo.framework"
BlueprintName = "Apollo"
ReferencedContainer = "container:Apollo.xcodeproj">
</BuildableReference>
</MacroExpansion>
<EnvironmentVariables>
<EnvironmentVariable
key = "APOLLO_TEST_CACHE_PROVIDER"
value = "ApolloTestSupport.InMemoryTestCacheProvider"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<CodeCoverageTargets>
<BuildableReference
BuildableIdentifier = "primary"
Expand Down Expand Up @@ -60,24 +76,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9FC750431D2A532C00458D91"
BuildableName = "Apollo.framework"
BlueprintName = "Apollo"
ReferencedContainer = "container:Apollo.xcodeproj">
</BuildableReference>
</MacroExpansion>
<EnvironmentVariables>
<EnvironmentVariable
key = "APOLLO_TEST_CACHE_PROVIDER"
value = "ApolloTestSupport.InMemoryTestCacheProvider"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -98,8 +96,6 @@
ReferencedContainer = "container:Apollo.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
11 changes: 10 additions & 1 deletion Sources/Apollo/JSONSerialziation+Sorting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ extension JSONSerialization {
// presently support, but we should use it where we can in
// order to get stable JSON representations, especially if being
// used in queries.
if #available(iOS 11, macOS 13, watchOS 4, tvOS 11, *) {
if #available(iOS 11, macOS 10.13, watchOS 4, tvOS 11, *) {
return try self.data(withJSONObject: object, options: [.sortedKeys])
} else {
return try self.data(withJSONObject: object)
}
}

/// Wrapper function so we don't have to scatter `if #available` all over the codebase to see if data can be sorted.
static func dataCanBeSorted() -> Bool {
if #available(iOS 11, macOS 10.13, watchOS 4, tvOS 11, *) {
return true
} else {
return false
}
}
}
8 changes: 4 additions & 4 deletions Tests/ApolloTests/GETTransformerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GETTransformerTests: XCTestCase {

let url = transformer.createGetURL()

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")
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")
}

func testEncodingQueryWithMoreThanOneParameterIncludingNonHashableValue() {
Expand All @@ -33,10 +33,10 @@ class GETTransformerTests: XCTestCase {

let url = transformer.createGetURL()

if #available(iOS 11, macOS 13, tvOS 11, watchOS 4, *) {
if JSONSerialization.dataCanBeSorted() {
// Here, we know that everything should be encoded in a stable order,
// and we can check the encoded URL string directly.
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")
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")
} else {
// We can't guarantee order of encoding, so we need to pull the JSON back
// out and check that it has the correct and correctly typed properties.
Expand Down Expand Up @@ -96,6 +96,6 @@ class GETTransformerTests: XCTestCase {

let url = transformer.createGetURL()

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")
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")
}
}
15 changes: 10 additions & 5 deletions Tests/ApolloTests/RequestCreatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ Charlie file content.

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

if #available(iOS 11, macOS 13, tvOS 11, watchOS 4, *) {
if JSONSerialization.dataCanBeSorted() {
let expectedString = """
--TEST.BOUNDARY
Content-Disposition: form-data; name="operations"

{"operationName":"HeroName","query":"query HeroName($episode: Episode) { hero(episode: $episode) { __typename name } }","variables":{"episode":null,\"upload\":null}}
{"operationName":"HeroName","query":"query HeroName($episode: Episode) {\\n hero(episode: $episode) {\\n __typename\\n name\\n }\\n}","variables":{"episode":null,"upload":null}}
--TEST.BOUNDARY
Content-Disposition: form-data; name="map"

Expand Down Expand Up @@ -239,12 +239,12 @@ Alpha file content.

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

if #available(iOS 11, macOS 13, tvOS 11, watchOS 4, *) {
if JSONSerialization.dataCanBeSorted() {
let expectedString = """
--TEST.BOUNDARY
Content-Disposition: form-data; name="operations"

{"operationName":"HeroName","query":"query HeroName($episode: Episode) { hero(episode: $episode) { __typename name } }","variables":{"episode":null,\"uploads\":null}}
{"operationName":"HeroName","query":"query HeroName($episode: Episode) {\\n hero(episode: $episode) {\\n __typename\\n name\\n }\\n}","variables":{"episode":null,\"uploads\":null}}
--TEST.BOUNDARY
Content-Disposition: form-data; name="map"

Expand Down Expand Up @@ -327,7 +327,12 @@ Alpha file content.
--TEST.BOUNDARY
Content-Disposition: form-data; name="test_query"

query HeroName($episode: Episode) { hero(episode: $episode) { __typename name } }
query HeroName($episode: Episode) {
hero(episode: $episode) {
__typename
name
}
}
"""
self.checkString(stringToCompare, includes: expectedEndString)
self.checkString(stringToCompare, includes: expectedQueryString)
Expand Down
36 changes: 3 additions & 33 deletions Tests/GitHubAPI/API.swift
Original file line number Diff line number Diff line change
@@ -1,35 +1,10 @@
// This file was automatically generated and should not be edited.

import Apollo
import Foundation

public final class RepositoryQuery: GraphQLQuery {
/// 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
/// }
/// }
/// }
/// }
/// }
/// }
/// The raw GraphQL definition of this operation.
public let operationDefinition =
"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 } } } } } }"

Expand Down Expand Up @@ -351,12 +326,7 @@ public final class RepositoryQuery: GraphQLQuery {
}

public final class RepoUrlQuery: GraphQLQuery {
/// query RepoURL {
/// repository(owner: "apollographql", name: "apollo-ios") {
/// __typename
/// url
/// }
/// }
/// The raw GraphQL definition of this operation.
public let operationDefinition =
"query RepoURL { repository(owner: \"apollographql\", name: \"apollo-ios\") { __typename url } }"

Expand Down
Loading