How to use existing dynamo db with AWS Amplify and graphql - graphql

We have existing database in dynamodb for our application. For one of our new React app, we want to use AWS Amplify and we are trying to use the existing tables.
I created a skeleton project and went to backend AWS AppSync console -> Data Sources and map the existing table to it. And I added that table definition to my schema.graphql in my react app. When I do an amplify push, I see it creating a new table in dynamodb, rather than pointing to the existing db.
I also tried to map one of the tables in AppSync Console, and did amplify pull from local project, assuming that will add the definition of the table in my local schema.graphql but that did not happen either. It did not pull down the details of the newly mapped data source from backend app sync console.
My existing db has lot of data and is shared with other applications as well. I do not want to create a new table.
Can you pls suggest how to accomplish this?
Also we have existing lamdba functions which we would want to leverage into this new Amplify project as well. Could you pls suggest pointers for this as well.
Any help is much appreciated!

Line 22 in the file below shows how the table name is constructed when the graphql.schema transformer runs; that is - the name is derived from the GraphQLAPI ID and this seems to be a one way process.
TableName: joinWithEnv('-', [SyncResourceIDs.syncTableName, Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId')]),
https://github.com/aws-amplify/amplify-cli/blob/e1e07b245db0963c4655e646c53e7615febe2930/packages/graphql-transformer-core/src/util/syncUtils.ts
The only option then would be to try and patch the resulting CFN script.

You can use amplify import storage to import existing DynamoDB tables or S3 buckets.
more here: https://docs.amplify.aws/cli/storage/import/
Also look at
Re-use existing AppSync GraphQL API - it might help with reusing lambda functions, if they are wrapped by an API.

Related

How can I create a NestJS graphql server with dynamic schema with respect to user?

I am using Nest JS for server and new to Graphql, I want to create a graphql server but schema defines in Graphql module in app.module. I am using schema first appraoch.
app.module
in importing Graphql Module, typepaths property defines to create typings from schemas present in any path.
but I don't have any particular schema because I want my user to enter any thing he want and fetch data using Graphql where typings should be with respect to particular user.
Things I tried:
I tried to rewrite the schema using filesystem methods from service but to update typings from schema nest server needs to restart to generate typings again.
please anyone give me a guide or any approach how can I achieve dynamic typings. I want a server which shows a graphql playground but user should be allow to query with respect to their data.
like for user 1 this highlighted box can be a schema but for different user this schema should be with respect to himself:user 1 should see this schema and should query only using this schema
Related Images are attached in link.
Any guide would be appreciated, Thanks!

How to use spatie / laravel-multitenancy with single database?

I want to convert my existing app to multi-tenant and don't want to use multiple databases. just read that the given package is allowing that.
https://github.com/spatie/laravel-multitenancy
I have read the single database documentation here: https://spatie.be/docs/laravel-multitenancy/v2/installation/using-a-single-database
But what's next ??
Let's say right now users are storing into users' tables, and by using this package I want to store users tenant-specific.
I don't found the real example anywhere. so better if anyone already implemented Spatie Multi-tenant by using a single Database, please help me here.
Thanks in advance.
Although spatie/laravel-multitenancy supporting single databases, it doesn't come with query scopes (and seems like there are no plans to add them, as you can see here: https://github.com/spatie/laravel-multitenancy/issues/124), so you would need to create them manually.
So, you need to:
add the tenant_id to your tenant-specific tables
add an observer to save the tenant_id when creating a new register in the table
add a global query scope to always filter the data using the current tenant id
You can see something similar in this video: https://www.youtube.com/watch?v=nCiNqboYFVQ
The difference is that you will use the current tenant returned by spatie/laravel-multitenancy instead of the logged user id to get the tenant data.
If you want a package that already brings the query scopes ready to use, you may try Tenancy for Laravel: https://tenancyforlaravel.com/docs/v3/single-database-tenancy
Or, if your application has a very simple multi-tenancy strategy (for example, the tenant is the logged user or his team) you can just create some query scopes without the need to use packages, exactly as the video above teaches, as it is much more simple to identify the tenant by the user_id or team_id, even in terminal commands and queue jobs (but seems that is not your case, as you need the users to belongs to a tenant).
I hope it helps you to select the correct package and strategy for your project.

New Tenancy 1.x Laravel How Insert Data after create DB

I am trying to test the new version of Tenancy 1.X in laravel, but I don't understand how to insert data after creating a Tenant database
I mean in the same function
I understand that the function in charge of creating is:
Created :: class,
Someone use this version?
I'm working on that now with no less issues and unknownledge but step by step I'm resolve my requirements. What exactly are you trying to do? Insert data from tenant domain or from another, for example main app.
main app:
Tenancy::setTenant($tenant)
App\Modals\Tenant\User::create(....);
App\Modals\Tenant\User::update(....);

accessing table metadata from embedded Teiid server

I have embedded Teiid 12.3 in a Spring Boot application. I want to get into the metadata of my VDB in order to generate a diagram using graphviz-java. I assume that if I have a org.teiid.metadata.Table object, I can call getIncomingObjects() to get references to tables that table depends on. I just can't figure out how to navigate from the EmbeddedServer to the Table objects.
I looked into using the administration API available via EmbeddedServer.getAdmin(). From there, I can call getVDBs(), and from there I can navigate down to getModels(), but below that level there is only the model source via getSourceMetadataText(). I also tried subclassing EmbeddedServer to make getVDBRepository() public. I can call getVDBRepository()*.getModels(), but it returns the same Model objects only get me access to the source definition of the models, not the runtime metadata model.
I tried getVDBRepository().getSystemStore() and VDBRepository.getODBCStore(), but those MetadataStores are not for the VDB I have deployed.
I haven't found any examples by Google, Teeid JIRA, Teiid forum, or StackOverflow to help me.
Take look at [1] the getSchema method on Admin API, this method returns the string form of the metadata, however you can grab Schema object for object form. If you do not want that way, Teiid also exposes system catalog using many SYS tables, you can issue SQL queries to grab the metadata of schemas and schema items in a VDB. One for internal access, another is from external access.
BTW one of users created a dependency diagram tool that may be useful if you are trying to do something similar. See [2]. Let me know if you interested in pushing that further.
[1] https://github.com/teiid/teiid/blob/master/runtime/src/main/java/org/teiid/runtime/EmbeddedAdminImpl.java#L544-L557
[2] https://github.com/teiid/metadata-catalog-ui

How to group users together by aws-cognito attributes?

I am trying to group users of my application together under a 'Company'.
I have done this in other applications by giving the user's an account attribute/property called "company", which equals a string.
Then all data associated with that company is available to that user.
How can I do this with the AWS Amplify framework?
After some research I was able to figure this out.
In case anyone else runs into this problem...
What I was looking for was what AWS Amplify classifies as a 'Custom Resolver'. Essentially the resolver is the API logic for the GraphQL server on AWS' end.
Within your Amplify project structure there should be a folder called 'Resolvers'.
Mine was in
/backend/api/[API_NAME}/resolvers
Inside of this folder you are able to place different types of customer resolver logic for your backend.
Ideally you would place two custom files for every custom endpoint.
The two custom files would be as follows:
Query.listSomeTable.req.vtl
Query.listSomeTable.res.vtl
OR
Mutation.createSomeTable.req.vtl
Mutation.createSomeTable.res.vtl
These two files will override the resolver logic that AWS produces automatically. The files are in Apache's Velocity Engine format; '.vtl'.
You can read more about it here:
https://aws-amplify.github.io/docs/cli-toolchain/graphql#add-a-custom-resolver-that-targets-a-dynamodb-table-from-model

Resources