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
Bydefault, Supergraphschema excludes all custom directives. The `@composeDirective` is used to specify custom directives that should be exposed in the Supergraph schema.
16
+
17
+
Example:
18
+
Given `@custom` directive we can preserve it in the Supergraph schema
See [@composeDirectivedefinition](https://www.apollographql.com/docs/federation/federated-types/federated-directives/#composedirective) for more information.
besafelyomittedfromtheschema. `@external` directive is only required on fields referenced by the `@requires` and
137
+
`@provides` directive.
91
138
92
139
#### Example
93
140
94
141
```kotlin
95
142
@KeyDirective(FieldSet("id"))
96
-
@ExtendsDirective
97
-
class Product(@ExternalDirective val id: String) {
98
-
fun newFunctionality(): String = "whatever"
143
+
class Product(val id: String) {
144
+
@ExternalDirective
145
+
var externalField: StringbyDelegates.notNull()
146
+
147
+
@RequiresDirective(FieldSet("externalField"))
148
+
funnewFunctionality(): String { ... }
99
149
}
100
150
```
101
151
102
152
will generate
103
153
104
154
```graphql
105
-
typeProduct@key(fields : "id") @extends {
106
-
id: String!@external
155
+
typeProduct@key(fields : "id") {
156
+
externalField: String!@external
157
+
id: String!
107
158
newFunctionality: String!
108
159
}
109
160
```
@@ -127,7 +178,10 @@ directive @inaccessible on FIELD_DEFINITION
127
178
| ARGUMENT_DEFINITION
128
179
```
129
180
130
-
Inaccessibledirectivemarkslocationwithinschema as inaccessible from the GraphQL Gateway. This allows you to incrementally add schema elements (e.g. fields) to multiple subgraphs without breaking composition.
181
+
Inaccessibledirectivemarkslocationwithinschema as inaccessible from the GraphQL Gateway. While `@inaccessible` fields are not exposed by the gateway to the clients,
182
+
they are still available for query plans and can be referenced from `@key` and `@requires` directives. This allows you to not expose sensitive fields to your clients but
183
+
still make them available for computations. Inaccessible can also be used to incrementally add schema elements (e.g. fields) to multiple subgraphs without breaking composition.
184
+
131
185
See [@inaccessible specification](https://specs.apollo.dev/inaccessible/v0.2) for additional details.
The `@link` directivelinksdefinitionswithinthedocumenttoexternalschemas. See [@linkspecification](https://specs.apollo.dev/link/v1.0) fordetails.
@@ -246,6 +353,19 @@ External schemas are identified by their `url`, which optionally ends with a nam
246
353
Bydefault, externaltypesshouldbenamespaced (prefixed with `<namespace>__`, e.g. `key` directive should be namespaced as `federation__key`) unlesstheyareexplicitlyimported.
We currently DO NOT support full `@link` directive capability as it requires support for namespacing and renaming imports. This functionality may be added in the future releases. See
251
371
[@link specification](https://specs.apollo.dev/link/v1.0) for details.
@@ -300,18 +420,16 @@ directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
federatedobjecttypetobeselectablefromthefederatedschema. Provided fields specified in the directive field set
306
-
should correspond to a valid field on the underlying GraphQL interface/object type. `@provides` directive can only be
307
-
used on fields returning federated extended objects.
308
-
309
-
#### Example 1:
423
+
The `@provides` directiveisarouteroptimizationhintspecifyingfieldsetthatcanberesolvedlocallyatthegivensubgraphthroughthisparticularquerypath. Thisallowsyouto
424
+
exposeonlyasubsetoffieldsfromtheunderlyingentitytypetobeselectablefromthefederatedschema without the need to call other subgraphs. Provided fields specified in the
425
+
directive field set should correspond to a valid field on the underlying GraphQL interface/object type. `@provides` directive can only be used on fields returning entities.
310
426
311
427
:::info
312
-
Due to the smart entity type merging, Federation v2 does not require `@provides` directive if field can always be resolved locally.
428
+
Federation v2 does not require `@provides` directive if field can **always** be resolved locally. `@provides` should be omitted in this situation.
313
429
:::
314
430
431
+
#### Example 1:
432
+
315
433
We might want to expose only name of the user that submitted a review.
316
434
317
435
```kotlin
@@ -322,9 +440,8 @@ class Review(val id: String) {
322
440
}
323
441
324
442
@KeyDirective(FieldSet("userId"))
325
-
@ExtendsDirective
326
443
classUser(
327
-
@ExternalDirective val userId: String,
444
+
val userId: String,
328
445
@ExternalDirective val name: String
329
446
)
330
447
```
@@ -337,8 +454,8 @@ type Review @key(fields : "id") {
337
454
user: User!@provides(fields : "name")
338
455
}
339
456
340
-
typeUser@key(fields : "userId") @extends{
341
-
userId: String!@external
457
+
typeUser@key(fields : "userId") {
458
+
userId: String!
342
459
name: String!@external
343
460
}
344
461
```
@@ -372,43 +489,34 @@ directive @requires(fields: _FieldSet!) on FIELD_DEFINITON
The `@requires` directiveisusedtospecifyexternal (provided by other subgraphs) entityfieldsthatareneededtoresolvetargetfield. Itisusedtodevelopaqueryplanwhere
@@ -474,5 +582,6 @@ type Product @tag(name: "MyCustomTag") {
474
582
```
475
583
476
584
:::caution
477
-
ApolloContractsbehaveslightlydifferentlydependingonwhichversionofApolloFederationyourgraphuses (1 or 2). See [documentation](https://www.apollographql.com/docs/studio/contracts/#federation-1-limitations) for details.
585
+
ApolloContractsbehaveslightlydifferentlydependingonwhichversionofApolloFederationyourgraphuses (1 or 2). See [documentation](https://www.apollographql.com/docs/studio/contracts/#federation-1-limitations)
0 commit comments