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/
An elm/json inspired package for working with GraphQL
elm install ryan-haskell/graphqlWhen working with JSON data, folks in the Elm community use the elm/json package. This is a great, general purpose library for safely handling unknown JSON sent from a backend API server.
This package builds on top of elm/json, adding functions designed specifically for working with GraphQL. This means you can easily work with scalars, enums, object types, input types, interfaces, and union types within your Elm application.
Here's a quick overview of what each module does:
GraphQL.Decode - Decode JSON responses sent from a GraphQL APIGraphQL.Encode - Create JSON values to send as variables to a GraphQL APIGraphQL.Http - Send HTTP requests to a GraphQL API endpointGraphQL.Scalar.ID - Work with the built-in GraphQL ID scalarGraphQL.Operation - Like GraphQL.Http, but allows you to handle Cmd values in one placeGraphQL.Error - Work with GraphQL validation errorsIn the official GraphQL documentation, they begin their guide with a sample query that uses the Star Wars GraphQL API.
This is an example that shows how to use this package to create an HTTP request for use in your Elm application:
import GraphQL.Decode exposing (Decoder)
import GraphQL.Encode
import GraphQL.Http
type Msg
= ApiResponded (Result GraphQL.Http.Error Data)
-- Sending a GraphQL query
findHero : String -> Cmd Msg
findHero heroId =
GraphQL.Http.get
{ url = "/graphql"
, query = """
query FindHero($id: ID!) {
hero(id: $id) {
name
appearsIn
}
}
"""
, variables =
[ ( "id", GraphQL.Encode.string heroId )
]
, onResponse = ApiResponded
, decoder = decoder
}
-- Defining a GraphQL Decoder
type alias Data =
{ hero : Maybe Hero
}
decoder : Decoder Data
decoder =
GraphQL.Decode.object Data
|> GraphQL.Decode.field
{ name = "hero"
, decoder = GraphQL.Decode.maybe heroDecoder
}
type alias Hero =
{ name : String
, appearsIn : List Episode
}
heroDecoder : Decoder Hero
heroDecoder =
GraphQL.Decode.object Hero
|> GraphQL.Decode.field
{ name = "name"
, decoder = GraphQL.Decode.string
}
|> GraphQL.Decode.field
{ name = "appearsIn"
, decoder = GraphQL.Decode.list episodeDecoder
}
type Episode
= NewHope
| EmpireStrikesBack
| ReturnOfTheJedi
episodeDecoder : Decoder Episode
episodeDecoder =
GraphQL.Decode.enum
[ ( "NEWHOPE", NewHope )
, ( "EMPIRE", EmpireStrikesBack )
, ( "JEDI", ReturnOfTheJedi )
]When you send this HTTP request, using a function like GraphQL.Http.post, the GraphQL API server will receive the following request:
// POST /graphql
{
"query": "query FindHero($id: Id!) { ... }",
"variables": {
"id": "1"
}
}When the API responds with a JSON payload, your decoder will convert the raw JSON into Elm values you can use in your application:
// The JSON sent from the API:
{
"data": {
"hero": {
"name": "R2-D2",
"appearsIn": [
"NEWHOPE",
"EMPIRE",
"JEDI"
]
}
}
}-- The JSON decoded into an Elm value
data ==
{ hero =
Just
{ name = "R2-D2"
, appearsIn =
[ NewHope
, EmpireStrikesBack
, ReturnOfTheJedi
]
}
}This Elm package is for making GraphQL requests without any code generation or build tools.
If you'd like to use code generation to keep your backend GraphQL schema in-sync with your Elm application, there are some great tools that include an NPM CLI to generate that code for you: