Skip to content

Commit

Permalink
update lighthouse example with latest schema changes
Browse files Browse the repository at this point in the history
See apollographql#166 for details.

Resolves apollographql#190
  • Loading branch information
dariuszkuc committed Feb 10, 2023
1 parent f3de5db commit c31fcf7
Show file tree
Hide file tree
Showing 20 changed files with 1,379 additions and 5,737 deletions.
3 changes: 3 additions & 0 deletions implementations/lighthouse/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/vendor

# override defaults
!app
2 changes: 1 addition & 1 deletion implementations/lighthouse/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.0-cli
FROM php:8.2-cli

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

Expand Down
21 changes: 21 additions & 0 deletions implementations/lighthouse/app/Models/CaseStudy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
* Primary key
* @property string $caseNumber
*
* Attributes
* @property string|null $description
*/
class CaseStudy extends Model
{
public $timestamps = false;

public $incrementing = false;

protected $primaryKey = 'caseNumber';
}
34 changes: 34 additions & 0 deletions implementations/lighthouse/app/Models/DeprecatedProduct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
* Primary key
* @property string $sku
* @property string $package
*
* Attributes
* @property string|null $reason
*
* Foreign keys
* @property string|null $createdByUserEmail
*
* Relations
* @property-read User|null $createdBy
*/
class DeprecatedProduct extends Model
{
public $timestamps = false;

public $incrementing = false;

protected $primaryKey = ['sku', 'package'];

public function createdBy(): BelongsTo
{
return $this->belongsTo(User::class, 'createdByUserEmail');
}
}
10 changes: 10 additions & 0 deletions implementations/lighthouse/app/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
* Primary key
Expand All @@ -14,6 +15,8 @@
* @property string|null $package
* @property string|null $variation
* @property array{size: string|null, weight: float|null}|null $dimensions
* @property string|null $notes
* @property array{array{study:array{caseNumber: string, description: string|null}, outcome: string|null}} $research
*
* Foreign keys
* @property string|null $createdByUserEmail
Expand All @@ -27,6 +30,8 @@ class Product extends Model

public $incrementing = false;

protected $primaryKey = 'id';

protected $casts = [
'dimensions' => 'array',
];
Expand All @@ -45,4 +50,9 @@ public function createdBy(): BelongsTo
{
return $this->belongsTo(User::class, 'createdByUserEmail');
}

public function research(): HasMany
{
return $this->hasMany(ProductResearch::class);
}
}
33 changes: 33 additions & 0 deletions implementations/lighthouse/app/Models/ProductResearch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
* Primary key
* @property string $studyCaseNumber
*
* Attributes
* @property string|null $outcome
*
* Foreign keys
* @property string|null $studyCaseNumber
*
* Relations
* @property-read CaseStudy $study
*/
class ProductResearch extends Model
{
public $timestamps = false;

public $incrementing = false;

protected $primaryKey = 'studyCaseNumber';

public function study(): BelongsTo
{
return $this->belongsTo(CaseStudy::class, 'studyCaseNumber');
}
}
10 changes: 10 additions & 0 deletions implementations/lighthouse/app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
* @property string $email
*
* Attributes
* @property string|null $name
* @property int|null $totalProductsCreated
* @property int $yearsOfEmployment
* @property int|null $averageProductsCreatedPerYear
*/
class User extends Authenticatable
{
Expand All @@ -18,4 +21,11 @@ class User extends Authenticatable
public $incrementing = false;

protected $primaryKey = 'email';

public function averageProductsCreatedPerYear() {
if ($this->totalProductsCreated !== null && $this->yearsOfEmployment !== null) {
return round($this->totalProductsCreated / $this->yearsOfEmployment);
}
return null;
}
}
3 changes: 3 additions & 0 deletions implementations/lighthouse/artisan
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env php
<?php

// turn off deprecation notices
error_reporting(E_ALL ^ E_DEPRECATED);

define('LARAVEL_START', microtime(true));

/*
Expand Down
4 changes: 2 additions & 2 deletions implementations/lighthouse/composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"require": {
"php": "^8",
"laravel/framework": "^8",
"laravel/framework": "^9",
"nuwave/lighthouse": "^5"
},
"autoload": {
Expand All @@ -16,4 +16,4 @@
"@php artisan package:discover --ansi"
]
}
}
}
Loading

0 comments on commit c31fcf7

Please sign in to comment.