This commit is contained in:
Daniel Flanagan 2020-04-03 16:58:41 -05:00
parent 6c34e829fd
commit f7c21483d7
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4

View file

@ -106,23 +106,32 @@ type IntrospectionResult
type alias Model =
{ introspectUrl : String
, introspections : OrderedDict String IntrospectionResult
, collapsedIntrospections : OrderedDict String Bool
}
init : () -> ( Model, Cmd Msg )
init _ =
( Model "https://www.graphqlhub.com/graphql" OrderedDict.empty, Cmd.none )
( Model "https://www.graphqlhub.com/graphql" OrderedDict.empty OrderedDict.empty, Cmd.none )
type Msg
= UpdateIntrospectUrl String
| RequestIntrospection
| IntrospectionRequest String (Result Http.Error Introspection)
| CollapseIntrospection String
| UncollapseIntrospection String
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
CollapseIntrospection url ->
( { model | collapsedIntrospections = OrderedDict.insert url True model.collapsedIntrospections }, Cmd.none )
UncollapseIntrospection url ->
( { model | collapsedIntrospections = OrderedDict.insert url False model.collapsedIntrospections }, Cmd.none )
UpdateIntrospectUrl url ->
( { model | introspectUrl = url }, Cmd.none )
@ -159,7 +168,11 @@ view model =
[]
[ H.ul []
(List.filterMap
(\u -> introspectionResultView u (Dict.get u model.introspections.dict))
(\u -> introspectionResultView
(Maybe.withDefault False (Dict.get u model.collapsedIntrospections.dict))
u
(Dict.get u model.introspections.dict)
)
model.introspections.order
)
]
@ -212,8 +225,8 @@ header model =
]
introspectionResultView : String -> Maybe IntrospectionResult -> Maybe (Html Msg)
introspectionResultView url mir =
introspectionResultView : Bool -> String -> Maybe IntrospectionResult -> Maybe (Html Msg)
introspectionResultView is_hidden url mir =
Maybe.map
(\ir ->
H.li
@ -232,6 +245,9 @@ introspectionResultView url mir =
, A.title (Debug.toString mir)
]
[ H.text url ]
, H.span
[ Ev.onClick ((if is_hidden then UncollapseIntrospection else CollapseIntrospection) url) ]
[ H.text (if is_hidden then "Show" else "Hide") ]
]
:: (case ir of
Loading ->
@ -241,13 +257,19 @@ introspectionResultView url mir =
[ H.text ("Error: " ++ httpErrorToString e) ]
Success i ->
[ introspectionView i ]
if not is_hidden then
[ introspectionView i ]
else
[ collapsedIntrospectionView i url ]
)
)
)
mir
collapsedIntrospectionView : Introspection -> String -> Html Msg
collapsedIntrospectionView i url = H.div [ Ev.onClick (UncollapseIntrospection url) ] [ H.text "Expand" ]
introspectionView : Introspection -> Html Msg
introspectionView i =
let
@ -273,33 +295,33 @@ introspectionView i =
sg =
styleGroup [ ( "margin", "1em 0" ) ]
rootQueryTypes = Debug.log "i.queryType" (
i.queryType
|> Maybe.andThen (\a -> Dict.get a types.dict)
|> Maybe.andThen .fields
|> Maybe.map (List.map fieldView)
|> Maybe.withDefault []
)
in
H.div []
(List.filterMap
identity
[ i.queryType
|> Maybe.andThen
(\q ->
Dict.get q types.dict
|> Maybe.andThen
(\t ->
Maybe.andThen t.fields (\f -> H.div [] (List.map fieldView f))
)
)
, H.div sg
[ H.h2 [] [ H.text "Query Fields" ]
, H.div [] (List.map typeView queryTypes)
]
, H.div sg
[ H.h2 [] [ H.text "Mutations" ]
, H.div [] (List.map typeView mutationTypes)
]
, H.div sg
[ H.h2 [] [ H.text "All Types" ]
, H.div [] (List.map typeView allTypes)
]
[ H.div sg
[ H.h2 [] [ H.text ("Query Types (" ++ (Maybe.withDefault "N/A" i.queryType) ++ ")") ]
, H.div (styleGroup [ ( "margin-left", "2em" ) ]) rootQueryTypes
]
)
, H.div sg
[ H.h2 [] [ H.text "Query Fields" ]
, H.div [] (List.map typeView queryTypes)
]
, H.div sg
[ H.h2 [] [ H.text "Mutations" ]
, H.div [] (List.map typeView mutationTypes)
]
, H.div sg
[ H.h2 [] [ H.text "All Types" ]
, H.div [] (List.map typeView allTypes)
]
]
kindColor : String -> String