harmboschloo / graphql-to-elm-package / GraphQL.Http.Basic

Some basic helper functions for creating GraphQL http requests.

getQuery : String -> GraphQL.Operation.Operation GraphQL.Operation.Query e a -> Http.Request (GraphQL.Response.Response e a)

getQuery url operation =
    Http.get
        (UrlHelper.withParameters url <| Operation.encodeParameters operation)
        (Response.decoder operation)

For `UrlHelper` see `GraphQL.Helpers.Url`.

postQuery : String -> GraphQL.Operation.Operation GraphQL.Operation.Query e a -> Http.Request (GraphQL.Response.Response e a)

postQuery url query =
    Http.post
        url
        (Http.jsonBody <| Operation.encode query)
        (Response.decoder query)

postMutation : String -> GraphQL.Operation.Operation GraphQL.Operation.Mutation e a -> Http.Request (GraphQL.Response.Response e a)

postMutation url mutation =
    Http.post
        url
        (Http.jsonBody <| Operation.encode mutation)
        (Response.decoder mutation)

postBatch : String -> GraphQL.Batch.Batch e a -> Http.Request (Result e a)

postBatch url batch =
    Http.post
        url
        (Http.jsonBody <| Batch.encode batch)
        (Batch.decoder batch)

postPlainBatch : String -> GraphQL.PlainBatch.Batch a -> Http.Request a

postPlainBatch url batch =
    Http.post
        url
        (Http.jsonBody <| PlainBatch.encode batch)
        (PlainBatch.decoder batch)