Skip to content

Commit bf0a97c

Browse files
authored
Merge pull request rebing#428 from mfn/mfn-upgrade-guide
[DOCS] Add upgrade guide from v1 to v2
2 parents 3ca74e0 + ec42966 commit bf0a97c

File tree

3 files changed

+59
-34
lines changed

3 files changed

+59
-34
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ CHANGELOG
3535
- Test suite has been refactored and now features Database (SQLite) tests too
3636

3737
### Changed
38-
- Follow Laravel convention and use plural for namspaces (e.g. new queries are place in `App\GraphQL\Queries`, not `App\GraphQL\Query` anymore); make commands have been adjusted
38+
- Follow Laravel convention and use plural for namspaces (e.g. new queries are placed in `App\GraphQL\Queries`, not `App\GraphQL\Query` anymore); make commands have been adjusted
3939
- Made the following classes _abstract_: `Support\Field`, `Support\InterfaceType`, `Support\Mutation`, `Support\Query`, `Support\Type`, `Support\UnionType` [\#357](https://github.com/rebing/graphql-laravel/pull/357)
4040
- Updated GraphiQL to 0.13.0 [\#335](https://github.com/rebing/graphql-laravel/pull/335)
4141
- If you're using CSP, be sure to allow `cdn.jsdelivr.net` and `cdnjs.cloudflare.com`
@@ -44,7 +44,7 @@ CHANGELOG
4444

4545
### Fixed
4646
- The Paginator correctly inherits the types model so it can be used with `SelectFields` and still generates correct SQL queries [\#415](https://github.com/rebing/graphql-laravel/pull/415)
47-
- Arguments are now validation before they're passed to `authorize()` [\#413](https://github.com/rebing/graphql-laravel/pull/413)
47+
- Arguments are now validated before they're passed to `authorize()` [\#413](https://github.com/rebing/graphql-laravel/pull/413)
4848
- File uploads now correctly work with batched requests [\#397](https://github.com/rebing/graphql-laravel/pull/397)
4949
- Path multi-level support for Schemas works again [\#358](https://github.com/rebing/graphql-laravel/pull/358)
5050
- SelectFields correctly passes field arguments to the custom query [\#327](https://github.com/rebing/graphql-laravel/pull/327)

Readme.md

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ It offers following features and improvements over the original package by
2424
and thus dealing with n+1 problems
2525
* Pagination support
2626
* Server-side support for [query batching](https://blog.apollographql.com/batching-client-graphql-queries-a685f5bcd41b)
27+
* Support for file uploads
2728

2829
## Installation
2930

@@ -120,6 +121,7 @@ To work this around:
120121
- [JSON Columns](#json-columns)
121122
- [Field deprecation](#field-deprecation)
122123
- [Default Field Resolver](#default-field-resolver)
124+
- [Upgrading from v1 to v2](#upgrading-from-v1-to-v2)
123125
- [Migrating from Folklore](#migrating-from-folklore)
124126
- [Performance considerations](#performance-considerations)
125127

@@ -521,7 +523,13 @@ public function validationErrorMessages(array $args = []): array
521523

522524
This library provides a middleware compliant with the spec at https://github.com/jaydenseric/graphql-multipart-request-spec .
523525

524-
You have to add the `\Rebing\GraphQL\Support\UploadType` first to your `config/graphql` schema types definition.
526+
You have to add the `\Rebing\GraphQL\Support\UploadType` first to your `config/graphql` schema types definition:
527+
528+
```php
529+
'types' => [
530+
\Rebing\GraphQL\Support\UploadType::class,
531+
],
532+
```
525533

526534
It is relevant that you send the request as `multipart/form-data`:
527535

@@ -1505,6 +1513,52 @@ The parameters received are your regular "resolve" function signature.
15051513

15061514
## Guides
15071515

1516+
### Upgrading from v1 to v2
1517+
1518+
Although version 2 builds on the same code base and does not radically change how the library itself works, many things were improved, sometimes leading to incompatible changes.
1519+
1520+
- Step 0: make a backup!
1521+
- Re-publish the configuration file to learn about all the new settings
1522+
- The order and arguments/types for resolvers has changed:
1523+
- before: `resolve($root, $array, SelectFields $selectFields, ResolveInfo $info)`
1524+
- after: `resolve($root, $array, $context, ResolveInfo $info, Closure $getSelectFields)`
1525+
- If you now want to use SelectFields, you've to first request it: `$selectFields = $getSelectFields();`. The primary reason for this is performance. SelectFields is an optional feature but consumes resources to traverse the GraphQL request AST and introspect all the types for their configuration to apply its magic. In the past it was always constructed and thus consumed resources, even when not requested. This has been changed to an explicit form.
1526+
- Many method signature declarations changed to improve type safety, which have to be adapted:
1527+
- The signature of the method fields changed:
1528+
- from `public function fields()`
1529+
- to `public function fields(): array`
1530+
- The signature of the method toType changed:
1531+
- from `public function toType()`
1532+
- to `public function toType(): \GraphQL\Type\Definition\Type`
1533+
- The signature of the method getFields changed:
1534+
- from `public function getFields()`
1535+
- to `public function getFields(): array`
1536+
- The signature of the method interfaces changed:
1537+
- from `public function interfaces()`
1538+
- to `public function interfaces(): array`
1539+
- The signature of the method types changed:
1540+
- from `public function types()`
1541+
- to `public function types(): array`
1542+
- The signature of the method type changed:
1543+
- from `public function type()`
1544+
- to `public function type(): \GraphQL\Type\Definition\Type`
1545+
- The signature of the method args changed:
1546+
- from `public function args()`
1547+
- to `public function args(): array`
1548+
- The signature of the method queryContext changed:
1549+
- from `protected function queryContext($query, $variables, $schema)`
1550+
- to `protected function queryContext()`
1551+
- The signature of the controller method query changed:
1552+
- from `function query($query, $variables = [], $opts = [])`
1553+
- to `function query(string $query, ?array $variables = [], array $opts = []): array`
1554+
- If you're using custom Scalar types:
1555+
- the signature of the method parseLiteral changed (due to upgrade of the webonxy library):
1556+
- from `public function parseLiteral($ast)`
1557+
- to `public function parseLiteral($valueNode, ?array $variables = null)`
1558+
- The `UploadType` now has to be added manually to the `types` in your schema if you want to use it. The `::getInstance()` method is gone, you simple reference it like any other type via `GraphQL::type('Upload')`.
1559+
- Follow Laravel convention and use plural for namspaces (e.g. new queries are placed in `App\GraphQL\Queries`, not `App\GraphQL\Query` anymore); the respective `make` commands have been adjusted. This will not break any existing code, but code generates will use the new schema.
1560+
- Be sure to read the [Changelog](CHANGELOG.md) for more details
1561+
15081562
### Migrating from Folklore
15091563
https://github.com/folkloreinc/laravel-graphql, formerly also known as https://github.com/Folkloreatelier/laravel-graphql
15101564

@@ -1528,39 +1582,9 @@ The following is not a bullet-proof list but should serve as a guide. It's not a
15281582
- Change namespace references:
15291583
- from `Folklore\`
15301584
- to `Rebing\`
1531-
- The signature of the method fields changed:
1532-
- from `public function fields()`
1533-
- to `public function fields(): array`
1534-
- The signature of the method toType changed:
1535-
- from `public function toType()`
1536-
- to `public function toType(): \GraphQL\Type\Definition\Type`
1537-
- The signature of the method getFields changed:
1538-
- from `public function getFields()`
1539-
- to `public function getFields(): array`
1540-
- The signature of the method interfaces changed:
1541-
- from `public function interfaces()`
1542-
- to `public function interfaces(): array`
1543-
- The signature of the method types changed:
1544-
- from `public function types()`
1545-
- to `public function types(): array`
1546-
- The signature of the method type changed:
1547-
- from `public function type()`
1548-
- to `public function type(): \GraphQL\Type\Definition\Type`
1549-
- The signature of the method args changed:
1550-
- from `public function args()`
1551-
- to `public function args(): array`
1552-
- The signature of the method queryContext changed:
1553-
- from `protected function queryContext($query, $variables, $schema)`
1554-
- to `protected function queryContext()`
1555-
- The signature of the controller method query changed:
1556-
- from `function query($query, $variables = [], $opts = [])`
1557-
- to `function query(string $query, ?array $variables = [], array $opts = []): array`
1585+
- See [Upgrade guide from v1 to v2 for all the function signature changes](#upgrading-from-v1-to-v2)
15581586
- The trait `ShouldValidate` does not exist anymore; the provided features are baked into `Field`
15591587
- The first argument to the resolve method for queries/mutations is now `null` (previously its default was an empty array)
1560-
- If you're using custom Scalar types:
1561-
- the signature of the method parseLiteral changed (due to upgrade of the webonxy library):
1562-
- from `public function parseLiteral($ast)`
1563-
- to `public function parseLiteral($valueNode, ?array $variables = null)`
15641588

15651589
## Performance considerations
15661590

config/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
'types' => [
124124
// 'example' => ExampleType::class,
125125
// 'relation_example' => ExampleRelationType::class,
126+
// \Rebing\GraphQL\Support\UploadType::class,
126127
],
127128

128129
// The types will be loaded on demand. Default is to load all types on each request

0 commit comments

Comments
 (0)