Skip to content

Commit

Permalink
Merge branch 'master' into pagination-first-0
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
spawnia committed Dec 15, 2023
2 parents 39d8408 + 76018af commit 977ce2f
Show file tree
Hide file tree
Showing 112 changed files with 10,168 additions and 413 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ trim_trailing_whitespace = false
[*.neon]
indent_size = 2

[*.yml]
[{*.yml, *.yaml}]
indent_size = 2

[*.proto]
indent_size = 2
40 changes: 40 additions & 0 deletions .github/workflows/proto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "Build protobuf"
on:
push:
branches:
- '*'
paths:
- '**.proto'
- 'buf.gen.yaml'

jobs:
proto:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- uses: shivammathur/setup-php@v2
with:
coverage: none
extensions: mbstring
php-version: 8.2

- run: composer install --no-interaction --no-progress --no-suggest

- uses: bufbuild/buf-setup-action@v1

- run: |
buf generate
rm -rf src/Tracing/FederatedTracing/Proto
mv proto-tmp/Nuwave/Lighthouse/Tracing/FederatedTracing/Proto src/Tracing/FederatedTracing/Proto
rm -rf proto-tmp
- run: vendor/bin/php-cs-fixer fix src/Tracing/FederatedTracing/Proto

- run: git pull

- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Apply proto changes
28 changes: 28 additions & 0 deletions .github/workflows/update-reports-proto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Update reports.proto"
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 0"

jobs:
proto:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- run: curl -sSfo src/Tracing/FederatedTracing/reports.proto https://usage-reporting.api.apollographql.com/proto/reports.proto

- run: |
sed -i 's/ \[(js_use_toArray) = true]//g' src/Tracing/FederatedTracing/reports.proto
sed -i 's/ \[(js_preEncoded) = true]//g' src/Tracing/FederatedTracing/reports.proto
sed -i '3 i option php_namespace = "Nuwave\\\\Lighthouse\\\\Tracing\\\\FederatedTracing\\\\Proto";' src/Tracing/FederatedTracing/reports.proto
sed -i '4 i option php_metadata_namespace = "Nuwave\\\\Lighthouse\\\\Tracing\\\\FederatedTracing\\\\Proto\\\\Metadata";' src/Tracing/FederatedTracing/reports.proto
- uses: peter-evans/create-pull-request@v5
with:
title: 'Updated `reports.proto`'
commit_message: Updated `reports.proto`
branch: patch/update-reports-proto
delete-branch: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ phpunit.xml
.php-cs-fixer.cache
build
phpstan-tmp-dir
proto-tmp

