Skip to content

Commit

Permalink
Feature/ parser supports directives, fixed implements and defaultValu…
Browse files Browse the repository at this point in the history
…e on inputObjects (#282)

* parse implements

* lit Assignment

* patterns inputValueDefinition

* inputObjectTypeDefinition

* add specs in type system

* Type System

* update TypeSystem

* scalar

* inputValue

* Formalization

* Formalization

* Formalization

* Formalization

* patterns

* keywords

* refactor SDL to specifications

* refactor SDL to specifications

* Operation specifications

* Formalize Operation

* add directive to selectionField

* arguments

* arguments

* fragment

* fragment

* Parser Supports directives on spread

* Parser Supports directives on spread

* Parser Supports directives on spread

* optionalDirective

* description

* description

* description

* update terms description

* description on Type

* Type Descriptions

* Type Descriptions

* Type Descriptions

* integrate type description

* integrate type description

* integrate type description

* fix test 1

* fix tests

* input Object Test

* input Object Test

* object field Test

* fix object field descriptions

* fix object field descriptions

* add tests for descriptions

* test directives

* operationKind -> operationType

* OperationKind -> OperationType

* update changelog

* add directive parsing tests for queries

* update changelog
  • Loading branch information
nalchevanidze authored Oct 31, 2019
1 parent 5d59bf1 commit c26bc97
Show file tree
Hide file tree
Showing 39 changed files with 770 additions and 473 deletions.
33 changes: 33 additions & 0 deletions assets/simple.gql
Original file line number Diff line number Diff line change
@@ -1,55 +1,88 @@
"""
my interface description
"""
type Query {
deity (name: [[[[[String!]]!]]], mythology: Realm): Deity!
character (characterID: String! , age: Int ): Character!
hero: Human!
}

"""
my interface description
"""
interface MyInterface {
"""
interface field description
"""
name: String
}


type Mutation {
createDeity (name: [[[[[String!]]!]]], mythology: String): Deity!
createCharacter (realm: Realm! , id: String! ): Character!
}

"""
my unon description
"""
union Character = Creature | Deity | Human

"my mutation description"
type Deity {
fullName: String!
power: Power
}

"""
my mutation description
some creature
"""
type Creature {
name: String!
realm: City!
immortality: Boolean!
}

"""
human
ewrw
"""
type Human {
humanName: String!
lifetime: Lifetime!
profession: Profession
}


enum Profession {
Priest
Farmer
Artist
}

"""
human
ew jso
ewrw
"""
input Realm {
owner: String!
age: Int
realm: Realm
profession: Profession
}

"ancient city"
enum City {
Athens
Ithaca
Sparta Troy
}

""" lifespan of mortal creatures """
scalar Lifetime


scalar Power
6 changes: 3 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

### Added

- dummy support of `directives`, only in `SDL` on fields of: object, inputObject and enum.

it is only parser support not actual implementation
- dummy support of `directives`, only parsing not actual implementation

### Fixed
- can be parsed `implements` with multiple interfaces separated by `&`
- can be parsed default value on `inputobject`
- Parser supports anonymous Operation: `query` , `mutation` , `subscription`
for example:

Expand Down
2 changes: 1 addition & 1 deletion examples/Client/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ defineByIntrospectionFile
}
|]


