Skip to content

Instantly share code, notes, and snippets.

@serbasii
Last active August 30, 2019 16:26
Show Gist options
  • Save serbasii/8cb59a411d390386354b9b2aa5bab2de to your computer and use it in GitHub Desktop.
Save serbasii/8cb59a411d390386354b9b2aa5bab2de to your computer and use it in GitHub Desktop.
dotnet-graphql override AddField, get register type's description attribute and set FieldType
public class MyObjectType : ObjectGraphType<MyObject>
{
public MyObjectType()
{
Field(t => t.Code);
}
public override FieldType AddField(FieldType fieldType)
{
//var type_ = fieldType.Resolver.GetType().GetTypeInfo().GenericTypeArguments[0];
Type type = fieldType.Resolver.GetType().GetGenericArguments()[0];
string description = type.GetProperty(fieldType.Name).GetCustomAttribute<DescriptionAttribute>().Description;
fieldType.Description = description;
return base.AddField(fieldType);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment