ryannhg/graphql/1.0.0

NOTE: the latest version is 2.1.0

Renamed to ryan-haskell/graphql. It is published under that name, and new versions come out there.

Versions published as ryannhg/graphql still install under that name. 4 versions of 4 come from the new location (see their notes).

Rerouted (renamed, needs approval). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/ryan-haskell/graphql.

What we checked: The repo moved to github.com/ryan-haskell/graphql and tag 1.0.0 is there; its commit 8fb41eb48e93 is from 2024-03-12 23:41 UTC, after the version was published (2022-12-26 04:35 UTC); elm.json differs from package.elm-lang.org's; the exposed modules match docs.json; the zip's SHA-1 is not the published one and nothing else confirms its contents.

We could not verify this copy against what was published, so the Lamdera compiler asks before using it (y/n). Without a terminal, as in CI, it stops with an error unless approved:

  • lamdera make --auto-approve-package-rerouting approves rerouted versions for that run,
  • LAMDERA_AUTO_APPROVE_PACKAGE_REROUTING=1 does the same for every run in that environment,
  • LAMDERA_CACHE=off skips the Lamdera package server altogether: packages come from package.elm-lang.org and GitHub only, as with elm, and a rerouted version then fails to download.

Details · package.elm-lang.org's zip: https://github.com/ryannhg/graphql/zipball/1.0.0/

GraphQL.Http

Making HTTP requests

get :
{ url : String
, query : String
, variables : List ( String, Value )
, decoder : Decoder data
, onResponse : Result Error data -> msg
}
-> Cmd msg

Send an HTTP GET request to your GraphQL API

GraphQL.Http.get
    { url = "/api/graphql"
    , query = """
        query FindPerson(name: $name) {
            person(name: $name) {
                id
                name
            }
        }
    """
    , variables =
        [ ( "name", GraphQL.Encode.string "Doug" )
        ]
    , onResponse = ApiResponded
    , decoder = decoder
    }
{ url : String
, query : String
, variables : List ( String, Value )
, decoder : Decoder data
, onResponse : Result Error data -> msg
}
-> Cmd msg

Send an HTTP POST request to your GraphQL API

GraphQL.Http.post
    { url = "/api/graphql"
    , query = """
        query FindPerson(name: $name) {
            person(name: $name) {
                id
                name
            }
        }
    """
    , variables =
        [ ( "name", GraphQL.Encode.string "Doug" )
        ]
    , onResponse = ApiResponded
    , decoder = decoder
    }

Advanced usage with elm/http

The two functions below are helpful for more advanced applications using functions like Http.request.

Use these if you need to send HTTP headers, define request timeouts, etc.

import GraphQL.Http
import Http


fetchCurrentUser : Cmd Msg
fetchCurrentUser =
    Http.request
        { method = "POST"
        , url = "/api/graphql"
        , headers = []
        , body =
            GraphQL.Http.body
                { operationName = Just "FetchCurrentUser"
                , query = """
                    query FetchCurrentUser {
                        me {
                            id
                            name
                        }
                    }
                """
                , variables = []
                }
        , expect =
            GraphQL.Http.expect
                FetchCurrentUserApiResponded
                decoder
        , tracker = Nothing
        , timeout = Nothing
        }
{ operationName : Maybe String
, query : String
, variables : List ( String, Value )
}
-> Body

Create the JSON body for your GraphQL request.

GraphQL.Http.body
    { operationName = Just "FetchCurrentUser"
    , query = """
        query FetchCurrentUser {
            me {
                id
                name
            }
        }
    """
    , variables = []
    }
expect : (Result Error data -> msg) -> Decoder data -> Expect msg

Expect a JSON response from a GraphQL API.

fetchData : Cmd Msg
fetchData =
    Http.request
        { -- ... other fields
        , expect =
            GraphQL.Http.expect
                ApiResponded
                decoder
        }