Amplify-cli: How to rebuild graphql schema?

Created on 2 Oct 2018  ·  24Comments  ·  Source: aws-amplify/amplify-cli

Which Category is your question related to?
API
What AWS Services are you utilizing?
AppSync
Provide additional details e.g. code snippets
OS: OS X 10.13.4

Reproduction steps:

  1. Run amplify add api with the following options
    ? Please select from one of the below mentioned services GraphQL
    ? Provide API name: squadhealthcheck
    ? Choose an authorization type for the API: API key
    ? Do you have an annotated GraphQL schema: No
    ? Do you want a guided schema creation: true
    ? What best describes your project: One-to-many relationship (e.g., “Blogs” with “Posts” and “Comments”)
    ? Do you want to edit the schema now: No
  2. Update amplify/backend/api/schema.graphql
  3. Run amplify push

Current result
Both GraphQL queries, mutations, subscriptions, and DynamoDB tables are created for the default schema (before changes)
The files inside amplify/backend/api/build/ are not updated as well.

Expected result
Both GraphQL and DynamoDB are setup according to the updated schema from the file amplify/backend/api/schema.graphql

bug question

Most helpful comment

You can try using the ‘amplify api gql-compile’ command?

All 24 comments

If you want to update the graphql schema, you can edit amplify/backend/api/schema.graphql and run amplify api push command. This should update the DynamoDB tables and graphql statements.

Please fell free to re-open the issue if you're still facing problems when updating the schema or need more clarification.

As you can see in my reproduction steps, I do it. And it doesn't work.

I inspected the code and noticed, that probably compile schema from amplify-provider-cloudformation/lib/utility-functions.js would do the trick with compliling graphQL schema.

I've also found out, compile schema method should be runned when I run amplify api configure command. So I did it, and I got an error:

? Please select from one of the below mentioned services: GraphQL
The selected resource is not managed using AWS Cloudformation. Please use the AWS AppSync Console to make updates to your API - squadhealthcheck
Error: Error updating resource
    at updateWalkthrough (/Users/oskarkaminski/.nvm/versions/node/v9.8.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-api/provider-utils/awscloudformation/service-walkthroughs/appSync-walkthrough.js:211:13)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:118:7)
There was an error updating the API resource

@yuth I can't reopen the issue...

You can try using the ‘amplify api gql-compile’ command?

@kaustavghosh06 I've tried amplify api gql-compile as well. It doesn't do anything. No output in the terminal. Also no change in the files.

The issue lays in the
amplify-category-api/provider-utils/awscloudformation/service-walkthroughs/appSync-walktrough.js
In the 208 line the conditional statement resource.provider !== providerName is true.
providerName has value awscloudformation, while resource.provider has value squadhealthcheck which is the value I provided as an API name.
Any ideas why?

@OskarKaminski I've root caused the issue. Sending a fix for it ASAP (within the next few hours). in the meanwhile to unblock yourself you could use the CLI version 0.1.24 to compile your schema.

Thanks a lot @kaustavghosh06

@OskarKaminski Just published the fix to NPM. Please install the latest version -> 0.1.27

Thanks @kaustavghosh06. The fix solved the issue. amplify api gql-compile compiles the schema, and print out the info to the console. I guess amplify api push will compile now as well.
Great job!

@yuth - I guess this issue still exists! After editing amplify/backend/api/schema.graphql and running amplify api push command nothing happends and there are changes in the schema in the aws AppSync console.

amplify --version: 0.1.35

the issue still exists in amplify version 0.1.35

@mkaschke @jtaylor1989 can you confirm that amplify ls show api has provider plugin as awscloudformation?
Refer #565 for details.

@YikSanChan - it shows the same table as the status table. About the issue: After I deleted the whole stack in aws cloudformation and start from amplify init, add API ... the push works but I don't know why.

@YikSanChan - it shows the same table as the status table.

Could you paste the output of the table (by chance if you have it)

Currently having the same issue. Any fixes for this?

gql-compile is not working, amplify api update not working, no tables are updated in dynamo...very frustrating. amplify api will not update, just stopped working.

I guess the bug might still be there

Just want to say that "amplify push" works for me today. I edited schema.graphql file and saw that the changes are reflected in AppSync Console.

I've made updates to amplify/backend/api/schema.graphql. Issuing amplify push results in 'No changes detected'. Running amplify api gql-compile resets the file to how it was before my changes. This is with amplify -v 4.13.2

If I issue amplify ls, it detects the changes to Api. but if I issue amplify push, it seems to first pull, overrides my changes, and then tries to push, resulting in no changes?

tuuli@battlestation ~/community :create-action-from-preview# amplify ls

Current Environment: tuuuli

| Category | Resource name              | Operation | Provider plugin   |
| -------- | -------------------------- | --------- | ----------------- |
| Api      | community                  | Update    | awscloudformation |
| Auth     | communityaf1e375e          | No Change | awscloudformation |
| Function | communityDDBStreamFunction | No Change | awscloudformation |
| Function | S3Trigger4f37926d          | No Change | awscloudformation |
| Storage  | communityPetitionImages    | No Change | awscloudformation |


