byyoungjin / myblog-next

https://log.byyoung.me
0 stars 1 forks source link

DB 연결작업 #10

Closed byyoungjin closed 3 years ago

byyoungjin commented 3 years ago
byyoungjin commented 3 years ago

issue1 : JSX element type Elem does not have any construct or call signatures

https://stackoverflow.com/questions/31815633/what-does-the-error-jsx-element-type-does-not-have-any-construct-or-call

byyoungjin commented 3 years ago

Advanced amplify data access pattern
https://www.youtube.com/watch?v=VG2XWoD-rS0

byyoungjin commented 3 years ago

issue2 : amplify api sort 하기

1. amplify api 에서 사용하는 dinamoDB 는 list에 대한 sort 기능이 기본적으로 제공되진 않는다.

  1. global secondary index 를 사용해야한다. global secondary index 를 만들면 -> sortDirection 을 사용할 수 있다. https://stackoverflow.com/questions/56488192/how-to-sort-on-a-field-in-list-query-in-aws-amplify https://medium.com/swlh/how-to-sort-query-results-with-graphql-and-aws-appsync-80b3233ec0a1

  2. hashKey 없이 전체 table 을 sort 하는 방법은 아직없다. 그래서 전체 테이블을 sort 하려면, 특정 키(보통 baseType) 를 테이블 전반적으로 동일하게 설정하고, hashKey 로 넣는다. 그리고 sortKey 를 넣어야 sort 가 가능하다. aws-amplify/amplify-category-api#298

위 baseType 의 경우, graphql-default-value-transformer 를 통해서 default 값 적용

byyoungjin commented 3 years ago

key update 하는법

GSI 로설정된 키는 바로 수정이 안된다. 그래서 다음과 같이 몇가지 방법을 시도해봤다.

1. 한번에 바꾸려고 해봄 -> not work

  1. amplify status -> no chage 확인
  2. 기존키 이름을 바꾼다. (기존키-legacy)
  3. 새로운키를 만들고 기존키 이름으로 지정한다. 수정할사항을 수정한다. (기존 로직에 반하는 것이 없는지 확인한다.)
  4. amplify push
  5. 기존키-legacy 키를 지운다.
  6. amplify push

    2. 두번에 나눔 -> not work

  7. 기존키 이름을 바꾼다. (기존키-legacy)
  8. amplify push -> key 를 동시에 delete, add 하는걸로 인식, error

3. 새로운키를 전혀 다른이름으로설정한다. -> work!

  1. 새로운 키를 새로운 이름으로 만들고, connection을 새로운 키와 체결한다.
  2. amplify push
  3. 기존키를 삭제한다.
  4. amplify push
byyoungjin commented 3 years ago

사진 업로드

  1. 올릴때는 그냥 data url 로올림, 올릴때 부터 바로 S3 업로드.
  2. publish 할때, image. 생성, postImage mapping https://docs.amplify.aws/lib/storage/upload/q/platform/js#browser-uploads
  3. images S3 url 을 generalImages field 에 array 로 저장한다.
    1. field 로 할지, 새로 table 을 만들지 생각해보자 -> table 로 한다.
  4. edit할때, 지워진 image 는 s3에서 삭제하고, 추가된 image 만 s3 에 업로드한다. (tag 처럼)
byyoungjin commented 3 years ago

issue : S3 upload 403 error

image

amplify storage update 를 통해서 auth 권한수정 image

parameter.json 을 보면 다음과 같이 수정이 되었다. image

그래도 여전히 안됨 아마 S3 상에서 policy 수정해서 access 권한을 줘야하는듯 하다. https://github.com/aws-amplify/amplify-js/issues/5729#issuecomment-690314737

iam role 을 통해서 권한부여 image

byyoungjin commented 3 years ago

issue: image forced to download

https://stackoverflow.com/questions/14150854/aws-s3-display-file-inline-instead-of-force-download

contentType 지정해줌으로 해결

byyoungjin commented 3 years ago

tag ,image 로직

byyoungjin commented 3 years ago

rollback 은 어떻게?

여러 transaction 을 묶어서 하나라도 실패하면 rollback 어떻게? ->resolver 를 생성?

TransctWriteItems 를 제공한다. https://aws.amazon.com/blogs/mobile/appsync-caching-transactions/

cache 관련내용인데, 참고할만한듯 https://docs.amplify.aws/lib/graphqlapi/advanced-workflows/q/platform/js#delta-sync

이거도 한번 보자 https://www.youtube.com/watch?v=QEMfnr5MO1w