forked from terhechte/swift-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 website bootstrap, codegen script, homebrew formula bootstrap, git …
…integration What's left is writing some documentation and publishing the 2.0.0 version 🚀
- Loading branch information
Showing
62 changed files
with
18,095 additions
and
6,865 deletions.
There are no files selected for viewing
This file contains 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,19 @@ | ||
name: Test | ||
|
||
on: | ||
push: {} | ||
pull_request: {} | ||
|
||
jobs: | ||
build: | ||
runs-on: macOS-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Resolve | ||
run: swift package resolve | ||
- name: Build | ||
run: swift build | ||
- name: Perform package tests | ||
run: swift test | ||
- name: Integration tests with workflows | ||
run: ./scripts/test.sh |
This file contains 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.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,9 @@ | ||
nodeLinker: node-modules | ||
|
||
plugins: | ||
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs | ||
spec: "@yarnpkg/plugin-workspace-tools" | ||
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs | ||
spec: "@yarnpkg/plugin-typescript" | ||
|
||
yarnPath: .yarn/releases/yarn-berry.cjs |
This file contains 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,40 @@ | ||
class SwiftGraphQL < Formula | ||
desc "GraphQL code generator and client written in Swift" | ||
homepage "https://github.com/maticzav/SwiftGraphQL" | ||
url "https://github.com/maticzav/swift-graphql/archive/2.0.0.tar.gz" | ||
sha256 "0e6adb87619b364ffe92d4e196a5811a0a988b02ba483324d14b5a5a83676ea5" | ||
head "https://github.com/maticzav/swift-graphql.git" | ||
|
||
depends_on :xcode | ||
|
||
def install | ||
|
||
# libxml2 has to be included in ISYSTEM_PATH for building one of | ||
# dependencies. It didn't happen automatically before Xcode 9.3 | ||
# so homebrew patched environment variable to get it work. | ||
# | ||
# That works fine when you have just Xcode installed, but there | ||
# is also CLT. If it is also installed, ISYSTEM_PATH has | ||
# a reference to CLT libxml2 AND a reference to Xcode default | ||
# toolchain libxml2. That causes build failure with "module redeclared" | ||
# error. So if both Xcode and CLT are installed one reference | ||
# has to be removed. | ||
# | ||
# It's a bug of homebrew but before it's fixed, it's easier | ||
# to provide in-place workaround for now. | ||
# Please remove this once homebrew is patched. | ||
|
||
# step 1: capture old value and patch environment | ||
if OS::Mac::Xcode.version >= Version.new("9.3") && !OS::Mac::Xcode.without_clt? then | ||
old_isystem_paths = ENV["HOMEBREW_ISYSTEM_PATHS"] | ||
ENV["HOMEBREW_ISYSTEM_PATHS"] = old_isystem_paths.gsub("/usr/include/libxml2", "") | ||
end | ||
|
||
# step 2: usual build | ||
system "make", "install", "PREFIX=#{prefix}" | ||
|
||
# step 3: restoring environment to pristine state | ||
ENV["HOMEBREW_ISYSTEM_PATHS"] = old_isystem_paths if defined? old_isystem_paths | ||
|
||
end | ||
end |
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,22 +1,96 @@ | ||
import ArgumentParser | ||
import Files | ||
import Foundation | ||
import SwiftGraphQLCodegen | ||
import Yams | ||
|
||
SwiftGraphQLCLI.main() | ||
|
||
// MARK: - CLI | ||
|
||
struct SwiftGraphQLCLI: ParsableCommand { | ||
// MARK: - Parameters | ||
|
||
@Argument(help: "GraphQL server endpoint.") | ||
var endpoint: String | ||
|
||
@Option(help: "Relative path to your YML config file.") | ||
@Option(help: "Relative path from CWD to your YML config file.") | ||
var config: String? | ||
|
||
@Option(name: .shortAndLong, help: "Relative path to the output file.") | ||
@Option(name: .shortAndLong, help: "Relative path from CWD to the output file.") | ||
var output: String? | ||
|
||
// MARK: - Main | ||
|
||
mutating func run() throws {} | ||
func run() throws { | ||
// Make sure we get a valid endpoint to fetch. | ||
guard let url = URL(string: endpoint) else { | ||
SwiftGraphQLCLI.exit(withError: SwiftGraphQLGeneratorError.endpoint) | ||
} | ||
|
||
// Load configuration if config path is present, otherwise use default. | ||
let config: Config | ||
|
||
if let configPath = self.config { | ||
let raw = try Folder.current.file(at: configPath).read() | ||
config = try Config(from: raw) | ||
} else { | ||
config = Config() | ||
} | ||
|
||
// Generate the code. | ||
let generator = GraphQLCodegen(scalars: config.scalars) | ||
let code = try generator.generate(from: url) | ||
|
||
// Write to target file or stdout. | ||
if let outputPath = self.output { | ||
try Folder.current.file(at: outputPath).write(code) | ||
} else { | ||
FileHandle.standardOutput.write(code.data(using: .utf8)!) | ||
} | ||
|
||
// The end | ||
} | ||
} | ||
|
||
SwiftGraphQLCLI.main() | ||
// MARK: - Configuraiton | ||
|
||
/* | ||
swiftgraphql.yml | ||
```yml | ||
scalars: | ||
Date: DateTime | ||
``` | ||
*/ | ||
|
||
struct Config: Codable, Equatable { | ||
/// Key-Value dictionary of scalar mappings. | ||
let scalars: ScalarMap | ||
|
||
// MARK: - Initializers | ||
|
||
/// Creates an empty configuration instance. | ||
init() { | ||
scalars = ScalarMap() | ||
} | ||
|
||
/// Creates a new config instance from given parameters. | ||
init(scalars: ScalarMap) { | ||
self.scalars = scalars | ||
} | ||
|
||
/// Tries to decode the configuration from a string. | ||
init(from data: Data) throws { | ||
let decoder = YAMLDecoder() | ||
self = try decoder.decode(Config.self, from: data) | ||
} | ||
} | ||
|
||
|
||
|
||
// MARK: - Errors | ||
|
||
enum SwiftGraphQLGeneratorError: String, Error { | ||
case endpoint = "Invalid endpoint!" | ||
} |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
examples/StarWars/Codegen/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.