Hotchocolate: Field selection dependency

Created on 10 Nov 2020  ยท  1Comment  ยท  Source: ChilliCream/hotchocolate

Is there a way to add a dependency for some field?
This example returns null if descriptionLocaleId is not selected in gql query.

descriptor.Field("description").Resolver(ctx => ctx.Parent<Item>().DescriptionLocaleId);

I am using EF Core 5, Hot Chocolate v11 with UseProjectionAttribute

Desired functionality:

descriptor.Field("description").DependsOn(x => x.DescriptionLocaleId).Resolver(ctx => ctx.Parent<Item>().DescriptionLocaleId);
โ“ question

Most helpful comment

@JakeSmokie
We plan to add resolver metadata to do exactly that

For now you can use the IsProjectedAttribute

[IsProjected(true)]
public string DescriptionLocaleId {get;set;}

or set it via

descriptor.Field(x => x.DescriptionLocaleId).IsProjected(true);

This way this field is always projected and your resolver should work.
Direct resolver dependencies will come in a later release

>All comments

@JakeSmokie
We plan to add resolver metadata to do exactly that

For now you can use the IsProjectedAttribute

[IsProjected(true)]
public string DescriptionLocaleId {get;set;}

or set it via

descriptor.Field(x => x.DescriptionLocaleId).IsProjected(true);

This way this field is always projected and your resolver should work.
Direct resolver dependencies will come in a later release

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sfmskywalker picture sfmskywalker  ยท  3Comments

sascha-andres picture sascha-andres  ยท  4Comments

jbray1982 picture jbray1982  ยท  5Comments

nigel-sampson picture nigel-sampson  ยท  5Comments

RohrerF picture RohrerF  ยท  3Comments