Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access Rich Text field with Macro via GraphQL #73

Open
rangler2 opened this issue Oct 8, 2021 · 2 comments
Open

Cannot access Rich Text field with Macro via GraphQL #73

rangler2 opened this issue Oct 8, 2021 · 2 comments

Comments

@rangler2
Copy link

rangler2 commented Oct 8, 2021

Hi,

Just raising this on the off chance that someone has already fixed this... Am running a customised version of the Umbraco 7 version of GraphQL based upon the 0.1.0 version found on nuget which I think was from the master branch..

If I add a simple macro (with no parameters, using a .cshtml that just outputs some text) into a rich text editor and then try to retrieve this via GraphQL then the value is null and following error is included in the response:

image

If I attach the debugger then it throws on this line because it can't get the Value -

: resolver.Resolve(publishedPropertyType, publishedProperty.Value);

The exception is -

System.InvalidOperationException
  HResult=0x80131509
  Message=Cannot render a macro when there is no current PublishedContentRequest.
  Source=umbraco
  StackTrace:
   at Umbraco.Web.UmbracoComponentRenderer.RenderMacro(String alias, IDictionary`2 parameters)
   at Umbraco.Web.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.<>c__DisplayClass0_1.<RenderRteMacros>b__1(String macroAlias, Dictionary`2 macroAttributes)
   at Umbraco.Core.Macros.MacroTagParser.ParseMacros(String text, Action`1 textFoundCallback, Action`2 macroFoundCallback)
   at Umbraco.Web.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.RenderRteMacros(String source, Boolean preview)
   at Umbraco.Web.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.ConvertDataToSource(PublishedPropertyType propertyType, Object source, Boolean preview)
   at Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.get_Value()
   at Our.Umbraco.GraphQL.Types.ComplexGraphTypeOfIPublishedContentExtensions.<>c__DisplayClass2_1.<AddUmbracoContentPropeties>b__0(ResolveFieldContext`1 context) in C:\working_git\my-navy-umbraco\Our.Umbraco.GraphQL\Types\ComplexGraphTypeOfIPublishedContentExtensions.cs:line 115
   at GraphQL.Resolvers.FuncFieldResolver`2.GraphQL.Resolvers.IFieldResolver.Resolve(ResolveFieldContext context)
   at GraphQL.Instrumentation.MiddlewareResolver.Resolve(ResolveFieldContext context)
   at GraphQL.Resolvers.FuncFieldResolver`1.GraphQL.Resolvers.IFieldResolver.Resolve(ResolveFieldContext context)
   at GraphQL.Execution.ExecutionStrategy.<ExecuteNodeAsync>d__7.MoveNext()

I am now trying to work out how to artificially add an Umbraco Context into this class but raising in case someone has solved this previously , and if not I can update if/when I figure it out.....

Thanks,
Andy

@rangler2
Copy link
Author

rangler2 commented Oct 8, 2021

Hi,

I fixed it by adding the following to the start of the method to trick it into using the context of the homepage -

UmbracoContext.Current.PublishedContentRequest = new PublishedContentRequest(new Uri("https://mysite.localhost/"), UmbracoContext.Current.RoutingContext);
UmbracoContext.Current.PublishedContentRequest.Prepare();

Cheers
Andy

@rangler2
Copy link
Author

rangler2 commented Oct 8, 2021

Actually it sometimes reverted back to null by having it before the foreach loop so I had to move it into the loop and change it so it only does this when a macro is found otherwise it makes the request take way longer (over a minute) just from repeatedly setting the context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant