aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.81k stars 819 forks source link

add-graphql-datasource : Error: Object type extension 'Query' cannot redeclare field getTodo #2797

Closed isheejong closed 4 years ago

isheejong commented 4 years ago

Note: If your question is regarding the AWS Amplify Console service, please log it in the official AWS Amplify Console forum

Which Category is your question related to? amplify api add-graphql-datasource

Amplify CLI Version sogori:amplify-aurora-test heejonglee$ amplify -v 3.17.0 sogori:amplify-aurora-test heejonglee$

What AWS Services are you utilizing?

Provide additional details e.g. code snippets

After add api which use a DynamoDB, I tried to add the data source. but it was failed below like:

// Aurora Severless cluster and DATA API was enabled. 

create table todo (
  id integer primary key,
  note varchar(20),
  done boolean
  );

sogori:amplify-aurora-test heejonglee$ amplify api add-graphql-datasource
Using datasource: Aurora Serverless, provided by: awscloudformation
? Provide the region in which your cluster is located: ap-northeast-1
? Select the Aurora Serverless cluster that will be used as the data source for your API: auroraa
✔ Fetched Aurora Serverless cluster.
? Select the database to use as the datasource: test
Successfully added the Aurora Serverless datasource locally

Some next steps:
"amplify push" will build all your local backend resources and provision it in the cloud
"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud

The following types do not have '@auth' enabled. Consider using @auth with @model
     - Todo
Learn more about @auth here: https://aws-amplify.github.io/docs/cli-toolchain/graphql#auth 

(node:5261) UnhandledPromiseRejectionWarning: Error: Object type extension 'Query' cannot redeclare field getTodo
    at TransformerContext.addObjectExtension (/Users/heejonglee/.npm-global/lib/node_modules/@aws-amplify/cli/node_modules/graphql-transformer-core/src/TransformerContext.ts:466:15)
    at TransformerContext.addQueryFields (/Users/heejonglee/.npm-global/lib/node_modules/@aws-amplify/cli/node_modules/graphql-transformer-core/src/TransformerContext.ts:390:12)
    at DynamoDBModelTransformer._this.createQueries (/Users/heejonglee/.npm-global/lib/node_modules/@aws-amplify/cli/node_modules/graphql-dynamodb-transformer/src/DynamoDBModelTransformer.ts:317:9)
    at DynamoDBModelTransformer._this.object (/Users/heejonglee/.npm-global/lib/node_modules/@aws-amplify/cli/node_modules/graphql-dynamodb-transformer/src/DynamoDBModelTransformer.ts:144:10)
    at GraphQLTransform.transformObject (/Users/heejonglee/.npm-global/lib/node_modules/@aws-amplify/cli/node_modules/graphql-transformer-core/src/GraphQLTransform.ts:317:25)
    at GraphQLTransform.transform (/Users/heejonglee/.npm-global/lib/node_modules/@aws-amplify/cli/node_modules/graphql-transformer-core/src/GraphQLTransform.ts:250:18)
    at /Users/heejonglee/.npm-global/lib/node_modules/@aws-amplify/cli/node_modules/graphql-transformer-core/src/util/amplifyUtils.ts:53:35
    at step (/Users/heejonglee/.npm-global/lib/node_modules/@aws-amplify/cli/node_modules/graphql-transformer-core/lib/util/amplifyUtils.js:44:23)
    at Object.next (/Users/heejonglee/.npm-global/lib/node_modules/@aws-amplify/cli/node_modules/graphql-transformer-core/lib/util/amplifyUtils.js:25:53)
    at fulfilled (/Users/heejonglee/.npm-global/lib/node_modules/@aws-amplify/cli/node_modules/graphql-transformer-core/lib/util/amplifyUtils.js:16:58)
(node:5261) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:5261) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
sogori:amplify-aurora-test heejonglee$
isheejong commented 4 years ago

I 'm out of idea why happen :(

nikhname commented 4 years ago

Hi @isheejong , does your existing schema already have a todo type? If so, creating a table in RDS with the same name will cause a conflict as the queries generated cannot point to both your dynamodb table and RDS tables. Try creating a table with a different name from the types in your existing schema.

nikhname commented 4 years ago

Closing due to lack of response. Please feel free to comment if you have further questions.

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

Etep15 commented 2 years ago

I ran into this issue as well and it was because my schema.graphq was not "essentially" empty. I had defined one of my types. Which is why this error was occurring as it wasn't written correct (I'm new to GraphQL).

The solution was to clear out my schema file and only have the following in it...

schema { query: Query }

Then run the amplify api add-graphql-datasource command.

This should then create the schema automatically based on the tables you have created in your RDS serverless cluster. Once the command is complete you should be able to open up amplify/backend/api/[your api name]/schema.graphql and see the automatically created GraphQL schema.

josefaidt commented 2 years ago

Thank you @Etep15 for taking the time to add your findings 🙏

re-locking conversation 🙂