Amplify + AppSync(graphQL) + DynamoDB로 어떤 느낌으로 리소스를 만들 수 있는지 살펴보기
Amplify + AppSync + Cognito로 읽기/쓰기 제어를 시도해 보세요.
htps : // 이 m / 부상 m1 / ms / 4868b8, 2b473, 7, c8f85
할 일
amplify측에서.
목차
1. 초기 설정
이번에는 다음이 끝난 것으로 합니다.
amplify add api
에 의한 cognito 설정 amplify push
react 및 react-amplified가 프로젝트 폴더에서 진행됩니다.amplify add auth
2. 스키마 설정
2-1.
amplify에서 생성되는 Blog example을 모티프로 하면서 아래와 같은 스키마를 작성해 보겠습니다.
schema.graphql
type Blog @model
@key (fields: ["id"])
@auth(rules: [
{ allow: owner },
{ allow: private, operations: [read] }
])
{
id: ID!
title: String!
owner: String!
updated_dt: AWSDateTime!
created_dt: AWSDateTime!
TTL: AWSTimestamp!
posts: [Post] @connection(keyName: "byBlog", fields: ["id"])
}
type Post @model
@auth(rules: [
{ allow: owner },
{ allow: private, operations: [read] }
])
@key (fields: ["id"])
@key (
name: "listByStatus",
fields: ["status", "updated_dt"],
queryField: "listPostsByStatus"
)
@key(name: "byBlog", fields: ["blogID"]) {
id: ID!
title: String!
blogID: ID!
status: String!
owner: String!
updated_dt: AWSDateTime!
created_dt: AWSDateTime!
TTL: AWSTimestamp!
blog: Blog @connection(fields: ["blogID"])
}
type Memo @model
@auth(rules: [
{ allow: owner }
])
@key (fields: ["owner", "updated_dt"]) {
id: ID!
memo: AWSJSON!
owner: String!
updated_dt: AWSDateTime!
created_dt: AWSDateTime!
TTL: AWSTimestamp!
}
npx create-react-app react-amplified
를 지정해 보았다 amplify init
에서 PK와 SK를 지정해 보았습니다.@auth
에서 GSI를 지정해 보았습니다.2-2.
그런 다음
@key
$ amplify add api
? Please select from one of the below mentioned services: GraphQL
? Provide API name: reactamplified
? Choose the default authorization type for the API Amazon Cognito User Pool
Use a Cognito user pool configured as a part of this project.
? Do you want to configure advanced settings for the GraphQL API No, I am done.
? Do you have an annotated GraphQL schema? No
? Do you want a guided schema creation? Yes
? What best describes your project: One-to-many relationship (e.g., “Blogs” with “Posts” and “Comments”)
? Do you want to edit the schema now? Yes
GraphQL schema compiled successfully.
Do you want to edit the schema now? 의 사서로 전술의 스키마를 기술합니다.
그리고
amplify push
(그렇지,? Choose the code generation language target 의 사촌으로 나온다.
푸시가 완료되면 생성된 리소스를 확인해 봅시다.
우선 AppSync 콘솔
3. AppSync 콘솔

제대로 스키마가 반영되고 있다. 과연, Blog와 Post의 관계는 이런 느낌이 될까.
그래서 이런 식으로 Mutation을 실행할 때.
AppSync 콘솔의 쿼리에서 실행할 수 있습니다.
mutation MyMutation {
createBlog(input: {title: "日記ブログログ", updated_dt: "2020-08-10T11:11:11.111Z", created_dt: "2020-08-10T11:11:11.111Z", TTL: 1572268323, owner: "testUser01"}) {
id
}
}
mutation MyMutation {
createPost(input: {title: "今日のカレー", blogID: "7998ea07-d679-4a6d-bca8-5ce6af692929", status: "ACTIVE", owner: "testUser01", created_dt: "2020-08-10T11:11:11.111Z", TTL: 1572268323, updated_dt: "2020-08-10T11:11:11.111Z"}) {
id
}
}
mutation MyMutation {
createMemo(input: {memo: "{}", owner: "testUser01", updated_dt: "2020-08-10T11:11:11.111Z", created_dt: "2020-08-10T11:11:11.111Z", TTL: 1572268323}) {
id
}
}

@key
는 명시적으로 기재하지 않는 것이 좋은 것일까. cognito의 사용자 이름을 입력했는지 모르겠습니다.그리고
amplify add api
라든지 flow
도 만들어지고 있다. 이것도 명시적으로는 만들지 않는 것이 좋을 것 같다.덧붙여 Query는 이런 느낌.
query MyQuery {
listPostsByStatus(filter: {owner: {beginsWith: "Test"}}, status: "ACTIVE", updated_dt: {ge: "2020-08-01"}) {
nextToken
items {
owner
status
title
id
created_dt
}
}
}
filter를 설정하지 않으면 뭔가 화가났다.
다음으로 DynamoDB의 정의가 어떤 느낌이 되고 있는지 확인.
덧붙여서 AppSync의 데이터 소스는 이런 느낌.

Posts 항목

owner
라고 하는 것이 만들어지고 있다.createdAt
어쨌든 now인 시간이 마음대로 들어 주는군요.Posts GSI

그래. 예상대로.
updatedAt
로 지정하면 만들어진다.별로 복잡한 일을 하지 않는다면 꽤 간단할 것 같은 인상.
5. 참고
htps : // / cs. 아 ws. 아마존. 이 m / 그럼 _ jp / 아 psy c / ㅁ st /에서 v 굉장히 / s ぁ rs. HTML
htps // d1. 아 wss c. 이 m / 그럼 _JP / s r 개 p다 y / 스도 2020 / 스 D_ 온 네 _2020_해서 ch07. pdf
이것도 잊지 않고
$ amplify delete
Reference
이 문제에 관하여(Amplify + AppSync(graphQL) + DynamoDB로 어떤 느낌으로 리소스를 만들 수 있는지 살펴보기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ikegam1/items/c0e8d4953610736fc20e텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)