DRAFT - Resolver Metadata #4847
                  
                    
                      PascalSenn
                    
                  
                
                  started this conversation in
                Feature Request
              
            Replies: 1 comment
-
| This is a good summary of our discussions. I will write down a view things around this on more detail once I find some time over the weekend. | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Resolver Metadata
In our last work group meeting we were discussing the UseSelection API of the new entity framework integration.
We were also discussing the
[Parent]attribute we currently use to inject the parent into a resolver.In the
UseSelectionfeature and also in V11 of HotChocolate we will need to add metadata to fields. This will enable the execution engine to execute queries in a very efficient way. The same metadata is used to create the lambda for the projection ofUseSelection. The metadata is indicating what properties have to be selected from the queryable for a give selection set.This issue refers often to a
Usertype defined as follows:{ "id": "a81f59f6-d8d6-467d-aa12-f49925265660", "name": "Marie", "lastName": "Curie", "displayName": "Marie Curie" }Terminology
user.Name{ displayName }Example of UseSelection
{ name }x => new User() {Name = x.Name }{ name lastName }x => new User() {Name = x.Name ,LastName = x.LastName }{ displayName lastName }x => new User() {Name = x.Name ,LastName = x.LastName }{ displayName }x => new User() {Name = x.Name ,LastName = x.LastName }Explanation:
The execution engine knows that when the field
nameis selected, then the propertyNameof the .Net Type needs to be selected. The same holds forlastName. As soon asdisplayNameis selected, which is a composition of name concatenated with last name, both properties need to be selected.Resolver Data
In the work group meeting we were focused on how we annotate resolvers with the metadata. It makes sense to first define what metadata we need for the execution and then define annotation interfaces.
A short overview of different types of metadata and their semantics is shown below:
GlobalStateIndicates consumption of a value of the global stateSetGlobalStateIndicates manipulation of a value of the global stateLocalStateIndicates consumption of a value of the local stateSetLocalStateIndicates manipulation of a value of the local stateScopedStateIndicates consumption of a value of the scoped stateSetScopedStateIndicates manipulation of a value of the scoped stateEntityIndicates consumption of a member of the entityFieldIndicates consumption of a field of the current typeArgumentIndicates consumption of an argumentIsArgumentIndicates the equality of an argument of the parent field and the current resolverServiceIndicates consumption of a serviceRessourceIndicates consumption of a resourceGlobal/Local/Scoped State
Resolver of fields can manipulate and consume state that is stored on the
ResolverContext.The implications of a consumption or manipulation of state on the execution, differ by the type of state.
Entity
The entity metadata, represents a dependency on a property of an entity. In case of a
ObjectType<TType>the entity would be an .Net Object of the typeTType.In case of a stichted type, the Entity may be a collection of
KeyValuePairs.Field
Field indicates that the current resolver has a dependency on another field. In case of the execution engine this would mean that this field has to be resolved before the current resolver.
Argument
A resolver can consume arguments
IsArgument
A resolver can return the same values as an already provided argument. In the following case the field
idwould not need to be resolved. The field is already known because of the argumentinput.id.{ getUser(input: { id: "a81f59f6-d8d6-467d-aa12-f49925265660" }) { id name } }Service / Ressource
A resolver may have a dependency on a service. e.g. in the resolver of the field
getUserstheUserrepository may be neededThe service may belong to a resource
{ getUsers { id name } }Entity and Field
EntityandFieldmay seem equal. This is not the case.An entity may have more information than the information represented by fields.
When we reduce the
Usertype like the following this becomes clear:The field
DisplayNamedoes not exists on the entity (in this case the .net typeUser), but hasdependencies on two properties of the entity.
The Problem with
IResolverContextand[Parent] TParentIResolverContextAs soon as a resovler has a dependency on
IResolverContextall metadata of the resolver is gone.The table below shows the possible metadata cause by a dependency on
IResolverContextresolverContext.ArgumentresolverContext.ContextDataresolverContext.LocalContextDataresolverContext.ScopedContextDataresolverContext.Parent<T>()resolverContext.Service<T>()resolverContext.Source[Parent] TParentA dependency on
[Parent] TParentcauses a dependency of all properties of the parent entity.Meta Data Annotation
Resolver metadata can only work when there is a way to provide the necessary information in all cases. All cases need to have way to annotate all the metadata defined under Resolver Data
Cases
PCF1 - Pure Code First Property
PCF2 - Pure Code First ComputedField
PCF3 - Pure Code First Extension
TO_BE_CONTINUED
Beta Was this translation helpful? Give feedback.
All reactions