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

Prevent crashing crashing the GraphQL schema when SEO feature is also enabled #16141

Conversation

tropcicstefan
Copy link
Contributor

Fixes #16140

@@ -30,6 +30,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Seo.Abstractions\OrchardCore.Seo.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Shortcodes.Abstractions\OrchardCore.Shortcodes.Abstractions.csproj" />
<ProjectReference Include="..\OrchardCore.Indexing\OrchardCore.Indexing.csproj" />
<ProjectReference Include="..\OrchardCore.Media\OrchardCore.Media.csproj" />
Copy link
Member

@MikeAlhayek MikeAlhayek May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tropcicstefan Let's not add this dependency. Two alternative ways to do this

First approach, move the SeoMetaQueryObjectType class into the Media module and register it using the following startup "in the Media startup

[RequireFeatures("OrchardCore.Apis.GraphQL", "OrchardCore.Seo")]
public class Startup : StartupBase
{
    public override void ConfigureServices(IServiceCollection services)
    {
        services.AddObjectGraphType<MetaEntry, MetaEntryQueryObjectType>();
        services.AddObjectGraphType<SeoMetaPart, SeoMetaQueryObjectType>();
    }
}

Second approach, Move both MediaFieldQueryObjectType and MediaAssetObjectType out of OrchardCore.Media and place them into OrchardCore.Media.Core. New the the SEO module can depend on OrchardCore.Media.Core and you are good to go.

However, I am thinking to combine the 2 solutions. The first solution is better but at the same time we should also move MediaFieldQueryObjectType and MediaAssetObjectType out of OrchardCore.Media and place them into OrchardCore.Media.Core.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, but want to know what is the reasoning, why shouldn't it depend on media when it's already dependant with manifest?

Copy link
Member

@MikeAlhayek MikeAlhayek May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tropcicstefan In OC, we do not allow a module to reference another module. It's okay for a module to reference on core projects but not a module. It is okay to have dependencies using the Mainifest file, but not project reference.

@MikeAlhayek MikeAlhayek changed the title fix: Seo module crashing whole GraphQL schema Prevent crashing crashing the GraphQL schema when SEO feature is also enabled May 22, 2024
Copy link
Member

@MikeAlhayek MikeAlhayek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please review the newly added references to double check if all these are really needed?

@@ -6,7 +6,7 @@
using OrchardCore.Apis.GraphQL;
using OrchardCore.Media.Fields;

namespace OrchardCore.Media.GraphQL
namespace OrchardCore.Media.Core.GraphQL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not change the namespace to avoid users having to fix their code if they are using this class

@@ -18,6 +18,8 @@

<ItemGroup>
<ProjectReference Include="..\OrchardCore.Infrastructure.Abstractions\OrchardCore.Infrastructure.Abstractions.csproj" />
<ProjectReference Include="..\OrchardCore.ContentManagement.Abstractions\OrchardCore.ContentManagement.Abstractions.csproj" />
<ProjectReference Include="..\OrchardCore.Media.Core\OrchardCore.Media.Core.csproj" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abstraction module should never depend on a core module

using OrchardCore.Seo.Models;

namespace OrchardCore.Seo.GraphQL;
namespace OrchardCore.Media.GraphQL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not change the namespace here.

@gvkries
Copy link
Contributor

gvkries commented May 23, 2024

This does not actually fix the underlaying problem. The problem is that GraphQL types are registered as scoped (as introduced by #15319). Therefore resolving them while building the schema as a singleton fails.

We will encounter these errors again, if we don't fix the way types are registered for GraphQL.

@gvkries
Copy link
Contributor

gvkries commented May 23, 2024

I think #16143 is a simpler solution and also fixes similar bugs we may encounter in the future.

@tropcicstefan
Copy link
Contributor Author

I think #16143 is a simpler solution and also fixes similar bugs we may encounter in the future.

probably true, but this should also be fixed because it only works for now because of ObjectGraphTypeFieldProvider.GetObjectGraphType. Fields should be mapped to correct types

@gvkries
Copy link
Contributor

gvkries commented May 23, 2024

probably true, but this should also be fixed because it only works for now because of ObjectGraphTypeFieldProvider.GetObjectGraphType. Fields should be mapped to correct types

Hmm, I don't think that has to change. Using the base class (ObjectGraphType<MediaField> in this case) is enough and it avoids having to reference the actual field type. No need to move any type around.

@tropcicstefan
Copy link
Contributor Author

it's ridiculous that I need as much instances of ObjectGraphType for a mediafield as there are nodes of mediafield in schema graph its a base type there should be only one instance

@gvkries
Copy link
Contributor

gvkries commented May 23, 2024

it's ridiculous that I need as much instances of ObjectGraphType for a mediafield as there are nodes of mediafield in schema graph its a base type there should be only one instance

Sorry, I don't understand. Can you elaborate?

@MikeAlhayek
Copy link
Member

@tropcicstefan if you are using the OC direct code "main branch", can you see if the crash issue you are having is fixed? Is you are using the preview, please wait until tomorrow and see if the latest previews fixes you issues.

@tropcicstefan
Copy link
Contributor Author

it's ridiculous that I need as much instances of ObjectGraphType for a mediafield as there are nodes of mediafield in schema graph its a base type there should be only one instance

Sorry, I don't understand. Can you elaborate?

If you have five content types and each has one mediafield, with your code there will be five instances of MediaFieldQueryObjectType

@gvkries
Copy link
Contributor

gvkries commented May 23, 2024

it's ridiculous that I need as much instances of ObjectGraphType for a mediafield as there are nodes of mediafield in schema graph its a base type there should be only one instance

Sorry, I don't understand. Can you elaborate?

If you have five content types and each has one mediafield, with your code there will be five instances of MediaFieldQueryObjectType

Oh, I see. Yes that is true, but there is no easy way around.

Edit: I tested that quickly and it doesn't look like that. It' instantiating the type only once.

@MikeAlhayek
Copy link
Member

@tropcicstefan did you get a chance to try out the latest code and see if your issue is fixed without this PR?

@tropcicstefan
Copy link
Contributor Author

Bug was on latest preview that day, and other pr fixes it. I don't think it's correct to convert to transient, but ok

@MikeAlhayek
Copy link
Member

I don't think it's correct to convert to transient, but ok

@tropcicstefan but did you confirm that it actually fixes your issue? The schema is built once and using transient isn't bad since it's not created on every request.

@tropcicstefan
Copy link
Contributor Author

yes it fixes the issue, confirmed

@gvkries
Copy link
Contributor

gvkries commented May 28, 2024

Bug was on latest preview that day, and other pr fixes it. I don't think it's correct to convert to transient, but ok

Originally, all GraphQL types were registered as singletons, but that had other problems after upgrading the GraphQL version itself (e.g. #15304, because the schema has to be rebuilt when dynamic types have changed).
'Scoped' can't be used here either, because the schema itself is still a singleton. So all that remains is the transient... 🤷‍♂️

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

Successfully merging this pull request may close these issues.

Seo module crashing whole GraphQL schema
3 participants