Skip to content
 
 

Repository files navigation

GraphqElm

Build Status

I built this package because I wanted to have something that:

  1. Gives you type-safe GraphQL queries (if it compiles, it's valid according to the schema),
  2. Creates decoders for you in a seamless and failsafe way, and
  3. Eliminates GraphQL features in favor of Elm language constructs where possible for a simpler UX (for example, GraphQL variables & fragments should just be Elm functions, constants, lets).

See an example in action on Ellie.

See more end-to-end example code in the examples/ folder.

Usage

graphqelm generates Elm code that allows you to build up type-safe GraphQL requests. Here are the steps to setup graphqelm.

  1. Add the Graphqelm elm package as a dependency in your elm-package.json.

    elm package install dillonkearns/graphqelm
  2. Install the graphqelm command line tool through npm. This is what you will use to generate Elm code for your API. It is recommended that you save the graphqelm command line tool as a dev dependency so that everyone on your project is using the same version.

    npm install --save-dev graphqelm
    # you can now run it locally with the ./node_modules/.bin/graphqelm binary,
    # or by calling it through an npm script as in this project's package.json
  3. Run the graphqelm command line tool installed above to generate your code. If you used the --save-dev method above, you can simply create a script in your package.json like the following:

    {
      "name": "star-wars-graphqelm-project",
      "version": "1.0.0",
      "scripts": {
        "api": "graphqelm https://graphqelm.herokuapp.com/api --base StarWars"
      },
      ...
  4. With the above in your package.json, running npm run api will generate Graphqelm code for you to call in ./src/StarWars/. You can now use the generated code as in this Ellie example or in the examples folder.

By default, deprecated Fields and Enums are not included in the generated GraphqElm code. Use the --includeDeprecated flag when running the graphqelm commandline tool if you would like to include them.

Contributors

Thank you Mario Martinez (martimatix) for all your feedback and for the elm-format PR!

Thank you Mike Stock (mikeastock) for setting up Travis CI!

Roadmap

Type-safe Input Objects are planned but not yet supported. Otherwise all core functionality has been implemented. I would also like to investigate supporting subscriptions.

See the full roadmap on Trello.

About

Autogenerate type-safe GraphQL queries in Elm.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages