Commit c69e6cca authored by David Négrier's avatar David Négrier

Improving article

parent 4966ab39
Pipeline #104770 passed with stages
in 6 minutes and 40 seconds
......@@ -286,6 +286,8 @@ modules to help you get started quickly. So far, we have a [Symfony bundle](http
We plan on working on [container-interop/service-provider compatibility](https://github.com/container-interop/service-provider/) and a Laravel module too.
<div class="alert alert-info"><strong>Update: </strong> since the writing of this article, the <a href="https://graphqlite.thecodingmachine.io/docs/laravel-package">Laravel</a> and the <a href="https://graphqlite.thecodingmachine.io/docs/universal_service_providers">service-provider</a> packages have been released.</div>
Webonyx has already bindings with PSR-15 middlewares so it is relatively easy to setup a working environment with
[Zend Expressive](https://docs.zendframework.com/zend-expressive/) or any PSR-15 enabled framework.
......
......@@ -40,8 +40,9 @@ public function product(string $id): Product
This simple code will expose a GraphQL schema with a `product` query that accepts an `$id` argument and returns a
`Product` output type.
You can read more about the GraphQLite philosophy in our [initial blog post announcement](/graphqlite-graphql-in-php-easy).
Also, do not hesitate to [jump directly in the documentation](https://graphqlite.thecodingmachine.io/).
This article really focuses on the improvements since GraphQLite 3. If you have not played with GraphQLite yet,
you should maybe start by reading more about the GraphQLite philosophy in our [initial blog post announcement](/graphqlite-graphql-in-php-easy).
Also, do not hesitate to [jump directly to the documentation](https://graphqlite.thecodingmachine.io/).
## So, what's new?
......@@ -55,44 +56,19 @@ GraphQLite 3 already offered these features:
With GraphQLite 4, we focused a lot on:
- improving developer experience
- the few missing GraphQL features remaining
- adding hook points to make GraphQLite extensible
So let's dive into the main new features:
## Mapping GraphQL interfaces
You can now map a PHP interface to a GraphQL interface, using the same `@Type` annotation you are already used to.
```php
/**
* @Type
*/
interface UserInterface
{
/**
* @Field
*/
public function getUserName(): string;
}
```
This will automatically create a GraphQL interface whose description is:
```graphql
interface UserInterface {
userName: String!
}
```
Of course, a PHP class implementing this PHP interface will translate into a GraphQL output type implementing the
GraphQL interface automatically!
## Autowiring services in resolvers
Maybe my favorite feature of this new release, because it simplifies a lot the way you organize your code.
Some frameworks (Symfony in particular) can inject services directly in controller actions.
The interest is somewhat limited since it is pretty easy to inject the services in the controller's container.
The interest is somewhat limited since it is pretty easy to inject the services in the controller's constructor.
But in the context of GraphQLite, it starts to make a lot of sense, because resolvers are scattered
all over your code (and particularly in your models). And injecting a service in a model is not something
......@@ -162,6 +138,34 @@ In GraphQLite 3, to do the same thing, you would have had to create an "external
fields declared in 2 classes. Same result in the end, your `Product` class is stripped from
possessing a name. Autowiring allows you to keep all your fields in the same class. Use it!
## Mapping GraphQL interfaces
You can now map a PHP interface to a GraphQL interface, using the same `@Type` annotation you are already using on classes.
```php
/**
* @Type
*/
interface UserInterface
{
/**
* @Field
*/
public function getUserName(): string;
}
```
This will automatically create a GraphQL interface whose description is:
```graphql
interface UserInterface {
userName: String!
}
```
Of course, a PHP class implementing this PHP interface will translate into a GraphQL output type implementing the
GraphQL interface automatically!
## Validating user input
GraphQL input types can now be [validated using simple to use annotations](https://graphqlite.thecodingmachine.io/docs/next/validation).
......@@ -205,12 +209,12 @@ public function findByMail(string $email): User
## Improved security handling
GraphQLite 4 comes with fine-grained security.
A much requested feature: GraphQLite 4 comes with fine-grained security.
Until v4, you could deny access to users based on user rights. With v4, you can grant or deny access based on the context.
For instance, imagine you are developing a blog platform. When writing a new article, a user can access his blog post,
but noone else should be allowed to. You can express this in GraphQLite using the new `@Security` annotation.
but no-one else should be allowed to. You can express this in GraphQLite using the new `@Security` annotation.
```php
/**
......@@ -228,7 +232,7 @@ class Post {
public function canAccess(Post $post, User $user): bool
{
// Some custom logic here
// Some custom logic here to know if $user can access $post
}
}
```
......@@ -262,7 +266,7 @@ class Post {
{
// This method will receive the $prefetchedUsers as first argument.
// This is the return value of the "prefetchUsers" method below.
// Using this prefetched list, it should be easy to map it//
// Using this pre-fetched list, it should be easy to map it
// to the post
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment