Amplify-cli: add-graphql-datasource - aurora serverless - update fails

Created on 7 Oct 2019  Â·  10Comments  Â·  Source: aws-amplify/amplify-cli

When running amplify add-graphql-datasource to update the schema, old schema changes seem to conflict with the script:

$ amplify api add-graphql-datasource
Using datasource: Aurora Serverless, provided by: awscloudformation
? Provide the region in which your cluster is located: us-east-1
? Select the Aurora Serverless cluster that will be used as the data source for your API: champagne-glory-us-east-1
✔ Fetched Aurora Serverless cluster.
? Select the database to use as the datasource: ChampagneGlory
Error: Unable to merge GraphQL type "Users": asNext is not iterable
    at Object.mergeType (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/graphql-toolkit/src/epoxy/typedefs-mergers/type.ts:20:13)
    at nodes.reduce (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/graphql-toolkit/src/epoxy/typedefs-mergers/merge-nodes.ts:42:22)
    at Array.reduce (<anonymous>)
    at Object.mergeGraphQLNodes (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/graphql-toolkit/src/epoxy/typedefs-mergers/merge-nodes.ts:29:16)
    at mergeGraphQLTypes (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/graphql-toolkit/src/epoxy/typedefs-mergers/merge-typedefs.ts:228:40)
    at Object.mergeTypeDefs (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/graphql-toolkit/src/epoxy/typedefs-mergers/merge-typedefs.ts:93:18)
    at mergeTypes (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/merge-graphql-schemas/src/merge_types.ts:9:10)
    at datasourceSelectionPrompt.then.then.then (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-api/commands/api/add-graphql-datasource.js:116:12)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)
There was an error adding the datasource

To Reproduce

  1. Setup an aws amplify project with an aurora api backend
  2. Run amplify add-graphql-datasource
  3. Make schema changes manually (not sure if optional)
  4. Update database tables
  5. run amplify add-graphql-datasource again
  6. See error

Expected behavior
Either an updated schema, or an error message that can be solved.

Desktop (please complete the following information):

  • MacOS 10.14.6 (18G87)
  • Amplify 3.10.0
bug graphql-transformer

Most helpful comment

Because updating in that way is mentioned in the docs I have marked this as a bug. In the mean time you can try deleting the api and adding it back with the updated datasource as a work around.

All 10 comments

@raelmiu Do you have type User already in your existing schema? Are there any other type collisions in existing schema, and have a table with the same name in RDS?

Yes, the User is already in the schema. Actually there are two "User" from DynamoDB and "Users" from RDS.
Not in conflict, but that should be updated, yes?

Not in conflict, but that should be updated, yes?

Merging User would cause problems as the data is stored in 2 data stores and resolvers used for them are different. The resolver is not equipped to fetch data from 2 different data sources and merge them together.

Could you try renaming one of the types and see if you are still having the same issue.

I don't think it's an issue of Model names. But I removed all the references to Userand got this error:

Error: Unable to merge GraphQL input type "CreateUsersInput": asNext is not iterable
    at Object.mergeInputType (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/graphql-toolkit/src/epoxy/typedefs-mergers/input-type.ts:23:13)
    at nodes.reduce (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/graphql-toolkit/src/epoxy/typedefs-mergers/merge-nodes.ts:50:22)
    at Array.reduce (<anonymous>)
    at Object.mergeGraphQLNodes (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/graphql-toolkit/src/epoxy/typedefs-mergers/merge-nodes.ts:29:16)
    at mergeGraphQLTypes (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/graphql-toolkit/src/epoxy/typedefs-mergers/merge-typedefs.ts:228:40)
    at Object.mergeTypeDefs (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/graphql-toolkit/src/epoxy/typedefs-mergers/merge-typedefs.ts:93:18)
    at mergeTypes (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/merge-graphql-schemas/src/merge_types.ts:9:10)
    at datasourceSelectionPrompt.then.then.then (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-api/commands/api/add-graphql-datasource.js:116:12)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)
There was an error adding the datasource

Which is the same as the last one.

To be very clear:User was a dynamoDb entitiy, it's no longer present. Users is a RDS entitity that's still present (has it's own table etc)

@raelmiu could you provide the query you used to create this table? In particular, what is your primary key and its type?

The primary keys are char(36) on all my entities.

That explains it @nikhname , but I got the impression I should be able to update it from this article:
https://aws-amplify.github.io/docs/cli-toolchain/graphql?sdk=js#how-does-this-work

You may run add-graphql-datasource again to update your project with changes in the database but be careful as these will overwrite any existing templates in the stacks/ or resolvers/ directories.

Because updating in that way is mentioned in the docs I have marked this as a bug. In the mean time you can try deleting the api and adding it back with the updated datasource as a work around.

For posterity: Tried the workaround with deleting the API and adding a new one, worked fine.

I'm also experiencing this issue? I'm attempting to delete and retry.

I ran into the same issue when adding a new table to the same Aurora database and running amplify api add-graphql-datasource. After I deleted all the existing types and inputs from schema.graphql and all the resolvers in the resolvers directory, the command succeeded. The schemas and resolvers was then automatically regenerated, including the new table.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jexh picture jexh  Â·  3Comments

nason picture nason  Â·  3Comments

darrentarrant picture darrentarrant  Â·  3Comments

onlybakam picture onlybakam  Â·  3Comments

gabriel-wilkes picture gabriel-wilkes  Â·  3Comments