저는 Elm 0.18에서 graphql을 사용하려고합니다. 제가 온라인에서 찾은 라이브러리는 0.18에서 작동하지 않는 것 같습니다. 그래서 저는 제 자신을 압연하고 있습니다.Elm에서의 graphql 처리 오류 (0.18)
내가 중첩 된 쿼리를 가지고 있다고 가정 해 봅시다.
그것을 통해 가고,GetPostCompleted
에 반환
Post
유형에 따라 통과
import Http
import HttpBuilder exposing (..)
import Json.Decode as Decode exposing (..)
import Json.Encode as Encode exposing (..)
import Json.Decode.Pipeline as Pipeline exposing (decode, required)
fetchPosts : Model -> Cmd Msg
fetchPosts model =
let
graphiql =
"""
query {
postById(id: 1) {
id
author {
id
name
}
content
comments {
date
author {
id
name
}
content
}
}
}
"""
localUserDecoder =
Pipeline.decode User
|> Pipeline.required "id" Decode.int
|> Pipeline.required "name" Decode.string
localCommentDecoder =
Pipeline.decode Comment
|> Pipeline.required "date" Decode.string
|> Pipeline.required "author" localUserDecoder
|> Pipeline.required "string" Decode.string
localPostDecoder =
Pipeline.decode Post
|> Pipeline.required "id" Decode.int
|> Pipeline.required "author" localUserDecoder
|> Pipeline.required "content" Decode.string
|> Pipeline.required "comments" (Decode.list localCommentDecoder)
localDecoder =
Decode.at [ "data", "postById" ] <|
localPostDecoder
in
HttpBuilder.post ("http://myserver/api")
|> HttpBuilder.withStringBody "text/plain" graphiql
|> HttpBuilder.withExpect (Http.expectJson localDecoder)
|> HttpBuilder.send GetPostCompleted
는, 모두가 잘 : 쿼리 및 HTTP 호출을 함수는 다음과 같이 보인다. 그러나 무언가가 꺼져 있다고 가정 해보십시오. author
이 어딘가에 user
으로 잘못 표시되었거나 필드가 디코더에서 순서가 잘못되었습니다. 컴파일러는 오류를 만든 곳을 알려주지 않고 네트워크 테이블에서 올바른 쿼리를 볼 수 있지만 elm 코드에서 발생하는 설명이 아닌 오류 만 표시합니다.
구조화 방법이 없으므로 디코더 중 하나에 이상이있는 경우 콘솔에 오류가 표시 될 수 있습니까? 현재 나는 모든 것을 풀어서 조각으로 묶어야합니다. 이것은 매우 어렵고 느릅 나무 같은 것입니다.
에서 느릅 나무 디코더를 유도,하지만 난 형 시스템에 대한 불만을 들었다 수 있는지 여부입니다. 이것이 사람들이 불평하는 주요한 것입니까? –
아니요, 불만 사항은 유형 분류에 관한 것이며 불필요한 보일러 판으로 내려갑니다. 여기에서는 훨씬 더 진보 된 타입의 시스템이 필요할 것입니다 (하스켈 또는 그 이상을 생각하십시오) –