Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Lexing, parsing, pretty-printing, and metaprogramming facilities for dealing with GraphQL schemas and queries

License

NotificationsYou must be signed in to change notification settings

dmjio/graphql-meta

Repository files navigation

AGraphQL toolkit providing the following:

  • AlexLexer of theGraphQL lexical specification.
  • HappyParser of theGraphQL BNF Grammar.
  • Pretty printer of theGraphQL abstract syntax tree (AST) for human consumption.
  • QuickCheck generators for creating random AST fragments
    • Used in conjunction with pretty printing to establish round trip property tests.
    • Source
  • Generics implementation providing correct-by-constructionSchema at compile time.
  • QuasiQuoter providing inline definitions ofExecutableDefinitions.

Table of Contents

Query

{-#LANGUAGE QuasiQuotes #-}moduleMain (main)whereimportGraphQL.QQ (query)main::IO()main=print [query| { building (id: 123) {floorCount, id}} |]

Result

QueryDocument {getDefinitions= [DefinitionOperation (AnonymousQuery [SelectionField (FieldNothing (Name {unName="building"}) [Argument (Name {unName="id"}) (ValueInt123)][] [SelectionField (FieldNothing (Name {unName="floorCount"})[][][])  ,SelectionField (FieldNothing (Name {unName="id"})[][][])  ])])  ]}

Substitution

GraphQLExecutableDefinition abstract syntax tree rewriting is made possible via Template Haskell's metavariable substitution. DuringQuasiQuotation all unbound variables in aGraphQL query that have identical names inside the current scope will automatically be translated intoGraphQL AST terms and substituted.

buildingQuery::Int->ExecutableDefinitionbuildingQuery buildingId=  [query| { building (id: $buildingId) {floorCount, id}} |]

Result

QueryDocument {getDefinitions= [DefinitionOperation (AnonymousQuery [SelectionField (FieldNothing (Name {unName="building"}) [Argument (Name {unName="buildingId"}) (ValueInt4)][] [SelectionField (FieldNothing (Name {unName="floorCount"})[][][])  ,SelectionField (FieldNothing (Name {unName="id"})[][][])  ])])  ]}

Generics

It is possible to derive GraphQL schema usingGHC.Generics.Simply importGHC.Generics, deriveGeneric (must enable theDeriveGeneric language extension) and make an instance ofToObjectTypeDefintion.See below for an example:

{-#LANGUAGE DeriveGeneric #-}moduleMainwhereimportGHC.Generics                    (Generic)importGraphQL.Internal.Syntax.Encoder (schemaDocument)importData.Proxy                      (Proxy)importqualifiedData.Text.IOasTimportGraphQL.Generic                 (ToObjectTypeDefinition(..))dataPerson=Person{name::String  ,age::Int}deriving (Show,Eq,Generic)instanceToObjectTypeDefinitionPersonshowPersonSchema::IO()showPersonSchema=print$ toObjectTypeDefinition (Proxy@Person)-- type Person{name:String!,age:Int!}

Limitations

  • Generic deriving is currently only supported on product types with record field selectors.
  • OnlyObjectTypeDefintion is currently supported.

Roadmap

  • Generic deriving ofScalarTypeDefintion andEnumTypeDefintion.

Maintainers

Credit

License

BSD3 2018-2019 Urbint Inc.

About

Lexing, parsing, pretty-printing, and metaprogramming facilities for dealing with GraphQL schemas and queries

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp