Skip to content

Commit 1ed9d21

Browse files
committed
Update documentation: introduced options type and isRequired
1 parent 86c3d47 commit 1ed9d21

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

docs/todo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
This library is still work in progress, and misses some valuable features:
33

44
- Introduction of `#[Deprecated]` attribute
5-
- Overwrite type via attributes
5+
- ~~Overwrite type via attributes~~
66
- Allow simple lists (array type)
77
- Connection, edge, nodes (see https://relay.dev/graphql/connections.htm)
88
- Make AST serializable (cacheable)

docs/usage.md

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Usage
22

33
The following attributes can be used:
4+
45
- `#[Mutation]`
56
- `#[Query]`
67
- `#[InputType]`
@@ -34,6 +35,7 @@ final readonly YourQuery
3435
```
3536

3637
### Automatic schema creation
38+
3739
*GraphQL Attribute Schema* will read the available public method's signature: input arguments and output type. These
3840
will be automatically configured in the schema (this can be overwritten by using `#[Arg]`, see [Arg](#arg) section).
3941

@@ -45,6 +47,7 @@ Also, the name of the mutation or query will be automatically read from the clas
4547
options).
4648

4749
### Requirements
50+
4851
Mutations and queries:
4952

5053
- must be in the namespace as defined at `Parser` creation (
@@ -57,13 +60,16 @@ Mutations and queries:
5760

5861
Both `#[Mutation]` and `#[Query]` attribute can be configured:
5962

60-
| Option | Description |
61-
|-------------|--------------------------------------------------------------------------|
62-
| name | Set custom name of mutation or query (instead of based on class) |
63-
| description | Set description of the mutation or query, readable in the GraphQL schema |
63+
| Option | Description |
64+
|-------------|-------------------------------------------------------------------------------|
65+
| name | Set custom name of mutation or query (instead of based on class) |
66+
| description | Set description of the mutation or query, readable in the GraphQL schema |
67+
| type | Set custom return type (can be either a `#[Type]` FQCN or `ScalarType` (enum) |
68+
| isRequired | When a custom type is set, isRequired should be set as well |
6469

6570
## InputType
66-
Input types can be defined with `#[InputType]`.
71+
72+
Input types can be defined with `#[InputType]`.
6773
In order to configure your class as input type, just add this attribute on class level:
6874

6975
```php
@@ -87,8 +93,10 @@ final readonly class YourInputType
8793
```
8894

8995
### Automatic schema creation
90-
*GraphQL Attribute Schema* will read the `__construct` signature: input arguments.
91-
Any input argument with a defined `#[Field]` will be automatically configured in the schema (this can be overwritten, see [Field](#field) section).
96+
97+
*GraphQL Attribute Schema* will read the `__construct` signature: input arguments.
98+
Any input argument with a defined `#[Field]` will be automatically configured in the schema (this can be overwritten,
99+
see [Field](#field) section).
92100

93101
Input can be both scalars or objects.
94102
When using objects, make sure these are defined as well with `#[InputType]` or `#[Enum]`.
@@ -106,6 +114,7 @@ options).
106114
| description | Set description of the input type, readable in the GraphQL schema |
107115

108116
## Type
117+
109118
Types can be defined with `#[Type]`.
110119
In order to configure your class as type, just add this attribute on class level:
111120

@@ -136,12 +145,16 @@ final readonly class YourType
136145
```
137146

138147
### Automatic schema creation
148+
139149
*GraphQL Attribute Schema* will both read the `__construct` signature: input arguments, as well as read all methods.
140150

141-
Any input argument with a defined `#[Field]` will be automatically configured in the schema (this can be overwritten, see [Field](#field) section).
151+
Any input argument with a defined `#[Field]` will be automatically configured in the schema (this can be overwritten,
152+
see [Field](#field) section).
142153

143-
Any method with a defined `#[Field]` will be automatically configured in the schema (this can be overwritten, see [Field](#field) section).
144-
The return type is seen as field type, any method input arguments are seen as filter arguments (this can be overwritten by using `#[Arg]`, see [Arg](#arg) section)..
154+
Any method with a defined `#[Field]` will be automatically configured in the schema (this can be overwritten,
155+
see [Field](#field) section).
156+
The return type is seen as field type, any method input arguments are seen as filter arguments (this can be overwritten
157+
by using `#[Arg]`, see [Arg](#arg) section)..
145158

146159
Input can be both scalars or objects.
147160
When using objects, make sure these are defined as well with `#[InputType]` or `#[Enum]`.
@@ -159,6 +172,7 @@ options).
159172
| description | Set description of the type, readable in the GraphQL schema |
160173

161174
## Enum
175+
162176
Enums can be defined with `#[Enum]`.
163177
In order to configure your enum class as enum, just add this attribute on class level:
164178

@@ -173,14 +187,17 @@ enum YourEnumType: string
173187
case Baz = 'BAZ';
174188
}
175189
```
190+
176191
### Automatic schema creation
192+
177193
*GraphQL Attribute Schema* will read the enum signature.
178194

179195
The values for the enum will be automatically read from the PHP `enum`; it uses the string version.
180196

181197
The name of the enum will be automatically read from the class name (this can be overwritten, see options).
182198

183199
### Requirements
200+
184201
Enums:
185202

186203
- must be of the PHP native `enum` type (no classes with public constants)
@@ -196,6 +213,7 @@ Enums:
196213
| description | Set description of the enum, readable in the GraphQL schema |
197214

198215
## Field
216+
199217
In `#[Type]` and `#[InputType]`, to define fields, the `#[Field]` attribute can be used.
200218
In order to configure any fields this can be set on constructor property (for `#[InputType]` or `#[Type]`) or
201219
on method (for `#[Type]` only).
@@ -243,14 +261,17 @@ final readonly class YourInputType
243261

244262
`#[Field]` attribute can be configured:
245263

246-
| Option | Description |
247-
|-------------|--------------------------------------------------------------|
248-
| name | Set custom name of field (instead of based on class) |
249-
| description | Set description of the field, readable in the GraphQL schema |
264+
| Option | Description |
265+
|-------------|----------------------------------------------------------------------------------------|
266+
| name | Set custom name of field (instead of based on class) |
267+
| description | Set description of the field, readable in the GraphQL schema |
268+
| type | Set custom type (can be either a `#[Type]`, `#[InputType]` FQCN or `ScalarType` (enum) |
269+
| isRequired | When a custom type is set, isRequired should be set as well |
250270

251271
## Arg
272+
252273
For `#[Mutation]`, `#[Query]` and `#[Type]` methods defined with `#[Field]`, input arguments are read
253-
automatically from the signature.
274+
automatically from the signature.
254275

255276
However, to overwrite e.g. name, `#[Arg]` can be used.
256277

@@ -299,7 +320,9 @@ final readonly class YourType
299320

300321
`#[Arg]` attribute can be configured:
301322

302-
| Option | Description |
303-
|-------------|-----------------------------------------------------------------|
304-
| name | Set custom name of argument (instead of based on class) |
305-
| description | Set description of the argument, readable in the GraphQL schema |
323+
| Option | Description |
324+
|-------------|------------------------------------------------------------------------|
325+
| name | Set custom name of argument (instead of based on class) |
326+
| description | Set description of the argument, readable in the GraphQL schema |
327+
| type | Set custom type (can be either a `#[Type]` FQCN or `ScalarType` (enum) |
328+
| isRequired | When a custom type is set, isRequired should be set as well |

0 commit comments

Comments
 (0)