8

I have been experimenting with AWS Amplify to generate a GraphQL API and backend. I can create a working backend using the guided schema creation. I chose the Todo example. I can call it from an app built in Android Studio. Queries and mutations work fine. Whenever I use Android Studio to look at the schema.graphql in amplify/backend/api/project/ (where project is the name of the project) I get errors about trying to redefine Todo and using undeclared directive @model. I am sure I am missing something obvious. So any help would be appreciated.

Android Studio 3.6.3 / Gradle 5.6.4 / Gradle Plugin 3.6.3 / JS Graph QL 2.4.0 / Java Language / Amplify CLI 4.18.1 / npm 6.14.4 / node 12.16.2

Am I just wrong trying to use this graphql plugin in this way?

To reproduce:

Create a project in Android Studio with an empty activity. From project root run:

amplify init 

Accept defaults. Run:

amplify add api

Choose GraphQL, guided schema and select the Todo example. Otherwise take the defaults. Run:

amplify push

graphql.schema in amplify/backend/api/project will contain the todo schema

type Todo @model {
...
}

Where ... is the default fields.

This produces the error

tried to use an undeclared directive "model"

And also produces 3 instances of the error

tried to redefine existing 'Todo' type

I can see that amplify has dropped the same json schema into #current-cloud-backend and the project build directory.

I accepted the default .graphqlconfig.yml file.

Quick update:

I did find I could eliminate the error by doing the following but seems like an unnecessary hack. Though if that is the correct fair enough.

  1. I edited the .yml to exclude the #current-cloud-backend copy of the schema and to exclude the build version of the schema.

  2. I manually pasted the directive SDL from the Amplify web page on directives into a graphql file and included it in the yml.

This removed the error about @model.

I also followed the advice in this article which dealt with the error about @aws_subscribe being undefined.

But I still get multiple re declaration errors in the generated schema.graphql in amplify/backend/api/project

shaedrich
  • 5,457
  • 3
  • 26
  • 42
pfield
  • 81
  • 4

1 Answers1

0

I was getting similar errors. I used the Blog/Post schema template and customized it. After running amplify push and retyping "@model", the errors went away.

DJSjr
  • 66
  • 5