defineByDocumentFile
"./assets/simple.gql"
[gql|

# Query Hero with Compile time Validation
query GetHero ($god: Realm, $id: String!)
{
Expand Down
2 changes: 2 additions & 0 deletions examples/Sophisticated/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Data.Morpheus.Kind (INPUT_UNION, OBJECT, SCALAR)
import Data.Morpheus.Types (Event (..), GQLRootResolver (..), GQLScalar (..), GQLType (..), ID, QUERY,
Resolver (..), ScalarValue (..), constRes)


$(importGQLDocumentWithNamespace "examples/Sophisticated/api.gql")

type AIntText = A (Int, Text)
Expand Down Expand Up @@ -79,6 +80,7 @@ data Content = Update

type APIEvent = (Event Channel Content)


gqlRoot :: GQLRootResolver IO APIEvent Query Mutation Subscription
gqlRoot = GQLRootResolver {queryResolver, mutationResolver, subscriptionResolver}
where
Expand Down
41 changes: 34 additions & 7 deletions examples/Sophisticated/api.gql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# for Input Union

input Cat {
input Cat @testDir {
name: String!
}

input Dog {
name: String!
name: String! @testDirective(testName:"")
}

input Bird {
Expand All @@ -14,32 +14,59 @@ input Bird {

# Main APi

enum CityID {
enum CityID @enumDir {
"""
temporary multiline Test for Enum field descripions
"""
Paris
BLN @testDirective(testName:"")
HH
"temporary singleline Test for Enum field descripions"
HH @enumFieldDir
}

input Coordinates {
latitude: Euro! @testDirective(testName:"")
"temporary singleline Test for input object field descripions"
longitude: [[[UniqueID!]!]]!
}

input UniqueID {
type: String,
"""
temporary multiline Test for Enum field descripions
"""
type: String = "test default value"
id: String!
}

type Address {
type Address @typeDirective(id:1) {
"""
temporary multiline Test for Enum field descripions
"""
city: String! @deprecated(testName:"",testName2: 123)
street: String!
"temporary singleline Test for input object field descripions"
houseNumber: Int!
}

"""
my custom description for user
"""
type User {
name: String!
email: String!
address(coordinates: Coordinates!, comment: String): Address!
address(
"""
temporary multiline Test for
arguments
descripions
"""
coordinates: Coordinates! @argsDirective(id:1) ,
"temporary singleline Test for input object field descripions"
comment: String = "test default value"
): Address!
home: CityID!
office(zipCode: [[[ID!]]!], id: CityID!): Address
entity: MyUnion
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Morpheus/Execution/Document/Convert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Data.Morpheus.Error.Internal (internalError)
import Data.Morpheus.Execution.Internal.Utils (capital)
import Data.Morpheus.Types.Internal.Data (ArgsType (..), DataField (..), DataField, DataFullType (..),
DataLeaf (..), DataTyCon (..), DataTypeKind (..),
DataTypeKind (..), OperationKind (..), ResolverKind (..),
DataTypeKind (..), OperationType (..), ResolverKind (..),
TypeAlias (..), sysTypes)
import Data.Morpheus.Types.Internal.DataD (ConsD (..), GQLTypeD (..), TypeD (..))
import Data.Morpheus.Types.Internal.Validation (Validation)
Expand Down
4 changes: 2 additions & 2 deletions src/Data/Morpheus/Execution/Server/Encode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Data.Morpheus.Types.GQLType (GQLType (CUSTO
import Data.Morpheus.Types.Internal.AST.Operation (Operation (..), ValidOperation)
import Data.Morpheus.Types.Internal.AST.Selection (Selection (..), SelectionRec (..), ValidSelection)
import Data.Morpheus.Types.Internal.Base (Key)
import Data.Morpheus.Types.Internal.Data (MUTATION, OperationKind, QUERY, SUBSCRIPTION)
import Data.Morpheus.Types.Internal.Data (MUTATION, OperationType, QUERY, SUBSCRIPTION)
import Data.Morpheus.Types.Internal.Resolver (MapGraphQLT (..), PureOperation (..), Resolver (..),
Resolving (..), ResolvingStrategy (..), resolveObject,
withObject)
Expand Down Expand Up @@ -130,7 +130,7 @@ type instance GRes OBJECT v = [(Key, (Key, ValidSelection) -> v)]
type instance GRes UNION v = (Key, (Key, ValidSelection) -> v)

--- GENERICS ------------------------------------------------
class ObjectResolvers (custom :: Bool) a (o :: OperationKind) (m :: * -> *) e where
class ObjectResolvers (custom :: Bool) a (o :: OperationType) (m :: * -> *) e where
objectResolvers :: PureOperation o => Proxy custom -> a -> [(Key, (Key, ValidSelection) -> ResolvingStrategy o m e Value)]

instance (Generic a, GResolver OBJECT (Rep a) o m e ) => ObjectResolvers 'False a o m e where
Expand Down
8 changes: 4 additions & 4 deletions src/Data/Morpheus/Execution/Server/Resolve.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import Data.Morpheus.Schema.SchemaAPI (defaultTyp
import Data.Morpheus.Types.GQLType (GQLType (CUSTOM))
import Data.Morpheus.Types.Internal.AST.Operation (Operation (..), ValidOperation)
import Data.Morpheus.Types.Internal.Data (DataFingerprint (..), DataTyCon (..),
DataTypeLib (..), MUTATION, OperationKind (..),
DataTypeLib (..), MUTATION, OperationType (..),
QUERY, SUBSCRIPTION, initTypeLib)
import Data.Morpheus.Types.Internal.Resolver (GQLRootResolver (..), Resolver (..), ResponseT,
toResponseRes)
Expand Down Expand Up @@ -103,10 +103,10 @@ streamResolver root@GQLRootResolver {queryResolver, mutationResolver, subscripti
query <- parseGQL request >>= validateRequest schema FULL_VALIDATION
Right (schema, query)
----------------------------------------------------------
execOperator (schema, operation@Operation {operationKind = Query}) =
execOperator (schema, operation@Operation {operationType = Query}) =
toResponseRes (encodeQuery (schemaAPI schema) queryResolver operation)
execOperator (_, operation@Operation {operationKind = Mutation}) = toResponseRes (encodeMutation mutationResolver operation)
execOperator (_, operation@Operation {operationKind = Subscription}) = response
execOperator (_, operation@Operation {operationType = Mutation}) = toResponseRes (encodeMutation mutationResolver operation)
execOperator (_, operation@Operation {operationType = Subscription}) = response
where
response = toResponseRes (encodeSubscription subscriptionResolver operation)

Expand Down
4 changes: 2 additions & 2 deletions src/Data/Morpheus/Kind.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Data.Morpheus.Kind
, ResContext(..)
) where

import Data.Morpheus.Types.Internal.Data (OperationKind (..))
import Data.Morpheus.Types.Internal.Data (OperationType (..))

data GQL_KIND
= SCALAR
Expand All @@ -30,7 +30,7 @@ data GQL_KIND
| WRAPPER


data ResContext (kind :: GQL_KIND) (operation:: OperationKind) (m :: * -> * ) event value = ResContext
data ResContext (kind :: GQL_KIND) (operation:: OperationType) (m :: * -> * ) event value = ResContext

--type ObjectConstraint a =
-- | context , like Proxy with multiple parameters
Expand Down
Loading

0 comments on commit c26bc97

Please sign in to comment.