-
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.
Merge pull request #1 - codegen rewrite, DuetGraphQL module, etc.
- Loading branch information
Showing
19 changed files
with
605 additions
and
409 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,28 @@ | ||
name: basic-ci | ||
|
||
on: push | ||
|
||
jobs: | ||
linux: | ||
runs-on: ubuntu-latest | ||
container: swift:5.5-focal | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Build | ||
run: swift build | ||
- name: Run tests | ||
run: SWIFT_DETERMINISTIC_HASHING=1 swift test | ||
|
||
macos: | ||
runs-on: macos-12 | ||
steps: | ||
- uses: maxim-lobanov/setup-xcode@v1 | ||
with: | ||
xcode-version: '13.2.1' | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Build | ||
run: swift build | ||
- name: Run tests | ||
run: SWIFT_DETERMINISTIC_HASHING=1 swift test |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,15 @@ let package = Package( | |
.library(name: "Duet", targets: ["Duet"]), | ||
.library(name: "DuetSQL", targets: ["DuetSQL"]), | ||
.library(name: "DuetMock", targets: ["DuetMock"]), | ||
.library(name: "DuetGraphQL", targets: ["DuetGraphQL"]), | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/jaredh159/x-kit.git", from: "1.0.2"), | ||
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.16.0"), | ||
.package(url: "https://github.com/pointfreeco/swift-tagged", from: "0.6.0"), | ||
.package(url: "https://github.com/wickwirew/Runtime.git", from: "2.2.4"), | ||
.package("jaredh159/[email protected]"), | ||
.package("vapor/[email protected]"), | ||
.package("pointfreeco/[email protected]"), | ||
.package("wickwirew/[email protected]"), | ||
.package("vapor/[email protected]"), | ||
.package("alexsteinerde/[email protected]", "GraphQLKit"), | ||
], | ||
targets: [ | ||
.target( | ||
|
@@ -35,8 +38,27 @@ let package = Package( | |
.product(name: "Tagged", package: "swift-tagged"), | ||
] | ||
), | ||
.target( | ||
name: "DuetGraphQL", | ||
dependencies: [ | ||
.product(name: "Vapor", package: "vapor"), | ||
"DuetSQL", | ||
"GraphQLKit", | ||
] | ||
), | ||
.target(name: "DuetMock", dependencies: ["Duet"]), | ||
.testTarget(name: "DuetSQLTests", dependencies: ["DuetSQL"]), | ||
.testTarget(name: "DuetTests", dependencies: ["Duet"]), | ||
] | ||
) | ||
|
||
extension PackageDescription.Package.Dependency { | ||
static func package(_ commitish: String, _ name: String? = nil) -> Package.Dependency { | ||
let parts = commitish.split(separator: "@") | ||
return .package( | ||
name: name, | ||
url: "https://github.com/\(parts[0]).git", | ||
from: .init(stringLiteral: "\(parts[1])") | ||
) | ||
} | ||
} |
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,56 @@ | ||
import DuetSQL | ||
import Graphiti | ||
import Vapor | ||
|
||
public enum Schema<Resolver> { | ||
public typealias ModelType<Model: DuetSQL.Model> = Type<Resolver, Request, Model> | ||
public typealias AppField<FieldType, Args: Decodable> = Field<Resolver, Request, FieldType, Args> | ||
public typealias AppType<Value: Encodable> = Type<Resolver, Request, Value> | ||
public typealias AppInput<InputObjectType: Decodable> = Input<Resolver, Request, InputObjectType> | ||
|
||
public static var IdentifiedEntityType: AppType<IdentifiedEntity> { | ||
Type(IdentifiedEntity.self) { | ||
Field("id", at: \.id.lowercased) | ||
} | ||
} | ||
} | ||
|
||
public struct InputArgs<Input: Codable>: Codable { | ||
public let input: Input | ||
|
||
public init(input: Input) { | ||
self.input = input | ||
} | ||
} | ||
|
||
public struct IdentifyEntityArgs: Codable { | ||
public let id: UUID | ||
|
||
public init(id: UUID) { | ||
self.id = id | ||
} | ||
} | ||
|
||
public struct GenericResponse: Codable { | ||
public let success: Bool | ||
|
||
public init(success: Bool) { | ||
self.success = success | ||
} | ||
} | ||
|
||
public struct DeletedEntityResult: Codable { | ||
public let deletedId: UUID | ||
|
||
public init(deletedId: UUID) { | ||
self.deletedId = deletedId | ||
} | ||
} | ||
|
||
public struct IdentifiedEntity: Codable { | ||
public let id: UUID | ||
|
||
public init(id: UUID) { | ||
self.id = id | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,43 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import { generateModelConformances } from './lib/models/model-conformances'; | ||
import { duetSqlModelConformance } from './lib/models/sql-conformance'; | ||
import { generateModelMocks } from './lib/models/model-mocks'; | ||
import { generateModelGraphQLTypes } from './lib/models/graphql'; | ||
import { scriptData } from './lib/script-helpers'; | ||
|
||
const { models, appRoot, types } = scriptData(); | ||
const { models, appRoot, types, config } = scriptData(); | ||
|
||
let duetConformancesCode = /* swift */ `// auto-generated, do not edit | ||
import Duet | ||
import Tagged | ||
`; | ||
|
||
let sqlConformancesCode = /* swift */ `// auto-generated, do not edit | ||
import DuetSQL | ||
`; | ||
|
||
let graphqlDir = config.graphqlConformancesDir; | ||
|
||
for (const model of models) { | ||
const [conformancePath, conformanceCode] = generateModelConformances(model, types); | ||
fs.writeFileSync(`${appRoot}/${conformancePath}`, conformanceCode); | ||
duetConformancesCode += `${model.duetIdentifiableConformance}\n${model.codingKeysExtension}\n`; | ||
sqlConformancesCode += `\n${duetSqlModelConformance(model, types)}\n`; | ||
|
||
// @TODO model mocks | ||
const [mocksPath, mocksCode] = generateModelMocks(model, types); | ||
const testDir = path.dirname(`${appRoot}/${mocksPath}`); | ||
if (!fs.existsSync(testDir)) { | ||
fs.mkdirSync(testDir); | ||
} | ||
fs.writeFileSync(`${appRoot}/${mocksPath}`, mocksCode); | ||
|
||
const [graphqlPath, graphqlCode] = generateModelGraphQLTypes(model, types); | ||
fs.writeFileSync(`${appRoot}/${graphqlPath}`, graphqlCode); | ||
if (graphqlDir) { | ||
const graphqlCode = generateModelGraphQLTypes(model, types); | ||
fs.writeFileSync(`${graphqlDir}/${model.name}+GraphQL.swift`, graphqlCode); | ||
} | ||
} | ||
|
||
fs.writeFileSync(config.duetConformancesLocation, duetConformancesCode); | ||
|
||
if (config.duetSqlConformancesLocation) { | ||
fs.writeFileSync(config.duetSqlConformancesLocation, sqlConformancesCode); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { describe, it, expect } from '@jest/globals'; | ||
import stripIndent from 'strip-indent'; | ||
import Model from '../Model'; | ||
|
||
describe(`Model`, () => { | ||
it(`generates correct Duet.IdentifiableConformance`, () => { | ||
const expected = stripIndent(/* swift */ ` | ||
extension Thing: Duet.Identifiable { | ||
public typealias Id = Tagged<Thing, UUID> | ||
} | ||
`); | ||
|
||
expect(Model.mock().duetIdentifiableConformance).toBe(expected); | ||
}); | ||
|
||
it(`generates correct CodingKeys`, () => { | ||
const expected = stripIndent(/* swift */ ` | ||
public extension Thing { | ||
enum CodingKeys: String, CodingKey, CaseIterable { | ||
case id | ||
case foo | ||
} | ||
} | ||
`); | ||
|
||
const model = Model.mock(); | ||
model.props = [ | ||
{ name: `id`, type: `Id` }, | ||
{ name: `foo`, type: `String` }, | ||
]; | ||
expect(model.codingKeysExtension).toBe(expected.trim()); | ||
}); | ||
|
||
it(`tableName (w/ migration number)`, () => { | ||
const model = Model.mock(); | ||
model.migrationNumber = 1; | ||
expect(model.tableName).toBe(`M1.tableName`); | ||
}); | ||
|
||
it(`tableName (NO migration number)`, () => { | ||
expect(Model.mock().tableName).toBe(`"things"`); | ||
}); | ||
}); |
Oops, something went wrong.