Repository navigation
Expand file tree
/
Copy pathlaragraph.php
More file actions
530 lines (499 loc) · 19.6 KB
/
Copy pathlaragraph.php
File metadata and controls
530 lines (499 loc) · 19.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
<?php
declare(strict_types=1);
use App\Enums\PostStatus;
use App\Enums\UserRole;
use App\GraphQL\Admin\AdminStatsType;
use App\GraphQL\Admin\StatsQuery;
use App\GraphQL\Validation\MaxRootFieldsRule;
use Ayimdomnic\Laragraph\Laragraph;
use Ayimdomnic\Laragraph\Relay\NodeQuery;
use Ayimdomnic\Laragraph\Scalars\DateTimeType;
use Ayimdomnic\Laragraph\Scalars\JsonType;
use Ayimdomnic\Laragraph\Scalars\UploadType;
return [
/*
|--------------------------------------------------------------------------
| Default Schema
|--------------------------------------------------------------------------
|
| The default schema name to use when no schema is specified. This should
| match a key in the 'schemas' array below.
|
*/
'default_schema' => 'default',
/*
|--------------------------------------------------------------------------
| Authentication / Authorization
|--------------------------------------------------------------------------
|
| default_guard — The Laravel guard used when a field does not explicitly
| specify one. Set to null to use Laravel's own default guard.
|
| Examples:
| 'default_guard' => 'sanctum',
| 'default_guard' => 'api',
|
*/
'auth' => [
// The example authenticates API clients with JWTs on the "api" guard.
'default_guard' => 'api',
],
/*
|--------------------------------------------------------------------------
| Auto-Discovery
|--------------------------------------------------------------------------
|
| When set, Laragraph scans these directories and auto-registers all
| classes that extend the corresponding base class — no manual config
| entries required. Explicit 'schemas' entries always take precedence
| over discovered ones.
|
| Set a key to '' to disable discovery for that category.
|
*/
'discover' => [
'types' => 'app/GraphQL/Types',
'queries' => 'app/GraphQL/Queries',
'mutations' => 'app/GraphQL/Mutations',
'subscriptions' => 'app/GraphQL/Subscriptions',
],
/*
|--------------------------------------------------------------------------
| Route Configuration
|--------------------------------------------------------------------------
|
| Configure the HTTP route used to serve GraphQL requests.
|
*/
'route' => [
'prefix' => 'graphql',
'middleware' => [],
'methods' => ['GET', 'POST'],
],
/*
|--------------------------------------------------------------------------
| Schemas
|--------------------------------------------------------------------------
|
| Each schema has its own set of queries, mutations, subscriptions, and
| middleware. You may define multiple schemas (e.g. 'default', 'admin').
|
| Example:
| 'query' => [
| 'users' => \App\GraphQL\Queries\UsersQuery::class,
| 'user' => \App\GraphQL\Queries\UserQuery::class,
| ],
| 'mutation' => [
| 'createUser' => \App\GraphQL\Mutations\CreateUserMutation::class,
| 'deleteUser' => \App\GraphQL\Mutations\DeleteUserMutation::class,
| ],
| 'subscription' => [
| 'userCreated' => \App\GraphQL\Subscriptions\UserCreatedSubscription::class,
| ],
|
*/
'schemas' => [
// POST/GET /graphql — everything in app/GraphQL/{Queries,Mutations,Subscriptions}
// is discovered automatically, so nothing needs listing here.
'default' => [
// node(id: ID!): Node — Relay re-fetching, see docs/06-pagination.md.
'query' => ['node' => NodeQuery::class],
'mutation' => [],
'subscription' => [],
],
// POST /graphql/admin — a second schema with its own route middleware:
// only authenticated admins reach it. Its extra type is registered here,
// so it never appears in the public schema.
'admin' => [
'query' => [
'stats' => StatsQuery::class,
],
'types' => [
'AdminStats' => AdminStatsType::class,
],
'middleware' => ['auth:api', 'can:access-admin-api'],
'method' => ['POST'],
],
],
/*
|--------------------------------------------------------------------------
| Types
|--------------------------------------------------------------------------
|
| Register GraphQL types that should be available across all schemas.
| The key is the type name used to reference it in other types; the value
| is the FQCN of your type class.
|
| Example:
| 'User' => \App\GraphQL\Types\UserType::class,
| 'Post' => \App\GraphQL\Types\PostType::class,
|
*/
'types' => [
// Built-in scalars
'DateTime' => DateTimeType::class,
'JSON' => JsonType::class,
'Upload' => UploadType::class,
// Native PHP enums become GraphQL enums — no wrapper class needed.
'UserRole' => UserRole::class,
'PostStatus' => PostStatus::class,
// Object, input, interface and union types in app/GraphQL/Types are discovered.
],
/*
|--------------------------------------------------------------------------
| Error Formatter
|--------------------------------------------------------------------------
|
| Called for each error in the response. You may override this to add
| custom extensions or transform error messages.
|
*/
'error_formatter' => [Laragraph::class, 'formatError'],
/*
|--------------------------------------------------------------------------
| Errors Handler
|--------------------------------------------------------------------------
|
| Called once with the full array of errors and the error formatter. You
| may use this to log, filter, or transform the errors array.
|
*/
'errors_handler' => [Laragraph::class, 'handleErrors'],
/*
|--------------------------------------------------------------------------
| Error Localization
|--------------------------------------------------------------------------
|
| Negotiated from the Accept-Language header, restricted to English and
| French — try `curl -H "Accept-Language: fr" ...` against the login
| mutation with bad credentials to see the translated error.
|
*/
'errors' => [
'negotiate_locale' => true,
'supported_locales' => ['en', 'fr'],
'locale_resolver' => null,
],
/*
|--------------------------------------------------------------------------
| Security
|--------------------------------------------------------------------------
|
| Limits that protect the API from overly expensive or abusive queries.
| Set a limit to null to disable it.
|
| query_max_depth — deepest allowed selection nesting. The standard
| introspection query (GraphiQL, codegen) needs 11.
| query_max_complexity — total field cost (see Field::complexity()).
| max_aliases — aliases per document; blocks alias flooding.
| disable_introspection — null (default) disables introspection whenever
| app.debug is off, i.e. in production. Set true or
| false to force it either way.
|
*/
'security' => [
'query_max_complexity' => 500,
'query_max_depth' => 15,
'disable_introspection' => null,
'max_aliases' => 30,
],
/*
|--------------------------------------------------------------------------
| Custom Validation Rules
|--------------------------------------------------------------------------
|
| Register additional GraphQL document-validation rules that are applied
| to every execution. Each entry must be a FQCN of a class that extends
| GraphQL\Validator\Rules\ValidationRule (resolved via the container).
|
| Rules can also be registered at runtime via:
| Laragraph::addValidationRule(new MyRule());
|
| Example:
| 'rules' => [
| \App\GraphQL\Validation\NoDirectMutationsRule::class,
| ],
|
*/
'validation' => [
'rules' => [
MaxRootFieldsRule::class,
],
],
/*
|
| Default items per page for paginated queries.
|
*/
'pagination' => [
'per_page' => 15,
// Largest page a client may request via first/last/per_page (null: no cap).
'max_per_page' => 100,
],
/*
|--------------------------------------------------------------------------
| Response Cache
|--------------------------------------------------------------------------
|
| When enabled, Laragraph caches serialised GraphQL query responses using
| your Laravel cache store. Mutations and subscriptions are never cached.
|
| store — any Laravel cache driver (redis, file, array, memcached …)
| ttl — time-to-live in seconds
|
| scope — 'user' (default) partitions entries per authenticated user (on
| laragraph.auth.default_guard), with guests sharing one partition, so a
| user's data is never served to someone else. Use 'global' only when
| every caller receives identical responses.
|
| Cache is keyed by schema + scope + query string + variables + operation
| name, so different variable combinations produce separate entries.
|
| To invalidate from code:
| \Ayimdomnic\Laragraph\Performance\ResponseCache::flush() // everything
| \Ayimdomnic\Laragraph\Performance\ResponseCache::forget($key) // one entry
|
*/
'cache' => [
'response' => [
'enabled' => env('LARAGRAPH_RESPONSE_CACHE', true),
'store' => 'default',
'ttl' => 60,
'scope' => 'user',
],
],
/*
|--------------------------------------------------------------------------
| Persisted Queries
|--------------------------------------------------------------------------
|
| Persisted queries let clients send a short query ID instead of the full
| query text, reducing bandwidth and optionally restricting execution to
| pre-approved operations only.
|
| enabled — Set to true to activate the persisted-query lookup in the
| request pipeline. When false (default) the feature is completely
| transparent — no overhead is added.
|
| store — Which store implementation to use:
| 'cache' — queries stored in the Laravel cache (supports APQ-style
| runtime registration); recommended for production
| 'array' — static in-memory map read from 'map' below; no persistence
|
| ttl — Lifetime in seconds for cache-backed entries (null = forever).
|
| map — Static ID → query-string pairs used by the 'array' store.
| 'map' => [
| 'GetAllUsers' => '{ users { id name } }',
| ],
|
| apq — Automatic Persisted Queries: when a client sends the full query
| together with its sha256Hash, the query is stored so later requests
| can send the hash alone. Mismatched hashes are rejected.
|
| only — Trusted-documents mode: execute query text only if it is already
| in the store under its SHA-256 hash; everything else is rejected with
| PERSISTED_QUERY_REQUIRED. Pair it with the 'array' store (or a cache
| store you pre-populate at deploy time) to lock the API down to the
| operations your own clients ship.
|
| Clients may send the ID via:
| { "queryId": "<id>", "variables": {} }
| Or the Apollo APQ format:
| { "extensions": { "persistedQuery": { "sha256Hash": "<hash>", "version": 1 } } }
|
*/
'persisted_queries' => [
'enabled' => true,
'store' => 'cache',
'ttl' => 3600,
'map' => [],
'apq' => true,
'only' => false,
],
/*
|--------------------------------------------------------------------------
| Response Extensions
|--------------------------------------------------------------------------
|
| Built-in extensions append metadata to the top-level `extensions` key of
| every GraphQL response. User-defined extensions can be registered at any
| time via ExtensionRegistry::add().
|
| request_id — Adds `extensions.requestId.id`. The value is taken from
| the incoming X-Request-ID header or auto-generated as UUID.
|
| query_timing — Adds `extensions.timing.execution_ms`; wall-clock time of
| Laragraph::execute() in milliseconds.
|
| query_complexity — Adds `extensions.queryComplexity.{cost,maxCost}`, so
| clients can see how close a query came to
| security.query_max_complexity. `cost` is null when the
| query failed before the cost walk ran.
|
*/
'extensions' => [
'request_id' => true,
'query_timing' => true,
'query_complexity' => true,
],
/*
|--------------------------------------------------------------------------
| Field Middleware
|--------------------------------------------------------------------------
|
| Global middleware applied around every field resolver, in declared order.
| Each entry may be a FQCN string (resolved via the container) or an
| instance. Classes must implement FieldMiddlewareInterface.
|
| Middleware runs after auth and validation, immediately before the
| field's resolve() method is called. Per-field middleware declared in
| Field::middleware() runs after global middleware.
|
| Example:
| 'middleware' => [
| \Ayimdomnic\Laragraph\Middleware\LoggingMiddleware::class,
| ],
|
*/
'middleware' => [],
/*
|--------------------------------------------------------------------------
| Logging
|--------------------------------------------------------------------------
|
| Settings used by the built-in LoggingMiddleware.
|
| channel — Laravel log channel name; null (default) uses the application's
| default log channel.
|
*/
'logging' => [
'channel' => null,
],
/*
|--------------------------------------------------------------------------
| Database Scalar Types
|--------------------------------------------------------------------------
|
| Enable a database-specific preset to automatically register scalar types
| that map to native column types of the target engine.
|
| preset — one of: 'postgres', 'cockroachdb', 'mssql', 'oracle', or null
|
| Presets:
| postgres → UUID, BigInt, JSONB, Money, TSVector, Interval, Inet
| cockroachdb → UUID, BigInt, JSONB, Inet
| mssql → UUID, BigInt, Money
| oracle → UUID, BigInt, Interval
|
| custom — merge additional scalars on top of (or instead of) the preset:
| 'custom' => [
| 'EmailAddress' => \App\GraphQL\Scalars\EmailAddressType::class,
| ],
|
*/
'database_types' => [
'preset' => null,
'custom' => [],
],
/*
|--------------------------------------------------------------------------
| Batched Requests
|--------------------------------------------------------------------------
|
| Allow clients to send multiple GraphQL operations in a single HTTP request
| as a JSON array: [{"query":"..."}, {"query":"..."}].
|
| enabled — Set to true to accept batch requests. When false (the
| default) any array payload returns HTTP 400.
|
| max_operations — Upper bound on the number of operations allowed per
| batch. Requests that exceed this limit are rejected
| with HTTP 400. Set to 0 for no limit (not recommended
| in public APIs).
|
*/
'batching' => [
'enabled' => true,
'max_operations' => 10,
],
/*
|--------------------------------------------------------------------------
| GraphiQL
|--------------------------------------------------------------------------
|
| The built-in GraphiQL browser IDE at /graphql/graphiql.
|
| enabled — null (default) serves it only while app.debug is on, i.e. not
| in production. Set true to always serve it (then protect it with
| 'middleware', e.g. ['auth', 'can:viewGraphiql']) or false to never.
|
*/
'graphiql' => [
'enabled' => null,
'middleware' => [],
'title' => 'Laragraph — GraphiQL',
],
/*
|--------------------------------------------------------------------------
| Tracing
|--------------------------------------------------------------------------
|
| When enabled, every field resolution (root Query/Mutation/Subscription
| fields and nested Type fields alike) is timed and reported under
| `extensions.tracing`, following the Apollo Tracing format. Disabled by
| default — enabling it adds a small wrapping cost to every resolver call,
| so it's best turned on selectively (e.g. behind a debug/admin guard)
| rather than left on for a public production API.
|
*/
'tracing' => [
// Per-field timings under extensions.tracing — for local debugging only.
'enabled' => env('LARAGRAPH_TRACING', false),
],
/*
|--------------------------------------------------------------------------
| Subscriptions
|--------------------------------------------------------------------------
|
| webonyx/graphql-php has no built-in subscription transport, so Laragraph
| provides one: the initial subscription request registers a subscriber
| (query + variables + the channel returned by the field's subscribe())
| and returns a channel/subscriberId pair instead of data. Application
| code then calls Laragraph::broadcast($channel, $payload) — typically
| from inside a mutation or a model event listener — to re-execute every
| registered subscriber's original query with $payload as the root value
| and push the result to that subscriber's own private channel via
| Laravel Broadcasting.
|
| enabled — Set to true to accept subscription operations. When
| false (default) they're rejected with a client error.
| driver — 'broadcast' pushes via Laravel Broadcasting (Reverb,
| Pusher, ...); 'log' writes updates to the log instead,
| useful for local development without a broadcast server.
| cache_store — Laravel cache store used to persist subscriber
| registrations; null uses the application's default.
| ttl — Subscriber registration lifetime in seconds.
| channel_prefix — Prefix for the private channel each subscriber is
| pushed to: "{prefix}.{subscriberId}".
|
*/
'subscriptions' => [
'enabled' => true,
'driver' => 'broadcast',
'cache_store' => null,
'ttl' => 3600,
'channel_prefix' => 'graphql-subscriber',
// Register the private-channel rule that lets only a subscription's
// owner listen to it. Set to false to define your own rule in
// routes/channels.php for "{channel_prefix}.{subscriberId}".
'authorize_channel' => true,
// Where Laragraph::broadcastLater() queues subscription fan-out
// (null: the application's default connection / queue).
'queue' => [
'connection' => null,
'queue' => null,
],
],
];