{"id":22062721,"url":"https://github.com/ryan-haskell/graphql","last_synced_at":"2025-12-11T20:53:14.449Z","repository":{"id":65119783,"uuid":"582205021","full_name":"ryan-haskell/graphql","owner":"ryan-haskell","description":"An elm/json inspired package for working with GraphQL","archived":false,"fork":false,"pushed_at":"2024-03-12T23:42:36.000Z","size":1866,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-27T09:29:34.179Z","etag":null,"topics":["elm","graphql","package"],"latest_commit_sha":null,"homepage":"https://package.elm-lang.org/packages/ryan-haskell/graphql/latest","language":"Elm","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ryan-haskell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-12-26T04:34:05.000Z","updated_at":"2024-09-10T21:33:01.000Z","dependencies_parsed_at":"2023-10-12T07:22:32.386Z","dependency_job_id":null,"html_url":"https://github.com/ryan-haskell/graphql","commit_stats":null,"previous_names":["ryan-haskell/graphql"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryan-haskell%2Fgraphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryan-haskell%2Fgraphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryan-haskell%2Fgraphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryan-haskell%2Fgraphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryan-haskell","download_url":"https://codeload.github.com/ryan-haskell/graphql/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227393647,"owners_count":17773322,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elm","graphql","package"],"created_at":"2024-11-30T18:26:40.670Z","updated_at":"2025-12-11T20:53:09.417Z","avatar_url":"https://github.com/ryan-haskell.png","language":"Elm","funding_links":[],"categories":[],"sub_categories":[],"readme":"# __@ryan-haskell/graphql__\n\nAn `elm/json` inspired package for working with GraphQL\n\n## __Installation__\n\n```\nelm install ryan-haskell/graphql\n```\n\n## __Introduction__\n\nWhen working with JSON data, folks in the Elm community use the [`elm/json`](https://package.elm-lang.org/packages/elm/json/latest) package. This is a great, general purpose library for safely handling unknown JSON sent from a backend API server.\n\nThis package builds on top of `elm/json`, adding functions designed specifically for working with [__GraphQL__](https://graphql.org/learn/). This means you can easily work with scalars, enums, object types, input types, interfaces, and union types within your Elm application.\n\nHere's a quick overview of what each module does:\n\n1. __`GraphQL.Decode`__ - Decode JSON responses sent from a GraphQL API\n1. __`GraphQL.Encode`__ - Create JSON values to send as variables to a GraphQL API\n1. __`GraphQL.Http`__ - Send HTTP requests to a GraphQL API endpoint\n1. __`GraphQL.Scalar.ID`__ - Work with the built-in GraphQL `ID` scalar\n1. __`GraphQL.Operation`__ - Like `GraphQL.Http`, but allows you to handle `Cmd` values in one place\n1. __`GraphQL.Error`__ - Work with GraphQL validation errors\n\n## __A quick example__\n\nIn [the official GraphQL documentation](https://graphql.org/learn/queries/), they begin their guide with a sample query that uses the _Star Wars_ GraphQL API. \n\nThis is an example that shows how to use this package to create an HTTP request for use in your Elm application:\n\n```elm\nimport GraphQL.Decode exposing (Decoder)\nimport GraphQL.Encode\nimport GraphQL.Http\n\n\ntype Msg\n    = ApiResponded (Result GraphQL.Http.Error Data)\n\n\n\n-- Sending a GraphQL query\n\n\nfindHero : String -\u003e Cmd Msg\nfindHero heroId =\n    GraphQL.Http.get\n        { url = \"/graphql\"\n        , query = \"\"\"\n            query FindHero($id: ID!) {\n              hero(id: $id) {\n                name\n                appearsIn\n              }\n            }\n          \"\"\"\n        , variables =\n            [ ( \"id\", GraphQL.Encode.string heroId )\n            ]\n        , onResponse = ApiResponded\n        , decoder = decoder\n        }\n\n\n\n-- Defining a GraphQL Decoder\n\n\ntype alias Data =\n    { hero : Maybe Hero\n    }\n\n\ndecoder : Decoder Data\ndecoder =\n    GraphQL.Decode.object Data\n        |\u003e GraphQL.Decode.field\n            { name = \"hero\"\n            , decoder = GraphQL.Decode.maybe heroDecoder\n            }\n\n\ntype alias Hero =\n    { name : String\n    , appearsIn : List Episode\n    }\n\n\nheroDecoder : Decoder Hero\nheroDecoder =\n    GraphQL.Decode.object Hero\n        |\u003e GraphQL.Decode.field\n            { name = \"name\"\n            , decoder = GraphQL.Decode.string\n            }\n        |\u003e GraphQL.Decode.field\n            { name = \"appearsIn\"\n            , decoder = GraphQL.Decode.list episodeDecoder\n            }\n\n\ntype Episode\n    = NewHope\n    | EmpireStrikesBack\n    | ReturnOfTheJedi\n\n\nepisodeDecoder : Decoder Episode\nepisodeDecoder =\n    GraphQL.Decode.enum\n        [ ( \"NEWHOPE\", NewHope )\n        , ( \"EMPIRE\", EmpireStrikesBack )\n        , ( \"JEDI\", ReturnOfTheJedi )\n        ]\n```\n\n### __Understanding how it works__\n\nWhen you send this HTTP request, using a function like [`GraphQL.Http.post`](https://package.elm-lang.org/packages/ryan-haskell/graphql/latest/GraphQL-Http#post), the GraphQL API server will receive the following request:\n\n```json\n// POST /graphql\n\n{\n    \"query\": \"query FindHero($id: Id!) { ... }\",\n    \"variables\": {\n        \"id\": \"1\"\n    }\n}\n```\n\nWhen the API responds with a JSON payload, your decoder will convert the raw JSON into Elm values you can use in your application:\n\n```json\n// The JSON sent from the API:\n{\n  \"data\": {\n    \"hero\": {\n      \"name\": \"R2-D2\",\n      \"appearsIn\": [\n        \"NEWHOPE\",\n        \"EMPIRE\",\n        \"JEDI\"\n      ]\n    }\n  }\n}\n```\n\n```elm\n-- The JSON decoded into an Elm value\ndata ==\n    { hero =\n        Just\n            { name = \"R2-D2\"\n            , appearsIn =\n                [ NewHope\n                , EmpireStrikesBack\n                , ReturnOfTheJedi\n                ]\n            }\n    }\n```\n\n## __Comparison with other tools__\n\nThis Elm package is for making GraphQL requests without _any_ code generation or build tools.\n\nIf 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:\n\n1. __[dillonkearns/elm-graphql](https://github.com/dillonkearns/elm-graphql)__ – Write Elm code, generate GraphQL\n2. __[vendrinc/elm-gql](https://github.com/vendrinc/elm-gql)__ – Write GraphQL, generate Elm code\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryan-haskell%2Fgraphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryan-haskell%2Fgraphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryan-haskell%2Fgraphql/lists"}