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

Remove dependency on apollo CLI for fetching schema #1935

Merged
merged 49 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
1de9881
Pull downloader into its own file
designatednerd May 25, 2021
3610cfa
Use URL downloader in CLI downloader
designatednerd May 27, 2021
93ec2e1
Update headers to take both key and value
designatednerd May 27, 2021
d277334
Add Apollo-Use-Only method to create a non-type safe GraphQL request
designatednerd May 27, 2021
6a7a606
Add methods for direct download from registry and introspection rathe…
designatednerd May 27, 2021
2e546a5
Revert "Add Apollo-Use-Only method to create a non-type safe GraphQL …
designatednerd May 28, 2021
8aa6e46
Pull untyped request body creator into codegen lib
designatednerd May 28, 2021
b314b97
update types on codegen tests
designatednerd May 28, 2021
95744c6
Pull out usage of the typescript CLI 🎉
designatednerd Jun 4, 2021
b465bbb
Make sure URL request headers are properly set
designatednerd Jun 4, 2021
153a3c2
don't try to import all of apollo 🤦‍♀️
designatednerd Jun 4, 2021
5bff0ef
Make sure keys are sorted
designatednerd Jun 4, 2021
8439a0a
Make sure folder is created before trying to write to it
designatednerd Jun 4, 2021
f791135
Update tests
designatednerd Jun 4, 2021
af8a782
Update that we should really only be getting SDL files, not JSON, bec…
designatednerd Jun 4, 2021
812d12a
start adding and testing downloading the schema from the graph registry
designatednerd Jun 4, 2021
e8c4faf
Turns out variant is actually required
designatednerd Jun 4, 2021
815a718
fix expected file name
designatednerd Jun 8, 2021
5c7769f
get rid of arguments parameter, update custom debug strings
designatednerd Jun 30, 2021
59dde6b
Turns out you have to _throw_ the error rather than just creating it …
designatednerd Jun 30, 2021
2600a93
Check that downloaded info from introspection query can be loaded int…
designatednerd Jun 30, 2021
9fe96ee
test that downloaded SDL schema from the Registry can be turned into …
designatednerd Jul 1, 2021
83c1e57
Clarify where we're converting from a downloaded Registry file vs a d…
designatednerd Jul 8, 2021
3c5e177
first swipe at adding SDL printing for introspection
designatednerd Jul 8, 2021
3c36ebc
Updated JS bundle
calvincestari Jul 8, 2021
3771b2d
add tslib to the package.json so it gets pulled in if you haven't glo…
designatednerd Jul 8, 2021
2426893
actual, successful swipe at getting introspection JSON converted to SDL.
designatednerd Jul 8, 2021
07f440d
Update integration tests for new schema downloader
calvincestari Sep 1, 2021
8a77f00
Organize code by section
calvincestari Sep 3, 2021
6e9aee8
Fix spelling mistake
calvincestari Sep 3, 2021
c11e734
Clean-up CLIDownloader API and tests
calvincestari Sep 8, 2021
fd02502
Clean-up URLDownloader and add tests
calvincestari Sep 10, 2021
7c5ae6f
Ignore URLDownloader test output
calvincestari Sep 11, 2021
c0338b3
Fix library import for ApolloPerformanceTests
calvincestari Sep 11, 2021
d7efb14
Improve test feedback when not setting a request handler
calvincestari Sep 11, 2021
a185a04
Remove comment about public use of UntypedGraphQLRequestBodyCreator
calvincestari Sep 13, 2021
c185d48
Improve test names and operation
calvincestari Sep 13, 2021
ed9bc43
Refactored ApolloSchemaDownloadConfiguration
calvincestari Sep 13, 2021
676882c
Refactor ApolloSchemaDownloader
calvincestari Sep 13, 2021
e99e052
Update schema download script for changed API
calvincestari Sep 13, 2021
67dddc0
Remove irrelevant schema download integration test
calvincestari Sep 13, 2021
ce93e15
Move linked library from ApolloPerformanceTest target to ApolloTestSu…
calvincestari Sep 14, 2021
436d1eb
Move MockNetworkSession to ApolloCodegenTestSupport target
calvincestari Sep 14, 2021
c524531
Add SDL validation to StarWarsApolloSchemaDownloaderTests
calvincestari Sep 14, 2021
062225c
Add registry-based ApolloSchemaDownloader integration test
calvincestari Sep 14, 2021
6e5e1dc
Finish unit tests for ApolloSchemaDownloader
calvincestari Sep 15, 2021
7b0c777
Add Apollo prefix to 'registry' usage in schema downloader
calvincestari Sep 15, 2021
7fffa63
Add documentation to ApolloSchemaDownloadConfiguration
calvincestari Sep 15, 2021
6216e33
Fix ApolloServerIntegrationTests for enum value renaming
calvincestari Sep 15, 2021
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ scripts/apollo.tar.gz
SwiftScripts/ApolloCLI
Tests/ApolloCodegenTests/scripts
Tests/ApolloCodegenTests/scripts directory
Tests/ApolloCodegenTests/Schema
Tests/ApolloCodegenTests/Output
SwiftScripts/.build-**

