{"id":20537988,"url":"https://github.com/dmjio/graphql-meta","last_synced_at":"2025-04-14T07:43:00.629Z","repository":{"id":146242186,"uuid":"149478817","full_name":"dmjio/graphql-meta","owner":"dmjio","description":"Lexing, parsing, pretty-printing, and metaprogramming facilities for dealing with GraphQL schemas and queries","archived":false,"fork":false,"pushed_at":"2024-12-14T00:09:50.000Z","size":105,"stargazers_count":21,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T21:23:14.741Z","etag":null,"topics":["facebook","graphql","haskell","lexer","parser"],"latest_commit_sha":null,"homepage":"","language":"Haskell","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/dmjio.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","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":"2018-09-19T16:15:55.000Z","updated_at":"2024-12-14T00:09:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"31af36a8-e702-4385-acd0-d0dd38a2d1d8","html_url":"https://github.com/dmjio/graphql-meta","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmjio%2Fgraphql-meta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmjio%2Fgraphql-meta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmjio%2Fgraphql-meta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmjio%2Fgraphql-meta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmjio","download_url":"https://codeload.github.com/dmjio/graphql-meta/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248842609,"owners_count":21170391,"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":["facebook","graphql","haskell","lexer","parser"],"created_at":"2024-11-16T00:43:48.730Z","updated_at":"2025-04-14T07:43:00.605Z","avatar_url":"https://github.com/dmjio.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"graphql-meta\n================\n\nA [GraphQL](https://graphql.org/) toolkit providing the following:\n  - Alex [Lexer](http://facebook.github.io/graphql/draft/#sec-Appendix-Grammar-Summary.Lexical-Tokens) of the `GraphQL` lexical specification.\n    - [Source](https://github.com/urbint/graphql-meta/blob/master/src/GraphQL/Lexer.x)\n  - Happy [Parser](http://facebook.github.io/graphql/draft/#sec-Appendix-Grammar-Summary.Document) of the `GraphQL` BNF Grammar.\n    - [Source](https://github.com/urbint/graphql-meta/blob/master/src/GraphQL/Lexer.x)\n  - [Pretty printer](http://hackage.haskell.org/package/prettyprinter) of the `GraphQL` abstract syntax tree (AST) for human consumption.\n    - [Source](https://github.com/urbint/graphql-meta/blob/master/src/GraphQL/Pretty.hs)\n  - [QuickCheck](http://www.cse.chalmers.se/~rjmh/QuickCheck/manual.html) generators for creating random AST fragments\n    - Used in conjunction with pretty printing to establish round trip property tests.\n\t- [Source](https://github.com/urbint/graphql-meta/blob/master/test/Test/GraphQL/Gen.hs)\n  - Generics implementation providing correct-by-construction `Schema` at compile time.\n    - [Source](https://github.com/urbint/graphql-meta/blob/master/src/GraphQL/Generic.hs)\n  - QuasiQuoter providing inline definitions of `ExecutableDefinitions`.\n    - [Source](https://github.com/urbint/graphql-meta/blob/master/src/GraphQL/QQ.hs)\n\n## Table of Contents\n- [Query](#query)\n  - [Substitution](#substitution)\n- [Schema](#schema)\n  - [Generics](#generics)\n  - [Limitations](#limitations)\n- [Maintainers](#maintainers)\n- [Credit](#credit)\n- [License](#license)\n\n## Query\n\n```haskell\n{-# LANGUAGE QuasiQuotes #-}\n\nmodule Main (main) where\n\nimport GraphQL.QQ (query)\n\nmain :: IO ()\nmain = print [query| { building (id: 123) {floorCount, id}} |]\n```\n\n#### Result\n\n```haskell\nQueryDocument {getDefinitions = [\n  DefinitionOperation (AnonymousQuery [\n\tSelectionField (Field Nothing (Name {unName = \"building\"}) [\n\t  Argument (Name {unName = \"id\"}) (ValueInt 123)] [] [\n\tSelectionField (Field Nothing (Name {unName = \"floorCount\"}) [] [] [])\n\t  , SelectionField (Field Nothing (Name {unName = \"id\"}) [] [] [])\n\t  ])\n\t])\n  ]}\n```\n\n### Substitution\n\n[GraphQL](https://graphql.org/) `ExecutableDefinition` abstract syntax tree rewriting is made possible via Template Haskell's metavariable substitution. During `QuasiQuotation` all unbound variables in a `GraphQL` query that have identical names inside the current scope will automatically be translated into `GraphQL` AST terms and substituted.\n\n```haskell\nbuildingQuery\n  :: Int\n  -\u003e ExecutableDefinition\nbuildingQuery buildingId =\n  [query| { building (id: $buildingId) {floorCount, id}} |]\n```\n\n#### Result\n\n```haskell\nQueryDocument {getDefinitions = [\n  DefinitionOperation (AnonymousQuery [\n\tSelectionField (Field Nothing (Name {unName = \"building\"}) [\n\t  Argument (Name {unName = \"buildingId\"}) (ValueInt 4)] [] [\n\tSelectionField (Field Nothing (Name {unName = \"floorCount\"}) [] [] [])\n\t  , SelectionField (Field Nothing (Name {unName = \"id\"}) [] [] [])\n\t  ])\n\t])\n  ]}\n```\n\n### Generics\n\nIt is possible to derive GraphQL schema using `GHC.Generics`.\nSimply import `GHC.Generics`, derive `Generic` (must enable the `DeriveGeneric` language extension) and make an instance of `ToObjectTypeDefintion`.\nSee below for an example:\n\n```haskell\n{-# LANGUAGE DeriveGeneric #-}\n\nmodule Main where\n\nimport           GHC.Generics                    (Generic)\nimport           GraphQL.Internal.Syntax.Encoder (schemaDocument)\nimport           Data.Proxy                      (Proxy)\nimport qualified Data.Text.IO                    as T\nimport           GraphQL.Generic                 (ToObjectTypeDefinition(..))\n\ndata Person = Person\n  { name :: String\n  , age  :: Int\n  } deriving (Show, Eq, Generic)\n\ninstance ToObjectTypeDefinition Person\n\nshowPersonSchema :: IO ()\nshowPersonSchema = print $ toObjectTypeDefinition (Proxy @ Person)\n\n-- type Person{name:String!,age:Int!}\n```\n\n## Limitations\n\n- Generic deriving is currently only supported on product types with record field selectors.\n- Only `ObjectTypeDefintion` is currently supported.\n\n## Roadmap\n\n- Generic deriving of `ScalarTypeDefintion` and `EnumTypeDefintion`.\n\n## Maintainers\n\n- [@dmjio](https://github.com/dmjio)\n- [@rschmuckler](https://github.com/rschmukler)\n\n## Credit\n\n- Inspired by [@edsko](https://github.com/edsko)'s work [Quasi-quoting DSLs for free](http://www.well-typed.com/blog/2014/10/quasi-quoting-dsls/).\n- `Alex` and `Happy` lexing \u0026 parsing inspired by [config-value](https://github.com/glguy/config-value)\n\n## License\n\n[BSD3](LICENSE) 2018-2019 Urbint Inc.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmjio%2Fgraphql-meta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmjio%2Fgraphql-meta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmjio%2Fgraphql-meta/lists"}