tuuli@battlestation ~/community :create-action-from-preview# amplify push
✔ Successfully pulled backend environment tuuuli from the cloud.

Current Environment: tuuuli

| Category | Resource name              | Operation | Provider plugin   |
| -------- | -------------------------- | --------- | ----------------- |
| Auth     | communityaf1e375e          | No Change | awscloudformation |
| Api      | community                  | No Change | awscloudformation |
| Function | communityDDBStreamFunction | No Change | awscloudformation |
| Function | S3Trigger4f37926d          | No Change | awscloudformation |
| Storage  | communityPetitionImages    | No Change | awscloudformation |

No changes detected

@Tuuleh I had the same issue. Just make sure you're making changes in /backend/api/schema.graphql and not /#current-cloud-backend/api/schema.graphql

@WarrenMT I was modifying /backend/api/schema.graphql and don't quite recall how I resolved this in the end. I might have abandoned that environment and used a different one.

I am also experiencing this issue. I.e. having created a graphql API...

I then go in to change the schema, and run amplify api gql-compile

D:\Josh\Documents\Projects...>amplify api gql-compile
Scanning for plugins...
Plugin scan successful

GraphQL schema compiled successfully.

Edit your schema at D:\Josh\Documents\Projects...schema.graphql or place .graphql files in a
directory at D:\Josh\Documents\Projects...

I can see the file changes,

D:\Josh\Documents\Projects...>git status
On branch db-integration
Your branch is up-to-date with 'origin/db-integration'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   amplify/backend/api/showcallDatastore/parameters.json
        modified:   amplify/backend/api/showcallDatastore/schema.graphql
        modified:   amplify/backend/api/showcallDatastore/stacks/CustomResources.json
        modified:   amplify/backend/api/showcallDatastore/transform.conf.json
        modified:   amplify/backend/auth/showcall64896de3/parameters.json
        modified:   amplify/backend/auth/showcall64896de3/showcall64896de3-cloudformation-template.yml
        modified:   amplify/backend/auth/userPoolGroups/parameters.json
        modified:   amplify/backend/auth/userPoolGroups/template.json
        modified:   amplify/backend/auth/userPoolGroups/user-pool-group-precedence.json
        modified:   amplify/backend/backend-config.json
        modified:   amplify/backend/function/showcall64896de3PostConfirmation/amplify.state
        modified:   amplify/backend/function/showcall64896de3PostConfirmation/function-parameters.json
        modified:   amplify/backend/function/showcall64896de3PostConfirmation/showcall64896de3PostConfirmation-cloudformation-template.json
        modified:   amplify/backend/function/showcall64896de3PostConfirmation/src/add-to-group.js
        modified:   amplify/backend/function/showcall64896de3PostConfirmation/src/event.json
        modified:   amplify/backend/function/showcall64896de3PostConfirmation/src/index.js
        modified:   amplify/backend/function/showcall64896de3PostConfirmation/src/package-lock.json
        modified:   amplify/backend/function/showcall64896de3PostConfirmation/src/package.json
        modified:   amplify/team-provider-info.json

no changes added to commit (use "git add" and/or "git commit -a")

but when I go to push changes, amplify says there are none!

D:\Josh\Documents\Projects...>amplify api push

Current Environment: dev

| Category | Resource name     | Operation | Provider plugin   |
| -------- | ----------------- | --------- | ----------------- |
| Api      | showcallDatastore | No Change | awscloudformation |

No changes detected

D:\Josh\Documents\Projects...>amplify status

Current Environment: dev

| Category | Resource name                    | Operation | Provider plugin   |
| -------- | -------------------------------- | --------- | ----------------- |
| Function | showcall64896de3PostConfirmation | No Change | awscloudformation |
| Auth     | showcall64896de3                 | No Change | awscloudformation |
| Auth     | userPoolGroups                   | No Change | awscloudformation |
| Api      | showcallDatastore                | No Change | awscloudformation |

I have amplify v4.18.1

Update

I have since tried again, only this time I began with amplify pull, then added my change to schema.graphql, and now see my resource show up on amplify status:

D:\Josh\Documents\Projects...>amplify status

Current Environment: dev

| Category | Resource name                    | Operation | Provider plugin   |
| -------- | -------------------------------- | --------- | ----------------- |
| Api      | showcallDatastore                | Update    | awscloudformation |
| Function | showcall64896de3PostConfirmation | No Change | awscloudformation |
| Auth     | showcall64896de3                 | No Change | awscloudformation |
| Auth     | userPoolGroups                   | No Change | awscloudformation |

Weird!

Thanks @kaustavghosh06. The fix solved the issue. amplify api gql-compile compiles the schema, and print out the info to the console. I guess amplify api push will compile now as well.
Great job!

this worked perfect thank you.

amplify api gql-compile and amplify push works fine for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davo301 picture davo301  ·  3Comments

kstro21 picture kstro21  ·  3Comments

onlybakam picture onlybakam  ·  3Comments

nason picture nason  ·  3Comments

ReidWeb picture ReidWeb  ·  3Comments