amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

amplify/backend/api/myproject/schema.graphql - single source of truth?

Open t0t07 opened this issue 7 years ago • 5 comments

** Which Category is your question related to? ** AppSync

** What AWS Services are you utilizing? ** AppSync

** Provide additional details e.g. code snippets ** In amplify/backend/api/myproject/schema.graphql, I define such a type with GraphQL transformer:

type Item @model {
  id: ID!
  createdAt: AWSDateTime
  content: String!
}

In this way, I am able to access createdAt attribute of the item, as it will be filled by server end as suggested in https://github.com/aws-amplify/amplify-cli/issues/401.

However, I want to remove createdAt from CreateItemInput and UpdateItemInput, that are auto-generated according to codegen - flow 2.

input CreateItemInput {
  id: ID
  createdAt: AWSDateTime
  content: String
}

input UpdateItemInput {
  id: ID!
  createdAt: AWSDateTime
  content: String
}

My questions:

  1. Can I do it on appsync console Schema and somehow "pull" it?
  2. Can I do it with myproject/build/schema.graphql and somehow "push" it?
  3. Or myproject/schema.graphql is the single source of truth and there is no way to manually tune the transformed schema AND generated resolvers?

t0t07 avatar Dec 21 '18 15:12 t0t07

For question 3, currently, there is no way to sync generated resolver code (e.g., amplify/backend/api/myproject/build/resolvers/Mutation.createItem.request) with resolver in AppSync console. Edit resolver on AppSync console directly. #30 If you really want to pull change from AppSync console, read this twitter thread

t0t07 avatar Dec 22 '18 04:12 t0t07

@YikSanChan

  1. Currently, there's not a clean way to pull your changes from the console, but yes you can follow the methodology mentioned in the twitter thread mentioned above in which case you would no longer be able to manage your API through the CLI (using the annotated schema) and you would have to rely on the console to make all your changes.

  2. I'll let @mikeparisstuff answer that, but i beleive you can do so

  3. You can use the amplify push —no-gql-override command to manually modify your generated resolvers and then push it. Note: this command basically would not automatically compile the annotated graphql schema and override the resolvers.

kaustavghosh06 avatar Jan 07 '19 18:01 kaustavghosh06

@kaustavghosh06 From https://github.com/aws-amplify/amplify-cli

The 'no-gql-override' flag does not automatically compile your annotated GraphQL schema and will override your local AppSync resolvers and templates.

But I don't fully understand what it does based on the documentation. "...will override your local AppSync resolvers and templates", what is local AppSync resolvers? Does it mean: we can modify resolver files locally (under /amplify/backend?) and push the change to AppSync console?

t0t07 avatar Jan 07 '19 21:01 t0t07

But isn't that meaning that everytime you update the api, you can't let the cli do the transform for you (since it will modify your previous choices), or let the cli do the transform and edit back the previous changes?

gitzhouxinyu1 avatar Jun 12 '19 05:06 gitzhouxinyu1

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.

github-actions[bot] avatar May 27 '21 07:05 github-actions[bot]