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
1 changed files with 51 additions and 29 deletions

View File

@ -106,23 +106,32 @@ type IntrospectionResult
type alias Model = type alias Model =
{ introspectUrl : String { introspectUrl : String
, introspections : OrderedDict String IntrospectionResult , introspections : OrderedDict String IntrospectionResult
, collapsedIntrospections : OrderedDict String Bool
} }
init : () -> ( Model, Cmd Msg ) init : () -> ( Model, Cmd Msg )
init _ = 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 type Msg
= UpdateIntrospectUrl String = UpdateIntrospectUrl String
| RequestIntrospection | RequestIntrospection
| IntrospectionRequest String (Result Http.Error Introspection) | IntrospectionRequest String (Result Http.Error Introspection)
| CollapseIntrospection String
| UncollapseIntrospection String
update : Msg -> Model -> ( Model, Cmd Msg ) update : Msg -> Model -> ( Model, Cmd Msg )
update msg model = update msg model =
case msg of 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 -> UpdateIntrospectUrl url ->
( { model | introspectUrl = url }, Cmd.none ) ( { model | introspectUrl = url }, Cmd.none )
@ -159,7 +168,11 @@ view model =
[] []
[ H.ul [] [ H.ul []
(List.filterMap (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 model.introspections.order
) )
] ]
@ -212,8 +225,8 @@ header model =
] ]
introspectionResultView : String -> Maybe IntrospectionResult -> Maybe (Html Msg) introspectionResultView : Bool -> String -> Maybe IntrospectionResult -> Maybe (Html Msg)
introspectionResultView url mir = introspectionResultView is_hidden url mir =
Maybe.map Maybe.map
(\ir -> (\ir ->
H.li H.li
@ -232,6 +245,9 @@ introspectionResultView url mir =
, A.title (Debug.toString mir) , A.title (Debug.toString mir)
] ]
[ H.text url ] [ 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 :: (case ir of
Loading -> Loading ->
@ -241,13 +257,19 @@ introspectionResultView url mir =
[ H.text ("Error: " ++ httpErrorToString e) ] [ H.text ("Error: " ++ httpErrorToString e) ]
Success i -> Success i ->
[ introspectionView i ] if not is_hidden then
[ introspectionView i ]
else
[ collapsedIntrospectionView i url ]
) )
) )
) )
mir mir
collapsedIntrospectionView : Introspection -> String -> Html Msg
collapsedIntrospectionView i url = H.div [ Ev.onClick (UncollapseIntrospection url) ] [ H.text "Expand" ]
introspectionView : Introspection -> Html Msg introspectionView : Introspection -> Html Msg
introspectionView i = introspectionView i =
let let
@ -273,33 +295,33 @@ introspectionView i =
sg = sg =
styleGroup [ ( "margin", "1em 0" ) ] 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 in
H.div [] H.div []
(List.filterMap [ H.div sg
identity [ H.h2 [] [ H.text ("Query Types (" ++ (Maybe.withDefault "N/A" i.queryType) ++ ")") ]
[ i.queryType , H.div (styleGroup [ ( "margin-left", "2em" ) ]) rootQueryTypes
|> 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 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 kindColor : String -> String