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
* Added @specifiedBy directive documentation
* Added inheritance sections to OBJECT and INTERFACE pages
* Various clean ups and word edits to other pages
Since our scalar is, internally, represented by a class, if we don't pre-register it GraphQL will attempt to parse the `Money` class as an object graph type. Once registered as a scalar, any attempt to use `Money` as an object graph type will cause an exception.
246
+
Since our scalar is represented by a .NET class, if we don't pre-register it GraphQL will attempt to parse the `Money` class as an object graph type. Once registered as a scalar, any attempt to use `Money` as an object graph type will cause an exception.
247
+
248
+
## @specifiedBy Directive
249
+
250
+
GraphQL provides a special, built-in directive called `@specifiedBy` that allows you to supply a URL pointing to a the specification for your custom scalar. This url is used by various tools to additional data to your customers so they know how to interact with your scalar type. It is entirely optional.
251
+
252
+
The @specifiedBy directive can be applied to a scalar in all the same ways as other type system directives or by use of the special `[SpecifiedBy]` attribute.
- Looking through the [built in scalars](https://github.com/graphql-aspnet/graphql-aspnet/tree/master/src/graphql-aspnet/Schemas/TypeSystem/Scalars) can be helpful when designing your own.
252
286
- Scalar types are expected to be thread safe.
253
287
- The runtime will pass a new instance of your scalar graph type to each registered schema. It must be declared with a public, parameterless constructor.
254
288
- Scalar types should be simple and work in isolation.
255
-
- The `ReadOnlySpan<char>` provided to the `Resolve()` method should be all the data needed to generate a value, there should be no need to perform side effects or fetch additional data.
289
+
- The `ReadOnlySpan<char>` provided to `ILeafValueResolver.Resolve` should be all the data needed to generate a value, there should be no need to perform side effects or fetch additional data.
256
290
- If you have a lot of logic to unpack a string, consider using a regular OBJECT graph type instead.
257
291
- Scalar types should not track any state or depend on any stateful objects.
258
-
-`ILeafValueResolver.Resolve` must be **FAST**! Since your resolver is used to construct an initial query plan, it'll be called #orders of magnitude more often than any controller action method.
292
+
-`ILeafValueResolver.Resolve` must be **FAST**! Since your resolver is used to construct an initial query plan from a text document, it'll be called orders of magnitude more often than any other method.
Copy file name to clipboardExpand all lines: docs/advanced/directives.md
+46-5Lines changed: 46 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -224,6 +224,8 @@ This Directive:
224
224
225
225
### Example: @deprecated
226
226
227
+
The @deprecated directive is a built in directive provided by graphql to indication deprecation on a field definition or enum value. Below is the code for its implementation.
DirectivesareinvokedasservicesthroughyourDIcontainerwhentheyareexecuted. Whenyouaddtypestoyourschemaduringitsinitialconfiguration, GraphQLASP.NETwillautomaticallyregisteranydirectivesitfindsattachedtoyourobjectsandpropertiesasservicesinyour `IServiceCollection` instance. However, therearetimeswhenitcannotdothis, suchaswhenyouapplyadirectivebyitsstringdeclaredname. Theselate-bounddirectivesmaystillbediscoverablelaterandgraphqlwillattempttoaddthemtoyourschemawheneveritcan. However, itmaydothisaftertheopportunitytoregisterthemwiththeDIcontainerhaspassed.
480
+
DirectivesareinvokedasservicesthroughyourDIcontainerwhentheyareexecuted. Whenyouaddtypestoyourschemaduringitsinitialconfiguration, GraphQLASP.NETwillautomaticallyregisteranydirectivesitfindsattachedtoyourentitiesasservicesinyour `IServiceCollection` instance. However, therearetimeswhenitcannotdothis, suchaswhenyouapplyadirectivebyitsstringdeclaredname. Theselate-bounddirectivesmaystillbediscoverablelaterandgraphqlwillattempttoaddthemtoyourschemawheneveritcan. However, itmaydothisaftertheopportunitytoregisterthemwiththeDIcontainerhaspassed.
440
481
441
482
Whenthisoccurs, ifyourdirectivecontainsapublic, parameterlessconstructorgraphqlwillstillinstantiateanduseyourdirectiveasnormal. Ifthedirectivecontainsdependenciesintheconstructorthatitcan't resolve, execution of that directive will fail and an exception will be thrown. To be safe, make sure to add any directives you may use to your schema during the `.AddGraphQL()` configuration method. Directives are directly discoverable and will be included via the `options.AddAssembly()` helper method as well.
GraphQLASP.NETbuildsyourschemaandallofitstypesfromyourcontrollersandobjects. Ingeneral, thisisdonebehindthescenesandyoudonotneedtointeractwithit. However, whenapplyingtypesystemdirectivesyouareaffectingthefinalgeneratedschemaatruntimeandneedtounderstandthevariouspartsofit. Ifyouhaveaquestiondon't be afraid to ask on [github](https://github.com/graphql-aspnet/graphql-aspnet).
458
499
459
500
**UMLDiagrams**
460
501
461
-
These [umldiagrams](../assets/2022-05-graphql-aspnet-type-system-interface-diagrams.pdf) detailsthemajorinterfacesandtheirmostusefulpropertiesofthetypesystem. However,
502
+
These [umldiagrams](../assets/2022-05-graphql-aspnet-type-system-interface-diagrams.pdf) detailthemajorinterfacesandtheirmostusefulpropertiesofthetypesystem. However,
462
503
thesediagramsarenotexaustive. Lookatthe [sourcecode](https://github.com/graphql-aspnet/graphql-aspnet/tree/master/src/graphql-aspnet/Interfaces/TypeSystem) for the full definitions.
463
504
464
505
**HelpfulExtensions**
465
506
466
-
Therearearobustsetofofbuiltinextensionsfor `ISchemaItem` thatcanhelpyoufilteryourdata. Seethe [fullsourcecode](https://github.com/graphql-aspnet/graphql-aspnet/tree/master/src/graphql-aspnet/Configuration/SchemaItemExtensions.cs) for details.
507
+
Therearearobustsetofofbuiltinextensionsfor `ISchemaItem` thatcanhelpyoufilteryourdatawhenapplyingdirectives. Seethe [fullsourcecode](https://github.com/graphql-aspnet/graphql-aspnet/tree/master/src/graphql-aspnet/Configuration/SchemaItemExtensions.cs) for details.
Copy file name to clipboardExpand all lines: docs/advanced/middleware.md
+20-12Lines changed: 20 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -140,9 +140,8 @@ The field execution pipeline is executed once for each field of data that needs
140
140
141
141
1.`ValidateFieldExecutionMiddleware` : Validates that the context and required invocation data has been correctly supplied.
142
142
2.`AuthorizeFieldMiddleware` : If the schema is configured for `PerField` authorization this component will invoke the field authorization pipeline for the current field and assign authorization results as appropriate.
143
-
3.`InvokeDirectiveResolversMiddleware` : Any directives that were attached to the active field are executed and their results acted on accordingly.
144
-
4.`InvokeFieldResolverMiddleware` : The field resolver is called and a data value is created for the active context. This middleware component is ultimately responsible for invoking your controller actions.
145
-
5.`ProcessChildFieldsMiddleware` : If any child fields were registered with the invocation context for this field they are dispatched using the context's field result as the new source object.
143
+
4.`InvokeFieldResolverMiddleware` : The field resolver is called and a data value is created for the active context. This middleware component is ultimately responsible for invoking your controller actions. It also handles call outs to the directive execution pipeline when required.
144
+
4.`ProcessChildFieldsMiddleware` : If any child fields were registered with the invocation context for this field they are dispatched using the context's field result as the new source object.
146
145
147
146
#### GraphFieldExecutionContext
148
147
@@ -165,24 +164,28 @@ public class GraphFieldExecutionContext
165
164
166
165
The field authorization pipeline can be invoked as part of query execution or field execution depending on your schema's configuration. It contains 1 component:
167
166
168
-
1.`FieldAuthorizationCheckMiddleware`: Inspects the active `ClaimsPrincipal` against the security requirements of the field on the context and generates a `FieldAuthorizationResult` indicating if the user is authorized or not. This component makes no decisions in regards to the authorization state. It is up to the other pipelines to act on the authorization results that are generated.
167
+
1.`FieldSecurityRequirementsMiddleware` : Gathers the authentication and authorization requirements for the given field and ensures that the field _can_ be authorized. There are some instances where by
168
+
nested authorization requirements create a scenario in which no user could ever be authorized. This generally involves using multiple auth providers with specific authentication scheme requirements.
169
+
2.`FieldAuthenticationMiddleware` : Authenticates the request to the field. This generates a ClaimsPrincipal to be authorized against.
170
+
3.`FieldAuthorizationMiddleware`: Inspects the active `ClaimsPrincipal` against the security requirements of the field on the context and generates a `FieldAuthorizationResult` indicating if the user is authorized or not. This component makes no decisions in regards to the authorization state. It is up to the other pipelines to act on the authorization results that are generated.
169
171
170
172
#### GraphFieldAuthorizationContext
171
173
172
-
In addition to the common properties defined above the field authorization context defines a number of useful properties:
174
+
In addition to the common properties defined above the field security context defines a number of useful properties:
-`Request`: Contains the field metadata for this context, including the security rules that need to be checked.
185
-
-`Result`: The generated authorization result indicating if the user is authorized or unauthorized for the field. This result will contain additional detailed information as to why a request was not authorized. This information is automatically added to any generated log events.
186
+
-`SecurityRequirements`: The security rules that need to be checked to authorize a user.
187
+
-`Request`: Contains details about the field currently being authed.
188
+
-`Result`: The generated challenge result indicating if the user is authorized or unauthorized for the field. This result will contain additional detailed information as to why a request was not authorized. This information is automatically added to any generated log events.
186
189
187
190
188
191
## Directive Execution Pipeline
@@ -199,10 +202,15 @@ public class GraphDirectiveExecutionContext
199
202
{
200
203
publicIGraphDirectiveRequestRequest { get; }
201
204
publicIDirectiveDirective {get;}
205
+
publicISchemaSchema {get; }
202
206
203
207
// common properties omitted for brevity
204
208
}
205
209
```
206
210
207
211
-`Request`: Contains the directive metadata for this context, including the DirectiveTarget, execution phase and executing location.
208
-
-`Directive`: The specific `IDirective`, registered to the schema, that is being processed.
212
+
-`Directive`: The specific `IDirective`, registered to the schema, that is being processed.
213
+
-`Schema`: the schema instance where the directive is declared.
214
+
215
+
> WARNING: Since the directive execution pipeline is used to construct the schema and apply type system directives, middleware components cannot inject a schema instance
216
+
from the DI container. To do so will cause a circular reference. Instead use the schema instance attached to the `GraphDirectiveExecutionContext`. The state of this schema object is not guaranteed at during schema generation as it will continue to change as type system directives are applied by the pipeline.
Copy file name to clipboardExpand all lines: docs/advanced/multiple-schema.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,11 @@ title: Multi-Schema Support
4
4
sidebar_label: Multi-Schema Support
5
5
---
6
6
7
-
GraphQL ASP.NET supports multiple schemas on the same server out of the box. Each schema is recognized by the runtime by its concrete type. To register multiple schemas you'll need to implement your own type that inherits from`ISchema`
7
+
GraphQL ASP.NET supports multiple schemas on the same server out of the box. Each schema is recognized by the runtime by its concrete type. To register multiple schemas you'll need to create your own type that implements`ISchema`
8
8
9
9
## Implement ISchema
10
10
11
-
While it is possible to implement directly from `ISchema` if you don't require any extra functionality in your schema its easier to just subclass the default schema.
11
+
While it is possible to implement `ISchema` directly, if you don't require any extra functionality in your schema its easier to just subclass the default schema.
0 commit comments