# Local Netlify folder
.netlify
.netlify
40 changes: 36 additions & 4 deletions Apollo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Sources/ApolloCodegenLib/ApolloCLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public struct ApolloCLI {
let lock = try waitForCLIFolderLock(cliFolderURL: cliFolderURL, timeout: timeout)
defer { lock.unlock() }

try CLIDownloader.downloadIfNeeded(cliFolderURL: cliFolderURL, timeout: timeout)
try CLIDownloader.downloadIfNeeded(to: cliFolderURL, timeout: timeout)

if !(try CLIExtractor.validateSHASUMOfDownloadedFile(in: cliFolderURL)) {
CodegenLogger.log("Downloaded zip file has incorrect SHASUM, forcing redownload")
try CLIDownloader.forceRedownload(cliFolderURL: cliFolderURL, timeout: timeout)
try CLIDownloader.forceRedownload(to: cliFolderURL, timeout: timeout)
}

let binaryFolderURL = try CLIExtractor.extractCLIIfNeeded(from: cliFolderURL)
Expand Down
97 changes: 97 additions & 0 deletions Sources/ApolloCodegenLib/ApolloSchemaDownloadConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import Foundation

/// A configuration object that defines behavior for schema download.
public struct ApolloSchemaDownloadConfiguration {

/// How to attempt to download your schema
public enum DownloadMethod: Equatable {

/// The Apollo Schema Registry, which serves as a central hub for managing your data graph.
case apolloRegistry(_ settings: ApolloRegistrySettings)
/// GraphQL Introspection connecting to the specified URL.
case introspection(endpointURL: URL)

public struct ApolloRegistrySettings: Equatable {
/// The API key to use when retrieving your schema from the Apollo Registry.
public let apiKey: String
/// The identifier of the graph to fetch. Can be found in Apollo Studio.
public let graphID: String
/// The variant of the graph in the registry.
public let variant: String?

/// Designated initializer
///
/// - Parameters:
/// - apiKey: The API key to use when retrieving your schema.
/// - graphID: The identifier of the graph to fetch. Can be found in Apollo Studio.
/// - variant: The variant of the graph to fetch. Defaults to "current", which will return whatever is set to the current variant.
public init(apiKey: String,
graphID: String,
variant: String = "current") {
self.apiKey = apiKey
self.graphID = graphID
self.variant = variant
}
}

public static func == (lhs: DownloadMethod, rhs: DownloadMethod) -> Bool {
switch (lhs, rhs) {
case (.introspection(let lhsURL), introspection(let rhsURL)):
return lhsURL == rhsURL
case (.apolloRegistry(let lhsSettings), .apolloRegistry(let rhsSettings)):
return lhsSettings == rhsSettings
default:
return false
}
}

}

public struct HTTPHeader: Equatable, CustomDebugStringConvertible {
let key: String
let value: String

public var debugDescription: String {
"\(key): \(value)"
}
}

/// How to download your schema. Supports the Apollo Registry and GraphQL Introspection methods.
let downloadMethod: DownloadMethod
/// The maximum time to wait before indicating that the download timed out, in seconds. Defaults to 30 seconds.
let downloadTimeout: Double
/// Any additional headers to include when retrieving your schema. Defaults to nil.
let headers: [HTTPHeader]
/// The URL of the folder in which the downloaded schema should be written.
let outputURL: URL

/// Designated Initializer
///
/// - Parameters:
/// - downloadMethod: How to download your schema.
/// - downloadTimeout: The maximum time to wait before indicating that the download timed out, in seconds. Defaults to 30 seconds.
/// - headers: [optional] Any additional headers to include when retrieving your schema. Defaults to nil
/// - outputFolderURL: The URL of the folder in which the downloaded schema should be written
/// - schemaFilename: The name, without an extension, for your schema file. Defaults to `"schema"
public init(using downloadMethod: DownloadMethod,
timeout downloadTimeout: Double = 30.0,
headers: [HTTPHeader] = [],
outputFolderURL: URL,
schemaFilename: String = "schema") {
self.downloadMethod = downloadMethod
self.downloadTimeout = downloadTimeout
self.headers = headers
self.outputURL = outputFolderURL.appendingPathComponent("\(schemaFilename).graphqls")
}
}

extension ApolloSchemaDownloadConfiguration: CustomDebugStringConvertible {
public var debugDescription: String {
return """
downloadMethod: \(self.downloadMethod)
downloadTimeout: \(self.downloadTimeout)
headers: \(self.headers)
outputURL: \(self.outputURL)
"""
}
}
Loading