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
29 changes: 24 additions & 5 deletions .claude/commands/review-pr.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,30 @@ When reviewing, check these project-specific rules:

See [CLAUDE.md](../../CLAUDE.md) and [knowledge/internal/](../../knowledge/internal/) for full conventions.

## Reply Format Rules
## Reply Format Rules (CRITICAL)

When replying to PR comments:

- **Commit hash references**: Write commit hashes as plain text, NOT in code blocks
- CORRECT: `Fixed in f3b5fec.`
- WRONG: `Fixed in \`f3b5fec\`.`
- This ensures GitHub auto-links the commit hash to the actual commit
### Commit Hash Formatting

**NEVER wrap commit hashes in backticks or code blocks.** GitHub only auto-links plain text commit hashes.

| Format | Example | Result |
|--------|---------|--------|
| ✅ CORRECT | `Fixed in f3b5fec.` | Clickable link to commit |
| ❌ WRONG | `Fixed in \`f3b5fec\`.` | Plain text, no link |

**Examples of correct replies:**

```text
Fixed in f3b5fec.

**Changes:**
- Updated header to use bun run generate
```

```text
Fixed in abc1234 along with other review items.
```

**Do NOT use backticks around the commit hash** - this breaks GitHub's auto-linking feature.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
8 changes: 5 additions & 3 deletions .claude/commands/sync-godot-iap.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ Synchronize OpenIAP changes to the [godot-iap](https://github.com/hyochan/godot-

## Type Generation Source

**OpenIAP has a built-in GDScript type generator:**
**OpenIAP has a built-in GDScript type generator (IR-based):**

- **Generator:** `/Users/crossplatformkorea/Github/hyodotdev/openiap/packages/gql/scripts/generate-gdscript-types.mjs`
- **Generator:** `/Users/crossplatformkorea/Github/hyodotdev/openiap/packages/gql/codegen/plugins/gdscript.ts`
- **Entry Point:** `/Users/crossplatformkorea/Github/hyodotdev/openiap/packages/gql/codegen/index.ts`
- **Output:** `/Users/crossplatformkorea/Github/hyodotdev/openiap/packages/gql/src/generated/types.gd`

---
Expand Down Expand Up @@ -713,6 +714,7 @@ Now update `docs/docs/` with new API documentation for the new version.

## References

- **OpenIAP GDScript Generator:** `/Users/crossplatformkorea/Github/hyodotdev/openiap/packages/gql/scripts/generate-gdscript-types.mjs`
- **OpenIAP GDScript Generator:** `/Users/crossplatformkorea/Github/hyodotdev/openiap/packages/gql/codegen/plugins/gdscript.ts`
- **OpenIAP Codegen Entry:** `/Users/crossplatformkorea/Github/hyodotdev/openiap/packages/gql/codegen/index.ts`
- **OpenIAP Docs:** https://openiap.dev/docs
- **Godot IAP Docs:** Check README.md
23 changes: 22 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,30 @@ openiap/

- `packages/apple/Sources/Models/Types.swift`
- `packages/google/openiap/src/main/Types.kt`
- `packages/gql/src/generated/*` - All generated type files
- `openiap-versions.json` - Managed by CI/CD workflows only

Regenerate types with: `./scripts/generate-types.sh`
Regenerate types: `cd packages/gql && bun run generate`

### GQL Code Generation System

The type generation uses an **IR-based (Intermediate Representation)** architecture:

```text
GraphQL Schema → Parser → IR → Language Plugins → Generated Code
codegen/core/ codegen/plugins/
├── types.ts ├── swift.ts
├── parser.ts ├── kotlin.ts
└── transformer.ts├── dart.ts
└── gdscript.ts
```

**Language plugins handle:**
- **Swift**: Codable protocol, ErrorCode custom initializer, platform defaults
- **Kotlin**: sealed interface, fromJson/toJson with nullable patterns
- **Dart**: sealed class, factory constructors, extends/implements
- **GDScript**: _init() pattern, Variant type for unions

### Git Commit Format

Expand Down
100 changes: 84 additions & 16 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bun install

### `@hyodotdev/openiap-gql`

GraphQL schema and type generation for all platforms.
GraphQL schema and **IR-based type generation** for all platforms.

```bash
cd packages/gql
Expand All @@ -51,12 +51,20 @@ cd packages/gql
bun run generate

# Generate for specific platform
bun run generate:ts # TypeScript
bun run generate:swift # Swift
bun run generate:kotlin # Kotlin
bun run generate:dart # Dart
bun run generate:ts # TypeScript (graphql-codegen)
bun run generate:swift # Swift (IR-based plugin)
bun run generate:kotlin # Kotlin (IR-based plugin)
bun run generate:dart # Dart (IR-based plugin)
bun run generate:gdscript # GDScript (IR-based plugin)
```

**Architecture:**
```text
GraphQL Schema → Parser → IR (Intermediate Representation) → Language Plugins → Generated Code
```

See [Code Generation Architecture](#code-generation-architecture) for details.

### `@hyodotdev/openiap-docs`

Documentation website at [openiap.dev](https://openiap.dev)
Expand Down Expand Up @@ -275,23 +283,83 @@ Each package has its own scripts. See individual `package.json` files for detail
```text
GraphQL Schema (packages/gql/src/*.graphql)
Type Generation (bun run generate)
[1] Parser (codegen/core/parser.ts)
[2] Transformer → IR (codegen/core/transformer.ts)
[3] Language Plugins (codegen/plugins/*.ts)
├─→ TypeScript (src/generated/types.ts) [graphql-codegen]
├─→ Swift (src/generated/Types.swift) [IR plugin]
├─→ Kotlin (src/generated/Types.kt) [IR plugin]
├─→ Dart (src/generated/types.dart) [IR plugin]
└─→ GDScript (src/generated/types.gd) [IR plugin]
Auto Sync (bun run sync)
├─→ TypeScript (src/generated/types.ts)
├─→ Swift (src/generated/Types.swift) ──┐
├─→ Kotlin (src/generated/Types.kt) ──┐ │
└─→ Dart (src/generated/types.dart) │ │
│ │
Auto Sync ───────────────┘ │
┌───────────────────────────────────────┘
├─→ packages/apple/Sources/Models/Types.swift
└─→ packages/google/.../openiap/Types.kt (+ post-processing)
└─→ packages/google/.../openiap/Types.kt
```

**Key Feature:** One `generate` command updates all platforms automatically!

## 🏗️ Code Generation Architecture

The GQL package uses an **IR-based (Intermediate Representation) code generation system**:

### Directory Structure

```text
packages/gql/codegen/
├── index.ts # Main entry point
├── core/
│ ├── types.ts # IR type definitions (IREnum, IRObject, etc.)
│ ├── parser.ts # GraphQL schema parser
│ ├── transformer.ts # AST → IR transformer
│ └── utils.ts # Case conversion, keyword escaping
└── plugins/
├── base-plugin.ts # Abstract base class
├── swift.ts # Swift: Codable, ErrorCode handling
├── kotlin.ts # Kotlin: sealed interface, fromJson/toJson
├── dart.ts # Dart: sealed class, factory constructors
└── gdscript.ts # GDScript: Godot engine types
```

### IR Types

| IR Type | Description |
|---------|-------------|
| `IREnum` | Enum with values, raw values (kebab-case), legacy aliases |
| `IRInterface` | Protocol/Interface with typed fields |
| `IRObject` | Struct/Class with fields, implements, union membership |
| `IRInput` | Input type with required field tracking |
| `IRUnion` | Union with members, nested union support |
| `IROperation` | Query/Mutation/Subscription definitions |

### Language Plugin Features

| Plugin | Key Features |
|--------|--------------|
| **Swift** | Codable protocol, ErrorCode custom init, platform defaults (ProductIOS) |
| **Kotlin** | sealed interface, fromJson/toJson, nullable patterns, type casting |
| **Dart** | extends/implements, factory constructors, sealed class, @override |
| **GDScript** | _init() pattern, from_json/to_json, Variant for unions |

### Schema Markers

Special comments in GraphQL SDL:

```graphql
# => Union
type RequestPurchaseResult {
purchase: Purchase # Generates union variant
purchases: [Purchase!]
}

# Future
fetchProducts(...): FetchProductsResult # Wraps in Promise/async
```

## 🔄 Common Workflows

### Adding a New Feature
Expand Down
17 changes: 15 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading