Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
better links to docs and example
  • Loading branch information
jamesmacaulay committed Mar 30, 2017
1 parent f550aed commit bc7d2c4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -6,7 +6,9 @@ A [GraphQL](http://graphql.org) library for [Elm](http://elm-lang.org), written

The goal of this package is to provide a really good interface for working directly with GraphQL queries and schemas in Elm. Right now the main offering of the package is an interface for building up nested queries and mutations in a way that also builds up a decoder capable of decoding successful responses to the request. The package also provides a module for sending these requests to a GraphQL server over HTTP and decoding the responses accordingly.

Here's [an end-to-end example](https://github.com/jamesmacaulay/elm-graphql/tree/master/example) that builds a query, sends it to a server, and decodes the response.
The docs can be found [here](http://package.elm-lang.org/packages/jamesmacaulay/elm-graphql/latest).

And [here's an end-to-end example](https://github.com/jamesmacaulay/elm-graphql/blob/master/example/Main.elm) that builds a query, sends it to a server, and decodes the response.

### Building requests

Expand Down
34 changes: 19 additions & 15 deletions example/Main.elm
Expand Up @@ -8,28 +8,15 @@ import GraphQL.Client.Http as GraphQLClient
import Task exposing (Task)


{-| Responses to `starWarsRequest` are decoded into this type.
-}
type alias FilmSummary =
{ title : Maybe String
, someCharacterNames : List (Maybe String)
, somePlanetNames : Maybe (List (Maybe String))
}


connectionNodes :
ValueSpec NonNull ObjectType result vars
-> ValueSpec NonNull ObjectType (List result) vars
connectionNodes spec =
extract
(field "edges"
[]
(list
(extract
(field "node" [] spec)
)
)
)


{-| The definition of `starWarsRequest` builds up a query request value that
will later be encoded into the following GraphQL query document:
Expand Down Expand Up @@ -99,6 +86,23 @@ starWarsRequest =
}


{-| A function that helps you extract node objects from paginated Relay connections.
-}
connectionNodes :
ValueSpec NonNull ObjectType result vars
-> ValueSpec NonNull ObjectType (List result) vars
connectionNodes spec =
extract
(field "edges"
[]
(list
(extract
(field "node" [] spec)
)
)
)


type alias StarWarsResponse =
Result GraphQLClient.Error FilmSummary

Expand Down

0 comments on commit bc7d2c4

Please sign in to comment.