All Projects → ghivert → elm-graphql

ghivert / elm-graphql

Licence: MIT license
GraphQL made easy in Elm!

Programming Languages

elm
856 projects

Projects that are alternatives of or similar to elm-graphql

Neuron
A GraphQL client for Elixir
Stars: ✭ 244 (+335.71%)
Mutual labels:  graphql-client
vue-gql
A small and fast GraphQL client for Vue.js
Stars: ✭ 32 (-42.86%)
Mutual labels:  graphql-client
kobby
Kobby is a codegen plugin of Kotlin DSL Client by GraphQL schema. The generated DSL supports execution of complex GraphQL queries, mutation and subscriptions in Kotlin with syntax similar to native GraphQL syntax.
Stars: ✭ 52 (-7.14%)
Mutual labels:  graphql-client
DotNetGraphQL
A sample demonstrating how to create a GraphQL Backend in .NET and consume it from a .NET mobile app created using Xamarin
Stars: ✭ 78 (+39.29%)
Mutual labels:  graphql-client
flutter-graphql
A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package. Built after react apollo
Stars: ✭ 45 (-19.64%)
Mutual labels:  graphql-client
showcase
A Full Stack Journey with Micro Services and Micro Front Ends. Using dapr, kubernetes, react module federation and web assembly,
Stars: ✭ 45 (-19.64%)
Mutual labels:  graphql-client
Aws Mobile Appsync Sdk Ios
iOS SDK for AWS AppSync.
Stars: ✭ 231 (+312.5%)
Mutual labels:  graphql-client
neo4j-graphql-java
Pure JVM translation for GraphQL queries and mutations to Neo4j's Cypher
Stars: ✭ 94 (+67.86%)
Mutual labels:  graphql-client
galoy-pay
A web application that can be used to send tips or payments to users
Stars: ✭ 21 (-62.5%)
Mutual labels:  graphql-client
python-graphql-client
Simple module for making requests to a graphQL server in python.
Stars: ✭ 65 (+16.07%)
Mutual labels:  graphql-client
gatsby-starter-redux-saas
An Gatsby starter for Saas products. Uses redux and apollo and a graphql token auth backend.
Stars: ✭ 18 (-67.86%)
Mutual labels:  graphql-client
StarWars
Minimal GraphQL based Jetpack Compose, Wear Compose and SwiftUI Kotlin Multiplatform sample (using StarWars endpoint - https://graphql.org/swapi-graphql)
Stars: ✭ 165 (+194.64%)
Mutual labels:  graphql-client
protoc-gen-twirpql
Generate A GraphQL Layer from A Twirp Server: https://twirpql.dev
Stars: ✭ 49 (-12.5%)
Mutual labels:  graphql-client
Apollo Android
🤖  A strongly-typed, caching GraphQL client for the JVM, Android, and Kotlin multiplatform.
Stars: ✭ 2,949 (+5166.07%)
Mutual labels:  graphql-client
aws-mobile-appsync-sdk-android
Android SDK for AWS AppSync.
Stars: ✭ 101 (+80.36%)
Mutual labels:  graphql-client
Productivity Frontend
Productivity Application - Kanban Style Productivity Management Application with Customizable Boards, Lists and Cards to Make You More Productive.
Stars: ✭ 234 (+317.86%)
Mutual labels:  graphql-client
character-overlay
Web App for adding an OBS overlay with character information such as name, picture, and health for your favorite role-playing game.
Stars: ✭ 17 (-69.64%)
Mutual labels:  graphql-client
py-graphql-client
Dead-simple GraphQL client with subscriptions over websockets
Stars: ✭ 36 (-35.71%)
Mutual labels:  graphql-client
LiveGQL
Use GraphQL Subscriptions on iOS 👌
Stars: ✭ 84 (+50%)
Mutual labels:  graphql-client
nim-graphql
Nim implementation of GraphQL with sugar and steroids
Stars: ✭ 47 (-16.07%)
Mutual labels:  graphql-client

Elm GraphQL

Opinion

Just import GraphQL, and write queries and mutations! This package suppose your decoders are already written and do not write decoders, or that you want to keep control on the data received by GraphQL response. It only provides a nice syntax to do GraphQL queries and mutations, and decode the "data" at the root of standard GraphQL response for you as long as you use the HTTP wrapper. Just think on your schema, and don't bother with everything else. By not writing custom decoders, you can make multiple queries on the same data, with different schemas each times. They will always be converted to the same type, avoiding you to rewrote a type for each request like others can do. Moreover, it is purely written in Elm, avoiding you to think to recompile .graphql files.

How to use?

Basically, creates an object with object, add some fields with a list of field, and you're done! You can add some arguments, selectors or alias to the fields, by using the corresponding functions. The type system is here to protect you from doing anything crazy, so relax and enjoy GraphQL!

Otherwise, a (huge) example:

Main.elm

module Main exposing (..)

import Json.Encode as Encode
import Json.Decode as Decode exposing (Decoder, field, maybe, int, string)
import Http exposing (Error)
import GraphQl exposing (Operation, Variables, Query, Named)

type Msg
  = GraphQlMsg (Result Error NameAndAddress)

type alias User =
  { id : Maybe Int
  , name : Maybe Name
  }

type alias Name =
  { firstName : Maybe String
  , lastName : Maybe String
  }

type alias Address =
  { street : Maybe String
  , town : Maybe String
  }

type alias NameAndAddress =
  { user : User
  , address : Address
  }

decodeName : Decoder Name
decodeName =
  Decode.map2 Name
    (maybe (field "first_name" string))
    (maybe (field "last_name" string))

decodeUser : Decoder User
decodeUser =
  Decode.map2 User
    (maybe (field "id" int))
    (maybe (field "name" decodeName))

decodeAddress : Decoder Address
decodeAddress =
  Decode.map2 Address
    (maybe (field "street" string))
    (maybe (field "town" string))

decodeNameAndAddress : Decoder NameAndAddress
decodeNameAndAddress =
  Decode.map2 NameAndAddress
    (field "user" decodeUser)
    (field "address" decodeAddress)


userRequest : Operation Query Variables
userRequest =
  GraphQl.named "MySuperQuery"
    [ GraphQl.field "user"
      |> GraphQl.withArgument "id" (GraphQl.variable "id")
      |> GraphQl.withAlias "current_user"
      |> GraphQl.withSelectors
        [ GraphQl.field "id"
        , GraphQl.field "name"
          |> GraphQl.withSelectors
            [ GraphQl.field "first_name"
            , GraphQl.field "last_name"
            ]
        ]
    , GraphQl.field "address"
      |> GraphQl.withArgument "city" (GraphQl.string "Paris")
      |> GraphQl.withArgument "id" (GraphQl.int 12)
      |> GraphQl.withArgument "type" (GraphQl.type_ "LOFT")
      |> GraphQl.withSelectors
        [ GraphQl.field "street"
        , GraphQl.field "town"
        ]
    ]
    |> GraphQl.withVariables [ ("id", "123") ]

sendRequest : Int -> Cmd Msg
sendRequest id =
  GraphQl.query userRequest
  |> GraphQl.addVariables [ ("id", Encode.int id) ]
  |> GraphQl.send "https://example.com" GraphQlMsg decodeNameAndAddress

Want to contribute?

If you think this package is good, or if you want to bugfix something, or just globally improve the package, feel free to contribute. Make a PR, open an issue, and I will gladly work on it to make it part of elm-graphql!

Alternatives

If you're searching a complete solution including Decoders implicitly defined with your query, take a look at Elm GraphQL by Dillon Kearns or maybe Elm GraphQL in Elm, and if you're searching for converting .graphql files to Elm, take a look at GraphQL to Elm!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].