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, verified). 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. Rebuilt with git archive from commit 94c58c7b566b of https://github.com/ryan-haskell/graphql (zip prefix ryannhg-graphql-71944fc/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 17617384f65dd8b6b98a141a08288b4ae53c8ec3.
The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.
Details · package.elm-lang.org's zip: https://github.com/ryannhg/graphql/zipball/1.1.0/
In GraphQL, an "operation" represents a query or mutation.
( If you're just getting started to this package, I'd ignore this and try GraphQL.Http instead! )
This module exposes functions to make it easier to set up error reporting for
all GraphQL requests in one place. Rather than executing Cmd values directly
from the GraphQL.Http package, you can describe your GraphQL operations as data, and
handle the actual HTTP stuff in one place.
This makes it easier to work with user tokens, environment specific URLs, without needing to pass that context through for each page that uses GraphQL.
Create a new operation:
operation : Operation Data
operation =
GraphQL.Operation.new
{ name = "FetchRepos"
, query = """
query FetchRepos($first: Int!) {
repos(first: $first) {
id
name
owner
}
}
"""
, variables =
[ ( "first", GraphQL.Encode.int 25 )
]
, decoder =
GraphQL.Decode.object Data
|> GraphQL.Decode.field
{ name = "repos"
, decoder = ...
}
}Convert an operation from one type variable to another. This is especially useful when using the Effect msg type in
an Elm Land application. (Although the effect pattern can be used without the Elm Land framework!)
The map function allows us to eliminate that extra data type variable, so we can still use Effect msg as expected:
type Effect msg
= -- ...
| SendGraphQL
{ operation : GraphQL.Operation.Operation msg
, onHttpError : Http.Error -> msg
}
sendGraphQL :
{ operation : Operation data
, onResponse : Result Http.Error data -> msg
}
-> Effect msg
sendGraphQL props =
let
operation : Operation msg
operation =
GraphQL.Operation.map
(\data -> props.onResponse (Ok data))
props.operation
in
SendGraphQL
{ operation = operation
, onHttpError = \httpError -> props.onResponse (Err httpError)
}Send an HTTP request with the GraphQL operation. Below is an example of how you
can use it with Elm Land's Effect module to ensure all
GraphQL HTTP errors are reported automatically:
type Effect msg
= -- ...
| SendGraphQL
{ operation : GraphQL.Operation.Operation msg
, onHttpError : Http.Error -> msg
}
toCmd :
{ options
| effect : Effect msg
, fromSharedMsg : Shared.Msg -> msg
, batch : List msg -> msg
}
-> Cmd msg
toCmd options =
case options.effect of
-- ...
SendGraphQL { operation, onHttpError } ->
GraphQL.Operation.toHttpCmd
{ method = "POST"
, url = "https://api.github.com/graphql"
, headers =
[ Http.header "Authorization" "Bearer {...}"
]
, timeout = Just 30000
, tracker = Nothing
, operation = operation
, onResponse =
\result ->
case result of
Ok msg ->
msg
Err httpError ->
options.batch
[ onHttpError httpError
, Shared.Msg.ReportHttpError httpError
|> options.fromSharedMsg
]
}
An operation represents a GraphQL query or mutation.