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
-
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
UseSelection
feature 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
User
type defined as follows: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
name
is selected, then the propertyName
of the .Net Type needs to be selected. The same holds forlastName
. As soon asdisplayName
is 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:
GlobalState
Indicates consumption of a value of the global state
SetGlobalState
Indicates manipulation of a value of the global state
LocalState
Indicates consumption of a value of the local state
SetLocalState
Indicates manipulation of a value of the local state
ScopedState
Indicates consumption of a value of the scoped state
SetScopedState
Indicates manipulation of a value of the scoped state
Entity
Indicates consumption of a member of the entity
Field
Indicates consumption of a field of the current type
Argument
Indicates consumption of an argument
IsArgument
Indicates the equality of an argument of the parent field and the current resolver
Service
Indicates consumption of a service
Ressource
Indicates consumption of a resource
Global/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
id
would not need to be resolved. The field is already known because of the argumentinput.id
.Service / Ressource
A resolver may have a dependency on a service. e.g. in the resolver of the field
getUsers
theUser
repository may be neededThe service may belong to a resource
Entity and Field
Entity
andField
may seem equal. This is not the case.An entity may have more information than the information represented by fields.
When we reduce the
User
type like the following this becomes clear:The field
DisplayName
does not exists on the entity (in this case the .net typeUser
), but hasdependencies on two properties of the entity.
The Problem with
IResolverContext
and[Parent] TParent
IResolverContext
As soon as a resovler has a dependency on
IResolverContext
all metadata of the resolver is gone.The table below shows the possible metadata cause by a dependency on
IResolverContext
resolverContext.Argument
resolverContext.ContextData
resolverContext.LocalContextData
resolverContext.ScopedContextData
resolverContext.Parent<T>()
resolverContext.Service<T>()
resolverContext.Source
[Parent] TParent
A dependency on
[Parent] TParent
causes 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