Skip to content
New issue

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

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

Already on GitHub? # to your account

Schema Reloading without app restart - Headless CMS #6113

Closed
hnazari13701371 opened this issue May 3, 2023 · 1 comment
Closed

Schema Reloading without app restart - Headless CMS #6113

hnazari13701371 opened this issue May 3, 2023 · 1 comment

Comments

@hnazari13701371
Copy link

Product

Hot Chocolate

Is your feature request related to a problem?

hi , i want to design and develop a headless cms . one of the first thing this kind of app is that an end user use data modeler to model their needs but when they create their model i need also change the schema base on changes .
i wonder how i can accomplish what i describe above
thanks

The solution you'd like

whenever user change model my schema change on the fly

@michaelstaib michaelstaib added ❓ question This issue is a question about feature of Hot Chocolate. 🌶️ hot chocolate and removed 🎉 enhancement labels May 6, 2023
@maxnatamo
Copy link

maxnatamo commented Jun 27, 2023

I've been looking for something similar. It would technically be possible by using the ITypeModule-interface and generate new types on the fly. However, I don't know if there's any way to create ObjectTypeDefinition-instances from a C# type, which would simplify it a lot. The alternative is to write field-descriptors manually, which would be a great pain.

It seems there is a really easy solutions already. If you return an empty list from ITypeModule.CreateTypesAsync, it will force a reload of the models (an eviction):

nternal static class ApplicationUpdateHandler
{
    public static event EventHandler? ApplicationUpdated;

    public static void UpdateApplication(Type[]? updatedTypes)
    {
        ApplicationUpdated?.Invoke(null, EventArgs.Empty);
    }
}

internal sealed class HotReloadTypeModule : ITypeModule
{
    public HotReloadTypeModule()
    {
        ApplicationUpdateHandler.ApplicationUpdated +=
            (s, e) => TypesChanged?.Invoke(this, EventArgs.Empty);
        ;
    }

    public event EventHandler<EventArgs>? TypesChanged;

    public ValueTask<IReadOnlyCollection<ITypeSystemMember>> CreateTypesAsync(
        IDescriptorContext context, CancellationToken cancellationToken)
    {
        // We do not generate any types here, as we just want to evict the
        // RequestExecutor and rebuild the original schema, by invoking TypesChanged.
        return ValueTask.FromResult<IReadOnlyCollection<ITypeSystemMember>>(
            Array.Empty<ITypeSystemMember>());
    }
}

Source: #5165

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants