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 821 forks source link

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

Closed YikSanChan closed 5 years ago

YikSanChan commented 5 years ago

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?
YikSanChan commented 5 years ago

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

kaustavghosh06 commented 5 years ago

@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.

YikSanChan commented 5 years ago

@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?

gitzhouxinyu1 commented 5 years ago

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?

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.