Closed29

バックエンドを書かずにRDBでCRUDしたい

tkttkt

バックエンド書くのはめんどくさいけど、RDBは使いたくて、

tkttkt

https://github.com/tktcorporation/ateaparty-reminder/commit/14e393810a1a0e7dfd5e372860a9f54b8991844b

> docker-compose run --rm hasura init
INFO Help us improve Hasura! The cli collects anonymized usage stats which
allow us to keep improving Hasura at warp speed. To opt-out or read more,
visit https://hasura.io/docs/latest/graphql/core/guides/telemetry.html 
INFO hasura cli is up to date                      version=2.1.1
? Name of project directory ? hasura
INFO directory created. execute the following commands to continue:

  cd hasura
  hasura console 

docker 経由で hasuracli を呼び出して init

tkttkt
> docker-compose run --rm hasura
INFO Help us improve Hasura! The cli collects anonymized usage stats which
allow us to keep improving Hasura at warp speed. To opt-out or read more,
visit https://hasura.io/docs/latest/graphql/core/guides/telemetry.html 
INFO hasura cli is up to date                      version=2.1.1
ERRO connecting to graphql-engine server failed   
INFO possible reasons:                            
INFO 1) Provided root endpoint of graphql-engine server is wrong. Verify endpoint key in config.yaml or/and value of --endpoint flag 
INFO 2) Endpoint should NOT be your GraphQL API, ie endpoint is NOT https://hasura-cloud-app.io/v1/graphql it should be: https://hasura-cloud-app.io 
INFO 3) Server might be unhealthy and is not running/accepting API requests 
INFO 4) Admin secret is not correct/set           
INFO                                              
FATA[0002] making http request failed: Get "http://localhost:8080/healthz": dial tcp 127.0.0.1:8080: connect: connection refused

console しようとしたら怒られた

tkttkt

docker-compose で 設定してつながるようになった
console も起動できてるっぽい
けど、アクセスできない

tkttkt

できた。

> docker-compose run --rm --service-ports hasura
Starting ateaparty-reminder_postgres_1 ... done
Starting ateaparty-reminder_graphql-engine_1 ... done
INFO Help us improve Hasura! The cli collects anonymized usage stats which
allow us to keep improving Hasura at warp speed. To opt-out or read more,
visit https://hasura.io/docs/latest/graphql/core/guides/telemetry.html 
INFO hasura cli is up to date                      version=2.1.1
WARN Error opening browser, try to open the url manually?  error="exec: \"xdg-open\": executable file not found in $PATH"
INFO console running at: http://localhost:9695/

こんな感じに出てたから、9695 port なんだと思ってたら、実は 8080 port だった

tkttkt
ateaparty-reminder_app_1      docker-entrypoint.sh /bin/    Up                                
                              ...                                                             
ateaparty-reminder_graphql-   graphql-engine serve          Up      0.0.0.0:8080->8080/tcp,:::
engine_1                                                            8080->8080/tcp            
ateaparty-reminder_hasura_1   /hasuracli/hasura console     Up      0.0.0.0:3000->3000/tcp,:::
                                                                    3000->3000/tcp, 0.0.0.0:96
                                                                    95->9695/tcp,:::9695->9695
                                                                    /tcp                      
ateaparty-                    docker-entrypoint.sh          Up      5432/tcp                  
reminder_postgres_1           postgres                           

graphql-server のほうにアクセスするらしい

tkttkt

するとあらたに Hasura console が立ち上がります。これは Hasura を立ち上げたときに自動的に localhost:8080 にできる Hasura console とは機能が違います。便宜的に CLI を使って立ち上げた hasura console を real hasura console と呼ぶことにします。

やらないといけないのはこれだった

tkttkt

それっぽいことをやってるのは GitHub 上でも何件かあったので、できないことはないはず

tkttkt

開けるけど grqphql server につなぎに行けないとか、なかなかうまく行かない

tkttkt

どっちにしてもシンプルな手段では厳しそうな気配。一旦ローカルで動かして、暇で仕方ないときにやるかな…

tkttkt
> hasura init . --endpoint http://graphql-engine:8080
? Initialize project with metadata & migrations from http://graphql-engine:8080 ? Yes
INFO validating endpoint failed, server not reachable 
INFO hasura project initialised. execute the following command to continue:
                hasura console
           
tkt@tkt-neon ~/src/github.com/tktcorporation/ateaparty-reminder/hasura (master)> hasura console
ERRO connecting to graphql-engine server failed   
INFO possible reasons:                            
INFO 1) Provided root endpoint of graphql-engine server is wrong. Verify endpoint key in config.yaml or/and value of --endpoint flag 
INFO 2) Endpoint should NOT be your GraphQL API, ie endpoint is NOT https://hasura-cloud-app.io/v1/graphql it should be: https://hasura-cloud-app.io 
INFO 3) Server might be unhealthy and is not running/accepting API requests 
INFO 4) Admin secret is not correct/set           
INFO                                              
FATA[0001] making http request failed: Get "http://graphql-engine:8080/healthz": dial tcp: lookup graphql-engine: Temporary failure in name resolution 
tkt@tkt-neon ~/src/github.com/tktcorporation/ateaparty-reminder/hasura (master) [1]> docker-compose ps
NAME                                  COMMAND                  SERVICE             STATUS              PORTS
ateaparty-reminder-graphql-engine-1   "graphql-engine serve"   graphql-engine      exited (0)          
ateaparty-reminder-postgres-1         "docker-entrypoint.s…"   postgres            running             5432/tcp
tkt@tkt-neon ~/src/github.com/tktcorporation/ateaparty-reminder/hasura (master)> docker-compose up
[+] Running 4/0
 ⠿ Container ateaparty-reminder-tf-1              Created                                                                                                                                                 0.0s
 ⠿ Container ateaparty-reminder-app-1             Created                                                                                                                                                 0.0s
 ⠿ Container ateaparty-reminder-postgres-1        Running                                                                                                                                                 0.0s
 ⠿ Container ateaparty-reminder-graphql-engine-1  Created                                                                                                                                                 0.0s

こんなかんじでやった。
endpointの指定ははじめ間違えて http://graphql-engine:8080 指定してたけど、外から繋がれるから、 http://localhost:8080 が正解だった

tkttkt

node のgraphql client どうしようか問題
prisma 触ってみたいけど client だけ使うとかできるんだろうか

tkttkt

node のgraphql client どうしようか問題
prisma 触ってみたいけど client だけ使うとかできるんだろうか

tkttkt

graphql schema から TS の型定義やらなんやらしてほしいけど、そこまでやってくれるのが見つからない

このスクラップは2022/09/21にクローズされました