1
Fork 0
mirror of https://github.com/Airsequel/AirGQL.git synced 2025-09-18 19:34:32 +02:00

Add basic directive support to introspection system

This commit is contained in:
prescientmoon 2024-11-14 12:48:07 +01:00
commit 67b37aabc5
2 changed files with 75 additions and 21 deletions
source/AirGQL

View file

@ -347,6 +347,10 @@ tableDeleteField accessMode table = do
] ]
directives :: [Type.Directive]
directives = []
getSchema getSchema
:: AccessMode :: AccessMode
-> [TableEntry] -> [TableEntry]
@ -383,6 +387,7 @@ getSchema accessMode tables = do
[] []
(Type.object "Query" queryType) (Type.object "Query" queryType)
(Just $ Type.object "Mutation" mutationType) (Just $ Type.object "Mutation" mutationType)
directives
-- We make this toplevel, because putting it inside `getSchemaResolver` -- We make this toplevel, because putting it inside `getSchemaResolver`

View file

@ -1,36 +1,40 @@
module AirGQL.Introspection.Types ( module AirGQL.Introspection.Types (
Schema (..), Schema (..),
Directive (..),
Name, Name,
IntrospectionType (..), IntrospectionType (..),
TypeKind (..), TypeKind (..),
Field (..), Field (..),
InputValue (..), InputValue (..),
EnumValue (..), EnumValue (..),
list,
nonNull,
field,
withArguments,
inputValue,
inputValueWithDescription,
withDescription,
withDefaultValue,
fieldWithDescription,
scalar,
object,
inputObject,
typeSchema,
typeIntrospectionType,
typeField,
typeString,
typeInt,
typeFloat,
typeBool,
typeID,
collectSchemaTypes, collectSchemaTypes,
deprecatedEnumValue,
directive,
directiveWithDescription,
enum, enum,
enumValue, enumValue,
enumValueWithDescription, enumValueWithDescription,
deprecatedEnumValue, field,
fieldWithDescription,
inputObject,
inputValue,
inputValueWithDescription,
list,
nonNull,
object,
repeatableDirective,
scalar,
typeBool,
typeField,
typeFloat,
typeID,
typeInt,
typeIntrospectionType,
typeSchema,
typeString,
withArguments,
withDefaultValue,
withDescription,
) where ) where
import Protolude ( import Protolude (
@ -50,6 +54,7 @@ import Protolude (
when, when,
($), ($),
(&), (&),
(<$>),
(<>), (<>),
) )
@ -64,6 +69,7 @@ data Schema = Schema
, types :: [IntrospectionType] , types :: [IntrospectionType]
, queryType :: IntrospectionType , queryType :: IntrospectionType
, mutationType :: Maybe IntrospectionType , mutationType :: Maybe IntrospectionType
, directives :: [Directive]
} }
deriving (Show, Generic) deriving (Show, Generic)
@ -345,6 +351,49 @@ deprecatedEnumValue reason (EnumValue{..}) =
} }
data Directive = Directive
{ name :: Text
, description :: Maybe Text
, locations :: [Text]
, args :: [InputValue]
, isRepeatable :: Bool
}
deriving (Generic, Show)
instance ToGraphQL Directive where
toGraphQL value =
Value.Object $
HashMap.fromList
[ ("name", toGraphQL value.name)
, ("description", toGraphQL value.description)
, ("isRepeatable", toGraphQL value.isRepeatable)
, ("args", toGraphQL value.args)
, ("locations", Value.List $ Value.Enum <$> value.locations)
]
directive :: Text -> [Text] -> [InputValue] -> Directive
directive name locations args =
Directive
{ name = name
, args = args
, locations = locations
, description = Nothing
, isRepeatable = False
}
directiveWithDescription :: Text -> Directive -> Directive
directiveWithDescription newDesc (Directive{..}) =
Directive{description = Just newDesc, ..}
repeatableDirective :: Directive -> Directive
repeatableDirective (Directive{..}) =
Directive{isRepeatable = True, ..}
{-| Updates the `types` property of a schema to reference {-| Updates the `types` property of a schema to reference
every type contained in other parts of the schema. every type contained in other parts of the schema.
-} -}