Edit schema

Upon creating your AppSync API, one of the first tasks recommended on the welcome page is to edit your schema. Go ahead and do that by clicking Edit schema.

Edit the AppSync GraphQL schema

You will be taken to an editing form. Highlight the existing content in the textarea, paste the following GraphQL schema over it, then click Save Schema.

type Mutation {
  createProduct(id: ID!): Product
    @aws_auth(cognito_groups: ["default"])
  updateProductState(id: ID!, transition: String!): Product
    @aws_auth(cognito_groups: ["default"])

type Product {
  id: ID!
  state: String!
  history: ProductHistory!

type ProductHistory {
  manufactured: String!
  inspected: String
  shipped: String
  stocked: String
  labeled: String
  sold: String

type Query {
  product(id: ID!): Product
    @aws_auth(cognito_groups: ["default"])
  products: [Product]
    @aws_auth(cognito_groups: ["default"])

type Subscription {
  createdProduct: Product
    @aws_subscribe(mutations: ["createProduct"])
    @aws_auth(cognito_groups: ["default"])
  updatedProductState: Product
    @aws_subscribe(mutations: ["updateProductState"])
    @aws_auth(cognito_groups: ["default"])

schema {
  query: Query
  mutation: Mutation
  subscription: Subscription

This schema defines two types of queries that can be run in our blockchain network: one to get a list of all the products that have been created in the system, and one to retrieve information about a single product. It also defines mutations that can be executed. These are operations that are intended to alter the state of the data source. The two supported mutations are createProduct and updateProductState. The types of data that products contain is also defined. Lastly, the schema defines subscriptions that can be used to receive notifications when something changes in the data source. Access to these queries, mutations and subscriptions will be managed by AppSync using the Cognito user pool we created in a previous step. The @aws_auth directive in the schema designates that users can only access these resources if they are authenticated and belong to the default group within the user pool.