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
This generates a new user with the input type file. A new command was necessary, as the user type has a different resolver to handle password and hash.
12
+
13
+
If important fields with dependent logics are missing, they are added automatically by the generator, such as the fields: **email**, **password**, **role**.
14
+
15
+
# Authorization for types
16
+
Use the new directive @authorize in the type definition to control the authorization settings:
17
+
```javascript
18
+
type User
19
+
@authorize(
20
+
create: ["owner"]
21
+
read: ["world"]
22
+
update: ["owner", "admin"]
23
+
delete: ["owner", "admin"]
24
+
ownerField:"id"
25
+
roleField:"role"
26
+
defaultUserRole:'user',
27
+
firstUserRole:'admin',
28
+
adminUserRole:'admin',
29
+
)
30
+
{
31
+
email:String!
32
+
name:String
33
+
role:String!
34
+
}
35
+
```
36
+
or:
37
+
```javascript
38
+
type Post
39
+
@authorize(
40
+
create: ["owner"]
41
+
read: ["world"]
42
+
update: ["owner", "admin"]
43
+
delete: ["owner", "admin"]
44
+
ownerField:"ownerId"
45
+
roleField:"role"
46
+
)
47
+
{
48
+
post:String!
49
+
comment:String
50
+
owner: User1 @belongsTo
51
+
}
52
+
```
53
+
54
+
Meaning of the directive's arguments:
55
+
* create = Authorization for a create mutation
56
+
* read = Authorization for a read query
57
+
* update = Authorization for a update mutation
58
+
* delete = Authorization for a delete mutation
59
+
*
60
+
Add the authorized users in the array with...
61
+
* "owner" = the user, who created the document
62
+
* "world" = everyone is authorized
63
+
* "admin" = the administrator, of the system
64
+
* role = add any role, in the role field
65
+
66
+
The generator will create a new folder named authorization. In that folder, a new index.js file is copied into, which hosts the authorization logic. This authorization logic exposes only one central function **authorize()**, which will be called for each resolver's data handler. This authorize function should be only used in the resolver. It can send and receive whether an array or a document. It has the following signature:
whereas: 'TypeName' is a string with the current type name of the resolver, the passed TypeName contains the context of the resolver (Model,...), 'mode' contains a string with any of the available modes of the data access: 'create', 'read', 'update', 'delete', to inform the authorization module, what kind of data operation it shall authorize, user is the context object of the authenticated user, and input is the data which should be checked. The authorize function returns checked and authorized data. If for example one document of the data array is not accessible by the authenticated user, then it is filtered out and not included in the returned array/object.
72
+
73
+
Also, for each generated type, it creates an additional file in the authorization folder named by its type.js. In that file, all rules for a successfull authorization check is stored. You can adjust this file directly also afterwards as it keeps only data, with the following rules:
0 commit comments