-
Notifications
You must be signed in to change notification settings - Fork 749
Remove dependency on apollo CLI for fetching schema #1935
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
Merged
Merged
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 3610cfa
Use URL downloader in CLI downloader
designatednerd 93ec2e1
Update headers to take both key and value
designatednerd d277334
Add Apollo-Use-Only method to create a non-type safe GraphQL request
designatednerd 6a7a606
Add methods for direct download from registry and introspection rathe…
designatednerd 2e546a5
Revert "Add Apollo-Use-Only method to create a non-type safe GraphQL …
designatednerd 8aa6e46
Pull untyped request body creator into codegen lib
designatednerd b314b97
update types on codegen tests
designatednerd 95744c6
Pull out usage of the typescript CLI 🎉
designatednerd b465bbb
Make sure URL request headers are properly set
designatednerd 153a3c2
don't try to import all of apollo 🤦♀️
designatednerd 5bff0ef
Make sure keys are sorted
designatednerd 8439a0a
Make sure folder is created before trying to write to it
designatednerd f791135
Update tests
designatednerd af8a782
Update that we should really only be getting SDL files, not JSON, bec…
designatednerd 812d12a
start adding and testing downloading the schema from the graph registry
designatednerd e8c4faf
Turns out variant is actually required
designatednerd 815a718
fix expected file name
designatednerd 5c7769f
get rid of arguments parameter, update custom debug strings
designatednerd 59dde6b
Turns out you have to _throw_ the error rather than just creating it …
designatednerd 2600a93
Check that downloaded info from introspection query can be loaded int…
designatednerd 9fe96ee
test that downloaded SDL schema from the Registry can be turned into …
designatednerd 83c1e57
Clarify where we're converting from a downloaded Registry file vs a d…
designatednerd 3c5e177
first swipe at adding SDL printing for introspection
designatednerd 3c36ebc
Updated JS bundle
calvincestari 3771b2d
add tslib to the package.json so it gets pulled in if you haven't glo…
designatednerd 2426893
actual, successful swipe at getting introspection JSON converted to SDL.
designatednerd 07f440d
Update integration tests for new schema downloader
calvincestari 8a77f00
Organize code by section
calvincestari 6e9aee8
Fix spelling mistake
calvincestari c11e734
Clean-up CLIDownloader API and tests
calvincestari fd02502
Clean-up URLDownloader and add tests
calvincestari 7c5ae6f
Ignore URLDownloader test output
calvincestari c0338b3
Fix library import for ApolloPerformanceTests
calvincestari d7efb14
Improve test feedback when not setting a request handler
calvincestari a185a04
Remove comment about public use of UntypedGraphQLRequestBodyCreator
calvincestari c185d48
Improve test names and operation
calvincestari ed9bc43
Refactored ApolloSchemaDownloadConfiguration
calvincestari 676882c
Refactor ApolloSchemaDownloader
calvincestari e99e052
Update schema download script for changed API
calvincestari 67dddc0
Remove irrelevant schema download integration test
calvincestari ce93e15
Move linked library from ApolloPerformanceTest target to ApolloTestSu…
calvincestari 436d1eb
Move MockNetworkSession to ApolloCodegenTestSupport target
calvincestari c524531
Add SDL validation to StarWarsApolloSchemaDownloaderTests
calvincestari 062225c
Add registry-based ApolloSchemaDownloader integration test
calvincestari 6e5e1dc
Finish unit tests for ApolloSchemaDownloader
calvincestari 7b0c777
Add Apollo prefix to 'registry' usage in schema downloader
calvincestari 7fffa63
Add documentation to ApolloSchemaDownloadConfiguration
calvincestari 6216e33
Fix ApolloServerIntegrationTests for enum value renaming
calvincestari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
Sources/ApolloCodegenLib/ApolloSchemaDownloadConfiguration.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
calvincestari marked this conversation as resolved.
|
||
|
|
||
| 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, | ||
|
calvincestari marked this conversation as resolved.
|
||
| 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) | ||
| """ | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.