graphqlschemaaws-appsyncgraphql-schema

How to return ID as a key in AppSync GraphQL schema?


I need to return following object to client:

{
      id: "be49e436-1da0-463e-91fc-e53695cee00b",
      groupName: "Maintainance Workers",
      groupId: "c0fc9f0c-af0e-43d8-b896-560dc389b506",
      groupDescription: "Lorem ipsum Description",
      accessPoints: {
        "e1274504-b471-427c-a63b-dd9aba46a118": [
          "89d9ef1c-7781-498b-a2ef-e0a107ad24e9",
          "fd9fe18e-f67a-42b3-b44c-cfa264532ffd",
        ],
      },
    }

for this I created following schema:

type Group {
   groupName: String!,
   groupDescription: String!,
   id: String!,
   groupId: String!,
   accessPoints: AccessPointsByBuilding
}

type AccessPointsByBuilding {
   String: [String!]
}

I know the problem is with AccessPointsByBuilding but I am unable to find the solution of this. Any help will be appreciated. TIA.


Solution

  • Use AWSJSON type to dynamically return any JSON object.

    type UserGroup {
        userGroupName: String!,
        userGroupDescription: String!,
        siteId: String!,
        userGroupId: String!,
        accessPoints: AWSJSON
    }
    

    https://docs.aws.amazon.com/appsync/latest/devguide/scalars.html