Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 10, 2020 @ 08:57
    Ismail Mayat
    0

    Modify graphql property before render

    I have site v7 that is using umbraco graphql package. I have doctype alert which I can get using query like:

    { content {
    byUrl(url: "/alerts/test/") {
      ... on Alert {
        _contentData {
          name
        },title
        summary
      }
    }}}
    

    What i want to do is before render for the summary field which is rich text edit field modify img tag. I have service to do this however I am unsure how to tap in the rendering process of graphql to intercept. I have for now got project using actual source code of umbraco graphql project.

    Would I need to modify StringValueResolver and create my own StringGraphType that does the transformation?

            public override Type GetGraphQLType(PublishedPropertyType propertyType)
        {
    
            if (propertyType.PropertyTypeAlias == "summary")
            {
                return typeof(CustomStringGraphType);
            }
    
            return propertyType.ClrType == typeof(string) 
                ? typeof(StringGraphType)
                : typeof(ListGraphType<StringGraphType>);
        }
    

    And in my CustomStringGraphType override

        public override object Serialize(object value)
    {
      return value;
    }
    

    and do my transformation there?

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 10, 2020 @ 15:12
    Ismail Mayat
    100

    OK so managed to get this sorted. I modified ComplexGraphTypeOfIPublishedContentExtensions.cs and around line 113 added the following:

     if (AlertWithImage(context, publishedProperty))
                        {
                            HtmlString tmp = (HtmlString) propertyValue;
                            var transformed = encoder.Convert(tmp.ToHtmlString());
                            HtmlString html = new HtmlString(transformed);
                            propertyValue = html;
                        }
    

    That did it

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies