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

Ability to dynamically create GraphQL Object Types and Fields from front end #10303

Open
2 tasks
DeviNoles opened this issue Sep 8, 2022 · 2 comments
Open
2 tasks
Labels
API Related to REST API issues feature-request Request a new feature

Comments

@DeviNoles
Copy link

Is this related to a new or existing framework?

No response

Is this related to a new or existing API?

GraphQL API

Is this related to another service?

No response

Describe the feature you'd like to request

Currently my application runs using AWS Amplify with a Vue frontend. The backend uses GraphQL and models that I've manually created in Amplify Studio / in the folder 'amplify/backend/api/myAPI/schema.graphql'. The problem I've run into is that I have to manually create these models and fields.

I'm looking for a solution for my users to be able to dynamically create fields and models. If you attempt to add a field to an Amplify Dynamo request that is nonexistent in the backend environment, the Dynamo operation will fail and you will receive an error in the console. I've come up with a hacked together way of adding dynamic fields to a model.

Dynamic Field Example:
Model: Person{
id: '123',
eyecolor: 'green'
}

If I were to do a Dynamo update haircolor: 'brown', I would receive an error because the model only is 'set up' for two fields: id and eyecolor.

On the other hand, I have not found anything related to creating models dynamically, and from my conclusion, this is not a feature yet.

Example:
Company A is using my inventory management software for their warehouse. Company A acquires a fleet of new vehicles that they would like a Dynamo table / model for to keep track of their vehicles. I would have to manually create this model either in Amplify Studio or through the schema.graphql file.

Describe the solution you'd like

I'd like a way to create new field and models dynamically, instead of having to create them manually in Amplify Studio / schema.graphql file.

Describe alternatives you've considered

I have a solution for creating dynamic fields that mainly involves two functions in a Lambda that's connected to an API Gateway (Very standard in my project). These two functions are createDynamicField() and getDynamicFields()

For dynamic fields to work, I have a model in Dynamo called 'DynamicModels'. Now going back to the Person model from above which has two attributes: id and eyecolor, let's say a user wanted to add a 'haircolor' field. In this case, the createDynamicField() Lambda gets called and a new record is added in the DynamicModels table. This record contains the new dynamic field 'haircolor' and the table it is attached to ('Person').

To load these dynamic fields, I now have to call getDynamicFields() every time I query the Dynamo 'Person' model and check if there are any Dynamic Fields associated with this specific person (Ex. Was haircolor added?)

After spending today looking through some Amplify documentation and reading AmplifyBackend's and AppSync's AWS SDK pages, I could not find a way to dynamically create models. I figure this would have to rebuild my backend on the fly every time...? (Not too sure on the technical aspects behind that). Eventually, I decided to ask in the AWS Amplify Discord's #graphql channel. There, a user by the name of 'ykethan' suggested I post a feature request and here I am!

Thank you for taking the time to read this, and anything you may contribute towards this issue.

Additional context

No response

Is this something that you'd be interested in working on?

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change
@DeviNoles DeviNoles added the feature-request Request a new feature label Sep 8, 2022
@bcs-gbl
Copy link

bcs-gbl commented Oct 13, 2022

Hi,

Im looking for a solution for this for a long time..

DynamoDB search capabilities, pagination, counting are very limited.

So, I try to achive dynamic attribute creation and query with an AWSJSON data type in DynamoDB, but I forward all DynamoDB data to OpenSearch and read/query from there.

The first when I stuck after the schema modification, because there's a bug in aws templates. (AWSJSON type mapping between DynamoDB and OpenSearch)

Another problem is the "@searchable" directive that works only on whole dynamodb tables, not only on attributes.
So I have to send all data from the whole table to OpenSearch. That is an expensive operation and has got limits too (data size).

The AWSJSON type has size limits too.

The next thing I will try are the lambda resolvers placed behind attributes (behind which is another, separately maintained OpenSearch table?). Perhaps with the help of these I can retrieve and search the data, but the effectiveness of this and the possibility of searching in the aggregated data are also uncertain.

@stocaaro stocaaro added the API Related to REST API issues label Jan 10, 2023
@chrisbonifacio chrisbonifacio removed the p4 label Feb 7, 2024
@LucianViana
Copy link

I found graphql from hot chocolate that creates fields dynamically but with the change of version it no longer works so I'm trying to do it with hasura graphql which has a structure created with metadata but the tendency is to migrate to YML and it's expensive, anyway there is no option So I created a field generator and I use solidjs to render my SSR pages but I still can't use dynamo to search for fields and I will continue to use mysql.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Related to REST API issues feature-request Request a new feature
Projects
None yet
Development

No branches or pull requests

5 participants