You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# doctrine-graphql-helper
2
2
3
-
Easily create a GraphQL schema from Doctrine entities.
3
+
Generate a PSR-7 GraphQL API server from an instance of the Doctrine ORM in just a few lines of PHP, with permissions and custom mutation resolvers available out-of-the-box.
This package is a helper package for [`graphql-php`](https://github.com/webonyx/graphql-php) and [`graphql-doctrine`](https://github.com/ecodev/graphql-doctrine), which install automatically with it. Entities used with this package must be graphql-doctrine-compatible. Refer to these packages’ documentation for more details.
12
+
This package is a helper package for [`graphql-php`](https://github.com/webonyx/graphql-php) and [`graphql-doctrine`](https://github.com/ecodev/graphql-doctrine), which install automatically with it. Entities used with this package must be `graphql-doctrine`-compatible. Refer to these packages’ documentation for more details.
13
13
14
14
### `GraphQLEntity`
15
15
Any entities which you wish to use in your API must extend `GraphQLEntity` and implement the required methods.
@@ -46,6 +46,8 @@ If you wish to use permissions, you may also provide the EntitySchemaBuilder con
46
46
### Running queries
47
47
You may use your built schema in a GraphQL server of your choice, or use the helper’s integration with `graphql-php` to retrieve a server object already set up with your schema and any permissions settings you have defined by calling `getServer()`.
48
48
49
+
The server object returned accepts a request object in its `executeRequest()` method. In some cases you may wish to run a JSON payload through the server - to do this you can parse the JSON to a format which the server will accept as a parameter to `executeRequest()` by calling `EntitySchemaBuilder::jsonToOperation($json)`.
50
+
49
51
### Using permissions
50
52
If you have set the schema builder’s permissions during instantiation, provide the permitted scopes (as an array) and the user’s identifier to the `getServer()` method to execute the query with permissions enabled.
51
53
The schema generator generates four queries for each provided entity, which have parallels to the HTTP request methods used in REST: a simple `GET` query, and `POST` (create), `UPDATE` and `DELETE` mutators. You may define the permissions at method-level granularity using the scopes array, provided to the builder’s constructor.
@@ -85,7 +87,7 @@ An asterisk (\*) is a wildcard, indicating full permissions are given for this s
85
87
***All:** Accessible to all users with this scope
86
88
***None:** Not accessible to users with this scope
87
89
***Permissive:** Users permissions with this scope are resolved in the entity’s `hasPermission()` method. If you don’t wish to use permissive, but are running the server with permissions enabled, simply implement the method with a return true.
88
-
The `hasPermission()`static is called for all methods that are defined as permissive, and you are passed an instance of the Doctrine entity manager, an instance of your API user class as `ApiUserInterface`, and the ID of the entity that is being queried by the user. You are not given an instantiated version of the entity class being called: if you wish, you must retrieve this from the entity manager manually using the provided entity ID.
90
+
The `hasPermission()`method is called for all methods that are defined as permissive, and you are passed an instance of the Doctrine entity manager and an instance of your API user class as `ApiUserInterface`.
89
91
90
92
## Using custom mutators
91
93
The schema generator exposes a simple API for adding your own mutators, and a class (`Mutation`). This wraps some advanced functionality of graphql-doctrine, and so reference to that package’s documentation may or will be required using this feature.
@@ -108,7 +110,7 @@ There are two methods of hydrating the new `Mutation` returned by the factory: u
108
110
## Methods exposed by the builder
109
111
The schema builder exposes a variety of methods which may be of use when writing resolver functions. You may wish to consult the documentation of `graphql-php` and `graphql-doctrine` for more information on the values that some of these methods return.
110
112
111
-
**`immutableListOf()`:** When given an entity’s class name, returns a GraphQL return type of a list of the entity.
113
+
**`listOfType()`:** When given an entity’s class name, returns a GraphQL return type of a list of the entity.
112
114
113
115
**`resolveQuery()`:** Resolves a query using the entity manager. Requires the args array given with the query, and the class name of the root entity being queried. You may also pass in an instance of the entity as the third parameter to fully resolve and then return this entity.
0 commit comments