# composer
composer.phar
Expand Down
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,44 @@ You can find and compare releases at the [GitHub release page](https://github.co

## Unreleased

## v6.29.0

### Fixed

- Return empty results for pagination `first: 0`

## v6.28.0

### Added

- Mark common pagination types as `@shareable` for Apollo Federation v2 https://github.com/nuwave/lighthouse/pull/2485

## v6.27.0

### Added

- Split up `@can` directive into `@canFind`, `@canModel`, `@canQuery`, `@canResolved` and `@canRoot` https://github.com/nuwave/lighthouse/pull/2483
- Added `action` and `returnValue` arguments to `@can*` family of directives https://github.com/nuwave/lighthouse/pull/2483
- Allows using any objects in `@can*` family of directives https://github.com/nuwave/lighthouse/pull/2483

## v6.26.1

### Fixed

- Add `scalar link__Import` and `enum link__Purpose` to `@link` definition https://github.com/nuwave/lighthouse/pull/2484

## v6.26.0

### Added

- Support federated tracing https://github.com/nuwave/lighthouse/pull/2479

## v6.25.0

### Added

- Add `@namespaced` directive for namespacing by separation of concerns https://github.com/nuwave/lighthouse/pull/2469

## v6.24.0

### Added
Expand Down
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ $user = User::create([
]);
```

## Working with proto files

Lighthouse uses [protobuf](https://developers.google.com/protocol-buffers) files for [federated tracing](src/Tracing/FederatedTracing/reports.proto).
When updating the proto files, the PHP classes need to be regenerated.
The generation is done with [buf](https://buf.build/docs/generate/overview).
The `make proto` command generates the new PHP classes and replace the old ones.

## Documentation

### External
Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,19 @@ docs: up ## Render the docs in a development server

docs/node_modules: up docs/package.json docs/yarn.lock ## Install yarn dependencies
${dcnode} yarn

.PHONY: proto/update-reports
proto/update-reports:
${dcphp} curl -sSfo src/Tracing/FederatedTracing/reports.proto https://usage-reporting.api.apollographql.com/proto/reports.proto
${dcphp} sed -i 's/ \[(js_use_toArray) = true]//g' src/Tracing/FederatedTracing/reports.proto
${dcphp} sed -i 's/ \[(js_preEncoded) = true]//g' src/Tracing/FederatedTracing/reports.proto
${dcphp} sed -i '3 i option php_namespace = "Nuwave\\\\Lighthouse\\\\Tracing\\\\FederatedTracing\\\\Proto";' src/Tracing/FederatedTracing/reports.proto
${dcphp} sed -i '4 i option php_metadata_namespace = "Nuwave\\\\Lighthouse\\\\Tracing\\\\FederatedTracing\\\\Proto\\\\Metadata";' src/Tracing/FederatedTracing/reports.proto

.PHONY: proto
proto:
docker run --rm --volume ".:/tmp" --workdir /tmp bufbuild/buf generate
${dcphp} rm -rf src/Tracing/FederatedTracing/Proto
${dcphp} mv proto-tmp/Nuwave/Lighthouse/Tracing/FederatedTracing/Proto src/Tracing/FederatedTracing/Proto
${dcphp} rm -rf proto-tmp
$(MAKE) php-cs-fixer
39 changes: 35 additions & 4 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,36 @@ It will prevent the following type of HTTP requests:
- `GET` requests
- `POST` requests that can be created using HTML forms

### `@can` directive is replaced with `@can*` directives

The `@can` directive was removed in favor of more specialized directives:
- with `find` field set: `@canFind`
- with `query` field set: `@canQuery`
- with `root` field set: `@canRoot`
- with `resolved` field set: `@canResolved`
- if none of the above are set: `@canModel`

```diff
type Mutation {
- createPost(input: PostInput! @spread): Post! @can(ability: "create") @create
+ createPost(input: PostInput! @spread): Post! @canModel(ability: "create") @create
- updatePost(input: PostInput! @spread): Post! @can(find: "input.id", ability: "edit") @update
+ updatePost(input: PostInput! @spread): Post! @canFind(find: "input.id", ability: "edit") @update
- deletePosts(ids: [ID!]! @whereKey): [Post!]! @can(query: true, ability: "delete") @delete
+ deletePosts(ids: [ID!]! @whereKey): [Post!]! @canQuery(ability: "delete") @delete
}

type Query {
- posts: [Post!]! @can(resolved: true, ability: "view") @paginate
+ posts: [Post!]! @canResolved(ability: "view") @paginate
}

type Post {
- sensitiveInformation: String @can(root: true, ability: "admin")
+ sensitiveInformation: String @canRoot(ability: "admin")
}
```

## v5 to v6

### `messages` on `@rules` and `@rulesForArray`
Expand Down Expand Up @@ -388,11 +418,10 @@ class SomeField

### Replace `@middleware` with `@guard` and specialized FieldMiddleware

The `@middleware` directive has been removed, as it violates the boundary between HTTP and GraphQL
request handling.
The `@middleware` directive has been removed, as it violates the boundary between HTTP and GraphQL request handling.
Laravel middleware acts upon the HTTP request as a whole, whereas field middleware must only apply to a part of it.

Authentication is one of most common use cases for `@middleware`. You can now use
the [@guard](docs/master/api-reference/directives.md#guard) directive on selected fields.
If you used `@middleware` for authentication, replace it with [@guard](docs/master/api-reference/directives.md#guard):

```diff
type Query {
Expand All @@ -405,6 +434,8 @@ Note that [@guard](docs/master/api-reference/directives.md#guard) does not log i
To ensure the user is logged in, add the `AttemptAuthenticate` middleware to your `lighthouse.php`
middleware config, see the [default config](src/lighthouse.php) for an example.

If you used `@middleware` for authorization, replace it with [@can](docs/master/api-reference/directives.md#can).

Other functionality can be replaced by a custom [`FieldMiddleware`](docs/master/custom-directives/field-directives.md#fieldmiddleware)
directive. Just like Laravel Middleware, it can wrap around individual field resolvers.

Expand Down
7 changes: 7 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: v1
managed:
enabled: true
plugins:
# For new releases, see https://github.com/protocolbuffers/protobuf/releases and https://buf.build/protocolbuffers/php
- plugin: buf.build/protocolbuffers/php:v25.1
out: proto-tmp
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"dms/phpunit-arraysubset-asserts": "^0.4 || ^0.5",
"ergebnis/composer-normalize": "^2.2.2",
"fakerphp/faker": "^1.21",
"google/protobuf": "^3.21",
"laravel/framework": "^9 || ^10",
"laravel/legacy-factories": "^1.1.1",
"laravel/lumen-framework": "^9 || ^10 || dev-master",
Expand All @@ -72,7 +73,9 @@
"thecodingmachine/phpstan-safe-rule": "^1.2"
},
"suggest": {
"ext-protobuf": "Improve protobuf serialization performance (used for tracing)",
"bensampo/laravel-enum": "Convenient enum definitions that can easily be registered in your Schema",
"google/protobuf": "Required when using the tracing driver federated-tracing",
"laravel/pennant": "Required for the @feature directive",
"laravel/scout": "Required for the @search directive",
"mll-lab/graphql-php-scalars": "Useful scalar types, required for @whereConditions",
Expand Down
Loading

0 comments on commit 977ce2f

Please sign in to comment.