AmplifyConsole에서 배포하는 동안 GraphQL 스키마를 빌드 할 때 발생하는 "Unknown directive '~'"의 해결 방법

추가 (2019/6/5)



맨 아래에 상세를 기술하고 있습니다만, 무려 amplify console측이 대응해 주셨습니다!

Amplify란?



Amplify는 AWS를 사용하여 모바일 및 웹 애플리케이션을 개발하고 백엔드 구성을 제공하는 프레임워크입니다. 각종 AWS 서비스와 Frontend의 ​​연계, Backend의 간편한 구성을 가능.

구성





Frontend



Vue.js

백엔드



AWS AppSync + GraphQL + DynamoDB

환경


  • Amplify CLI == 1.7.0
  • Vue-CLI == v3.0.0

  • GraphQL Schema 정의



    schema.graphql
    type Book @model @key(fields: ["category", "title"]){
      category: String!
      title: String!
      price: Int!
    }
    
    @model 또는 @key 는 amplify 쪽 지시어
    DynamoDB의 Partition key나 Sort Key를 설정할 때에 사용되는 것이 @key 지시어.
    최초의 요소가 Partition Key, 그 다음이 Sort Key 가 된다.

    GraphQL 스키마 빌드


    $ amplify api gql-compile
    
    GraphQL schema compiled successfully.
    Edit your schema at /path/to/schema.graphql or place .graphql files 
    in a directory at /path/to/schema
    

    로컬에서는 빌드에 성공한다.

    AmplifyConsole에서 배포



    빌드 설정은 다음과 같습니다.

    amplify.yml
    version: 0.1
    backend:
      phases:
        build:
          commands:
            - '# Execute Amplify CLI with the helper script'
            - amplifyPush --simple
    frontend:
      phases:
        preBuild:
          commands:
            - yarn install
        build:
          commands:
            - yarn run build
      artifacts:
        baseDirectory: dist
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
    

    Local에서 잘 가고 있던 빌드로 닦아



    build.log
    SchemaValidationError: Schema Errors: Unknown directive "key".
    

    로그를 자세히 확인해 보면
    ## Install AWS Amplify CLI
    RUN /bin/bash -c ". ~/.nvm/nvm.sh && \
        npm install -g @aws-amplify/[email protected]"
    

    과연. . 분명히 Console 측이 install하고있는 @aws-amplify/cli의 버전이 오래된 것 같습니다.

    해결책



    amplify.yml의 빌드 설정에 추가

    amplify.yml
    ~
    backend:
      phases:
        build:
          commands:
            - '# Execute Amplify CLI with the helper script'
            - npm install -g @aws-amplify/cli   // ---------------- 追記 ----------------
            - amplifyPush --simple
    ~
    

    Frontend에서 빌드가 시작되면 문제 없지만, 연계의 사정상 Backend의 빌드가 되어 버리기 때문에 추기가 필요하게 된다.

    끝에



    이런 버전 차이에 의한 불편은 자주 있는 것이므로 맨 먼저 의심하지 않으면 안 된다고 반성.

    추가 (2019/6/5)



    GitHub에 issue 세우고 있었습니다만, 무려 하루 부족하고 대응해 주셨습니다! !
    일부러 Twitter에 리플라이를 주시는 신 대응만! 감사합니다! !

    Please try again. The new CLI is available in all regions.— Nikhil Swaminathan (@TheSwaminator) 2019년 6월 4일

    좋은 웹페이지 즐겨찾기