summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--CHANGELOG.md6
-rw-r--r--Data/GraphQL.hs140
-rw-r--r--LICENSE30
-rw-r--r--README.md22
-rw-r--r--Setup.hs2
-rw-r--r--TODO3
-rw-r--r--graphql.cabal26
-rw-r--r--stack.yaml5
9 files changed, 235 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3a5b475
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.stack-work/
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..a5ca3ef
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,6 @@
+# Change Log
+All notable changes to this project will be documented in this file.
+
+## [0.1] - 2015-09-12
+### Added
+- Data types for the GraphQL language.
diff --git a/Data/GraphQL.hs b/Data/GraphQL.hs
new file mode 100644
index 0000000..d878022
--- /dev/null
+++ b/Data/GraphQL.hs
@@ -0,0 +1,140 @@
+module Data.GraphQL where
+
+import Data.Text (Text)
+
+-- * Name
+
+type Name = Text
+
+-- * Document
+
+newtype Document = Document [Definition] deriving (Eq,Show)
+
+data Definition = DefinitionOperation OperationDefinition
+ | DefinitionFragment FragmentDefinition
+ | DefinitionType TypeDefinition
+ deriving (Eq,Show)
+
+data OperationDefinition =
+ Query (Maybe [VariableDefinition]) (Maybe [Directive]) SelectionSet
+ | Mutation (Maybe [VariableDefinition]) (Maybe [Directive]) SelectionSet
+ | Subscription (Maybe [VariableDefinition]) (Maybe [Directive]) SelectionSet
+ deriving (Eq,Show)
+
+data VariableDefinition = VariableDefinition Variable Type (Maybe DefaultValue)
+ deriving (Eq,Show)
+
+newtype Variable = Variable Name deriving (Eq,Show)
+
+newtype SelectionSet = SelectionSet [Selection] deriving (Eq,Show)
+
+data Selection = SelectionField Field
+ | SelectionFragmentSpread FragmentSpread
+ | SelectionInlineFragment InlineFragment
+ deriving (Eq,Show)
+
+data Field = Field (Maybe Alias) Name (Maybe [Argument])
+ (Maybe [Directive])
+ (Maybe SelectionSet)
+ deriving (Eq,Show)
+
+type Alias = Name
+
+data Argument = Argument Name Value deriving (Eq,Show)
+
+-- * Fragments
+
+data FragmentSpread = FragmentSpread Name (Maybe [Directive])
+ deriving (Eq,Show)
+
+data InlineFragment =
+ InlineFragment TypeCondition (Maybe [Directive]) SelectionSet
+ deriving (Eq,Show)
+
+data FragmentDefinition =
+ FragmentDefinition Name TypeCondition (Maybe [Directive]) SelectionSet
+ deriving (Eq,Show)
+
+type TypeCondition = NamedType
+
+-- * Values
+
+data Value = ValueVariable Variable
+ | ValueInt Int
+ | ValueFloat Float
+ | ValueString Text
+ | ValueBoolean Bool
+ | ValueEnum Name
+ | ValueList ListValue
+ | ValueObject ObjectValue
+ deriving (Eq,Show)
+
+newtype ListValue = ListValue [Value] deriving (Eq,Show)
+
+newtype ObjectValue = ObjectValue [ObjectField] deriving (Eq,Show)
+
+data ObjectField = ObjectField Name Value deriving (Eq,Show)
+
+type DefaultValue = Value
+
+-- * Directives
+
+data Directive = Directive Name (Maybe [Argument]) deriving (Eq,Show)
+
+-- * Type Reference
+
+data Type = TypeNamed NamedType
+ | TypeList ListType
+ | TypeNonNull NonNullType
+ deriving (Eq,Show)
+
+newtype NamedType = NamedType Name deriving (Eq,Show)
+
+newtype ListType = ListType Type deriving (Eq,Show)
+
+data NonNullType = NonNullTypeNamed NamedType
+ | NonNullTypeList ListType
+ deriving (Eq,Show)
+
+-- * Type definition
+
+data TypeDefinition = TypeDefinitionObject ObjectTypeDefinition
+ | TypeDefinitionInterface InterfaceTypeDefinition
+ | TypeDefinitionUnion UnionTypeDefinition
+ | TypeDefinitionScalar ScalarTypeDefinition
+ | TypeDefinitionEnum EnumTypeDefinition
+ | TypeDefinitionInputObject InputObjectTypeDefinition
+ | TypeDefinitionTypeExtension TypeExtensionDefinition
+ deriving (Eq,Show)
+
+data ObjectTypeDefinition = ObjectTypeDefinition Name (Maybe Interfaces) [FieldDefinition]
+ deriving (Eq,Show)
+
+type Interfaces = [NamedType]
+
+data FieldDefinition = FieldDefinition Name [InputValueDefinition]
+ deriving (Eq,Show)
+
+data InputValueDefinition = InputValueDefinition Name Type (Maybe DefaultValue)
+ deriving (Eq,Show)
+
+data InterfaceTypeDefinition = InterfaceTypeDefinition Name [FieldDefinition]
+ deriving (Eq,Show)
+
+data UnionTypeDefinition = UnionTypeDefinition Name [NamedType]
+ deriving (Eq,Show)
+
+data ScalarTypeDefinition = ScalarTypeDefinition Name
+ deriving (Eq,Show)
+
+data EnumTypeDefinition = EnumTypeDefinition Name [EnumValueDefinition]
+ deriving (Eq,Show)
+
+newtype EnumValueDefinition = EnumValueDefinition Name
+ deriving (Eq,Show)
+
+data InputObjectTypeDefinition = InputObjectTypeDefinition Name [InputValueDefinition]
+ deriving (Eq,Show)
+
+newtype TypeExtensionDefinition = TypeExtensionDefinition ObjectTypeDefinition
+ deriving (Eq,Show)
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..35025b8
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,30 @@
+Copyright J. Daniel Navarro (c) 2015
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of J. Daniel Navarro nor the names of other
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..96408a4
--- /dev/null
+++ b/README.md
@@ -0,0 +1,22 @@
+# Haskell GraphQL
+
+[![Hackage Version](https://img.shields.io/hackage/v/graphql.svg)](https://hackage.haskell.org/package/graphql)
+
+For now this only provides the data types to represent the GraphQL AST,
+but the idea is to be a Haskell port of
+[`graphql-js`](https://github.com/graphql/graphql-js). Next releases
+should include:
+
+- [ ] Parser for the GraphQL language.
+- [ ] Data types for the GraphQL Schema language.
+- [ ] Parser for the GraphQL Schema language.
+- [ ] Interpreter of GraphQL requests.
+- [ ] Utilities to define GraphQL types and schema.
+
+## Contact
+
+Suggestions, contributions and bug reports are welcome.
+
+Feel free to contact me, jdnavarro, on the #haskell channel on the
+[GraphQL Slack Server](https://graphql.slack.com). You can obtain an
+invitation [here](https://graphql-slack.herokuapp.com/).
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
index 0000000..9a994af
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..6002a0a
--- /dev/null
+++ b/TODO
@@ -0,0 +1,3 @@
+- Data type accessors
+- Deal with Location
+- Deal with Strictness/unboxing
diff --git a/graphql.cabal b/graphql.cabal
new file mode 100644
index 0000000..7687c30
--- /dev/null
+++ b/graphql.cabal
@@ -0,0 +1,26 @@
+name: graphql
+version: 0.1
+synopsis: GraphQL Types
+description:
+ Data types for the GraphQL language.
+homepage: https://github.com/jdnavarro/graphql-haskell
+bug-reports: https://github.com/jdnavarro/graphql-haskell/issues
+license: BSD3
+license-file: LICENSE
+author: Danny Navarro
+maintainer: j@dannynavarro.net
+copyright: Copyright (C) 2015 J. Daniel Navarro
+category: Web,Parsing
+build-type: Simple
+extra-source-files: README.md CHANGELOG.md stack.yaml
+cabal-version: >=1.10
+
+library
+ exposed-modules: Data.GraphQL
+ build-depends: base >= 4.7 && < 5,
+ text >=0.11.3.1
+ default-language: Haskell2010
+
+source-repository head
+ type: git
+ location: git://github.com/jdnavarro/graphql-haskell.git
diff --git a/stack.yaml b/stack.yaml
new file mode 100644
index 0000000..bee0443
--- /dev/null
+++ b/stack.yaml
@@ -0,0 +1,5 @@
+flags: {}
+packages:
+- '.'
+extra-deps: []
+resolver: lts-3.4