Closed Lenny4 closed 11 months ago
By definition, GraphQL is Schema Based with strongly typed data. In essence, your question is how do you manage a dynamically changing Schema? And per the HC docs that is exactly what the Dynamic Schemas
feature is for....
Here the docs talk about building your schema during runtime based on types defined in a JSON file... which you would use your SQL DB (or other source) instead of the JSON file used in the example... https://chillicream.com/docs/hotchocolate/v13/defining-a-schema/dynamic-schemas#example-creating-types-from-a-json-file
You will have to take care to safely clear & rebuild your Schema when you change it dynamically.
In addition, you probably will not be able to use Strongly typed models as would normally be used in Hot Chocolate, because your schema will have changes that lose parity with the models (without re-compilation) and/or some other dynamic execution of C# code (which is outside the scope of the question).
Therefore you may also find this Stack Overflow post useful on how to manually and dyanmically process the GraphQL query selections, etc. and use them for dynamic queries.... https://stackoverflow.com/a/68325016/7293142
Product
Hot Chocolate
Is your feature request related to a problem?
I'm building a GraphQL api with HotChocolate.
Here is my model
SimpleModel
:Here is my table
simple_model
corresponding toSimpleModel
:As you can see there is an extra column (
column_not_in_model
) which is not map in the model. I cannot add a property in mySimpleModel
corresponding to this column because each user which will use my application should be able to add as many custom column in the database.Now the question is:
how do I map these customs columns with my model dynamically ?
I want to be able to request the data in
column_not_in_model
with a graphQl query like so:Here is my Query object:
In my Programs.cs I added the services like this:
I have already look at
Dynamic Schemas
but it doesn't seems to be what I'm looking for, sinceDynamic Schemas
allows you to modify the structure of data already mapped in the model.The solution you'd like
I don't really know what would be the best way to implement this.