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 12306314ac4e of https://github.com/ryan-haskell/graphql (zip prefix ryannhg-graphql-7fbe1a7/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 66eaf131e08af546ac9c3e0389964d5b22063d8a.
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/2.1.0/
An elm/json inspired package for working with GraphQL
elm install ryannhg/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: