mirror of
https://github.com/Airsequel/AirGQL.git
synced 2025-08-13 18:26:58 +03:00
Add docs to standard graphql types
This commit is contained in:
parent
c161fbd288
commit
c5fbeee8bd
1 changed files with 271 additions and 129 deletions
|
@ -22,7 +22,9 @@ module AirGQL.Introspection.Types (
|
|||
typeField,
|
||||
typeString,
|
||||
typeInt,
|
||||
typeFloat,
|
||||
typeBool,
|
||||
typeID,
|
||||
collectSchemaTypes,
|
||||
enum,
|
||||
enumValue,
|
||||
|
@ -78,57 +80,6 @@ instance ToGraphQL Schema where
|
|||
]
|
||||
|
||||
|
||||
typeSchema :: IntrospectionType
|
||||
typeSchema =
|
||||
object
|
||||
"__Schema"
|
||||
[ field "description" typeString
|
||||
, field "types" $ nonNull $ list $ nonNull typeIntrospectionType
|
||||
, field "queryType" $ nonNull typeIntrospectionType
|
||||
, field "mutationType" typeIntrospectionType
|
||||
, field "subscriptionType" typeIntrospectionType
|
||||
, field "directives" $ nonNull $ list $ nonNull typeDirective
|
||||
]
|
||||
|
||||
|
||||
typeDirective :: IntrospectionType
|
||||
typeDirective =
|
||||
object
|
||||
"__Directive"
|
||||
[ field "name" typeString
|
||||
, field "description" typeString
|
||||
, field "args" $ nonNull $ list $ nonNull typeInputValue
|
||||
, field "isRepeatable" $ nonNull typeBool
|
||||
, field "locations" $ nonNull $ list $ nonNull typeDirectiveLocation
|
||||
]
|
||||
|
||||
|
||||
typeDirectiveLocation :: IntrospectionType
|
||||
typeDirectiveLocation =
|
||||
enum
|
||||
"__DirectiveLocation"
|
||||
[ enumValue "QUERY"
|
||||
, enumValue "MUTATION"
|
||||
, enumValue "SUBSCRIPTION"
|
||||
, enumValue "FIELD"
|
||||
, enumValue "FRAGMENT_DEFINITION"
|
||||
, enumValue "FRAGMENT_SPREAD"
|
||||
, enumValue "INLINE_FRAGMENT"
|
||||
, enumValue "VARIABLE_DEFINITION"
|
||||
, enumValue "SCHEMA"
|
||||
, enumValue "SCALAR"
|
||||
, enumValue "OBJECT"
|
||||
, enumValue "FIELD_DEFINITION"
|
||||
, enumValue "ARGUMENT_DEFINITION"
|
||||
, enumValue "INTERFACE"
|
||||
, enumValue "UNION"
|
||||
, enumValue "ENUM"
|
||||
, enumValue "ENUM_VALUE"
|
||||
, enumValue "INPUT_OBJECT"
|
||||
, enumValue "INPUT_FIELD_DEFINITION"
|
||||
]
|
||||
|
||||
|
||||
-- | The name of a graphql type.
|
||||
type Name = Text
|
||||
|
||||
|
@ -209,35 +160,6 @@ instance ToGraphQL IntrospectionType where
|
|||
]
|
||||
|
||||
|
||||
typeIntrospectionType :: IntrospectionType
|
||||
typeIntrospectionType =
|
||||
object
|
||||
"__Type"
|
||||
[ field
|
||||
"kind"
|
||||
$ enum
|
||||
"__TypeKind"
|
||||
[ enumValue "SCALAR"
|
||||
, enumValue "OBJECT"
|
||||
, enumValue "ENUM"
|
||||
, enumValue "INPUT_OBJECT"
|
||||
, enumValue "LIST"
|
||||
, enumValue "NON_NULL"
|
||||
, enumValue "INTERFACE"
|
||||
]
|
||||
, field "name" typeString
|
||||
, field "description" typeString
|
||||
, field "interfaces" $ list $ nonNull typeIntrospectionType
|
||||
, field "possibleTypes" $ list $ nonNull typeIntrospectionType
|
||||
, field "fields" (list $ nonNull typeField)
|
||||
& withArguments [inputValue "includeDeprecated" typeBool]
|
||||
, field "enumValues" (list $ nonNull typeEnumValue)
|
||||
& withArguments [inputValue "includeDeprecated" typeBool]
|
||||
, field "inputFields" $ list $ nonNull typeInputValue
|
||||
, field "ofType" typeIntrospectionType
|
||||
]
|
||||
|
||||
|
||||
mkType :: TypeKind -> IntrospectionType
|
||||
mkType kind =
|
||||
IType
|
||||
|
@ -302,19 +224,6 @@ instance ToGraphQL Field where
|
|||
]
|
||||
|
||||
|
||||
typeField :: IntrospectionType
|
||||
typeField =
|
||||
object
|
||||
"__Field"
|
||||
[ field "name" $ nonNull typeString
|
||||
, field "description" typeString
|
||||
, field "args" $ nonNull $ list $ nonNull typeInputValue
|
||||
, field "type" $ nonNull typeIntrospectionType
|
||||
, field "isDeprecated" $ nonNull typeBool
|
||||
, field "deprecationReason" typeString
|
||||
]
|
||||
|
||||
|
||||
fieldWithDescription :: Text -> Field -> Field
|
||||
fieldWithDescription newDesc (Field{..}) =
|
||||
Field
|
||||
|
@ -360,17 +269,6 @@ instance ToGraphQL InputValue where
|
|||
]
|
||||
|
||||
|
||||
typeInputValue :: IntrospectionType
|
||||
typeInputValue =
|
||||
object
|
||||
"__InputValue"
|
||||
[ field "name" $ nonNull typeString
|
||||
, field "description" typeString
|
||||
, field "type" $ nonNull typeIntrospectionType
|
||||
, field "defaultValue" typeString
|
||||
]
|
||||
|
||||
|
||||
inputValue :: Text -> IntrospectionType -> InputValue
|
||||
inputValue fieldName fieldType =
|
||||
InputValue
|
||||
|
@ -409,19 +307,14 @@ instance ToGraphQL EnumValue where
|
|||
]
|
||||
|
||||
|
||||
typeEnumValue :: IntrospectionType
|
||||
typeEnumValue =
|
||||
object
|
||||
"__EnumValue"
|
||||
[ field "name" $ nonNull typeString
|
||||
, field "description" typeString
|
||||
, field "isDeprecated" $ nonNull typeBool
|
||||
, field "deprecationReason" typeString
|
||||
]
|
||||
|
||||
|
||||
enumValue :: Text -> EnumValue
|
||||
enumValue name = EnumValue{name = name, description = Nothing, isDeprecated = False, deprecationReason = Nothing}
|
||||
enumValue name =
|
||||
EnumValue
|
||||
{ name = name
|
||||
, description = Nothing
|
||||
, isDeprecated = False
|
||||
, deprecationReason = Nothing
|
||||
}
|
||||
|
||||
|
||||
enumValueWithDescription :: Text -> EnumValue -> EnumValue
|
||||
|
@ -438,24 +331,12 @@ deprecatedEnumValue reason (EnumValue{..}) =
|
|||
}
|
||||
|
||||
|
||||
typeString :: IntrospectionType
|
||||
typeString = scalar "String"
|
||||
|
||||
|
||||
typeInt :: IntrospectionType
|
||||
typeInt = scalar "Int"
|
||||
|
||||
|
||||
typeBool :: IntrospectionType
|
||||
typeBool = scalar "Boolean"
|
||||
|
||||
|
||||
{-| Updates the `types` property of a schema to reference
|
||||
every type contained in other parts of the schema.
|
||||
-}
|
||||
collectSchemaTypes :: Schema -> Schema
|
||||
collectSchemaTypes schema = do
|
||||
let basic = [typeInt, typeString, typeBool, typeSchema]
|
||||
let basic = [typeInt, typeFloat, typeString, typeBool, typeID, typeSchema]
|
||||
let all = do
|
||||
collectTypes schema.queryType
|
||||
for_ schema.mutationType collectTypes
|
||||
|
@ -489,3 +370,264 @@ collectTypes ty = do
|
|||
collectTypes arg.type_
|
||||
InputObject name fields -> insertType name $ do
|
||||
for_ fields $ \thisField -> collectTypes thisField.type_
|
||||
|
||||
|
||||
--------------------- Declarations for all the standard gql types
|
||||
typeString :: IntrospectionType
|
||||
typeString =
|
||||
scalar "String"
|
||||
& withDescription
|
||||
"The `String` scalar type represents textual data, \
|
||||
\represented as UTF-8 character sequences. \
|
||||
\The String type is most often used by GraphQL \
|
||||
\to represent free-form human-readable text."
|
||||
|
||||
|
||||
typeInt :: IntrospectionType
|
||||
typeInt =
|
||||
scalar "Int"
|
||||
& withDescription
|
||||
"The `Int` scalar type represents \
|
||||
\non-fractional signed whole numeric values. \
|
||||
\Int can represent values between -(2^31) and 2^31 - 1."
|
||||
|
||||
|
||||
typeFloat :: IntrospectionType
|
||||
typeFloat =
|
||||
scalar "Float"
|
||||
& withDescription "Signed double-precision floating-point value."
|
||||
|
||||
|
||||
typeBool :: IntrospectionType
|
||||
typeBool =
|
||||
scalar "Boolean"
|
||||
& withDescription "The `Boolean` scalar type represents `true` or `false`."
|
||||
|
||||
|
||||
typeID :: IntrospectionType
|
||||
typeID =
|
||||
scalar "ID"
|
||||
& withDescription
|
||||
"The `ID` scalar type represents a unique identifier, \
|
||||
\often used to refetch an object or as key for a cache. \
|
||||
\The ID type appears in a JSON response as a String; \
|
||||
\however, it is not intended to be human-readable. \
|
||||
\When expected as an input type, any string \
|
||||
\(such as `\"4\"`) or integer (such as `4`) input value \
|
||||
\will be accepted as an ID."
|
||||
|
||||
|
||||
typeField :: IntrospectionType
|
||||
typeField =
|
||||
object
|
||||
"__Field"
|
||||
[ field "name" $ nonNull typeString
|
||||
, field "description" typeString
|
||||
, field "args" $ nonNull $ list $ nonNull typeInputValue
|
||||
, field "type" $ nonNull typeIntrospectionType
|
||||
, field "isDeprecated" $ nonNull typeBool
|
||||
, field "deprecationReason" typeString
|
||||
]
|
||||
& withDescription
|
||||
"Object and Interface types are described by a list of Fields, each of \
|
||||
\which has a name, potentially a list of arguments, and a return type."
|
||||
|
||||
|
||||
typeInputValue :: IntrospectionType
|
||||
typeInputValue =
|
||||
object
|
||||
"__InputValue"
|
||||
[ field "name" $ nonNull typeString
|
||||
, field "description" typeString
|
||||
, field "type" $ nonNull typeIntrospectionType
|
||||
, field "defaultValue" typeString
|
||||
& fieldWithDescription
|
||||
"A GraphQL-formatted string representing \
|
||||
\the default value for this input value."
|
||||
]
|
||||
& withDescription
|
||||
"Arguments provided to Fields or Directives and the input \
|
||||
\fields of an InputObject are represented as Input Values \
|
||||
\which describe their type and optionally a default value."
|
||||
|
||||
|
||||
typeEnumValue :: IntrospectionType
|
||||
typeEnumValue =
|
||||
object
|
||||
"__EnumValue"
|
||||
[ field "name" $ nonNull typeString
|
||||
, field "description" typeString
|
||||
, field "isDeprecated" $ nonNull typeBool
|
||||
, field "deprecationReason" typeString
|
||||
]
|
||||
& withDescription
|
||||
"One possible value for a given Enum. Enum values are unique values, \
|
||||
\not a placeholder for a string or numeric value. However an Enum value \
|
||||
\is returned in a JSON response as a string."
|
||||
|
||||
|
||||
typeTypeKind :: IntrospectionType
|
||||
typeTypeKind =
|
||||
enum
|
||||
"__TypeKind"
|
||||
[ enumValue "SCALAR"
|
||||
& enumValueWithDescription "Indicates this type is a scalar."
|
||||
, enumValue "OBJECT"
|
||||
& enumValueWithDescription
|
||||
"Indicates this type is an object. `fields` and \
|
||||
\`interfaces` are valid fields."
|
||||
, enumValue "INTERFACE"
|
||||
& enumValueWithDescription
|
||||
"Indicates this type is an interface. `fields` \
|
||||
\and `possibleTypes` are valid fields."
|
||||
, enumValue "UNION"
|
||||
& enumValueWithDescription
|
||||
"Indicates this type is a union. `possibleTypes` is a valid field."
|
||||
, enumValue "ENUM"
|
||||
& enumValueWithDescription
|
||||
"Indicates this type is an enum. `enumValues` is a valid field."
|
||||
, enumValue "INPUT_OBJECT"
|
||||
& enumValueWithDescription
|
||||
"Indicates this type is an input object. \
|
||||
\`inputFields` is a valid field."
|
||||
, enumValue "LIST"
|
||||
& enumValueWithDescription
|
||||
"Indicates this type is a list. `ofType` is a valid field."
|
||||
, enumValue "NON_NULL"
|
||||
& enumValueWithDescription
|
||||
"Indicates this type is a non-null. `ofType` is a valid field."
|
||||
]
|
||||
& withDescription
|
||||
"An enum describing what kind of type a given `__Type` is."
|
||||
|
||||
|
||||
typeIntrospectionType :: IntrospectionType
|
||||
typeIntrospectionType =
|
||||
object
|
||||
"__Type"
|
||||
[ field "kind" typeTypeKind
|
||||
, field "name" typeString
|
||||
, field "description" typeString
|
||||
, field "interfaces" $ list $ nonNull typeIntrospectionType
|
||||
, field "possibleTypes" $ list $ nonNull typeIntrospectionType
|
||||
, field "fields" (list $ nonNull typeField)
|
||||
& withArguments [inputValue "includeDeprecated" typeBool]
|
||||
, field "enumValues" (list $ nonNull typeEnumValue)
|
||||
& withArguments [inputValue "includeDeprecated" typeBool]
|
||||
, field "inputFields" $ list $ nonNull typeInputValue
|
||||
, field "ofType" typeIntrospectionType
|
||||
]
|
||||
& withDescription
|
||||
"The fundamental unit of any GraphQL Schema is the type. \
|
||||
\There are many kinds of types in GraphQL as represented by the `__TypeKind` enum.\n\n\
|
||||
\Depending on the kind of a type, certain fields describe information about that type. \
|
||||
\Scalar types provide no information beyond a name and description, while Enum types provide their values. \
|
||||
\Object and Interface types provide the fields they describe. \
|
||||
\Abstract types, Union and Interface, provide the Object types possible at runtime. \
|
||||
\List and NonNull types compose other types."
|
||||
|
||||
|
||||
typeSchema :: IntrospectionType
|
||||
typeSchema =
|
||||
object
|
||||
"__Schema"
|
||||
[ field "description" typeString
|
||||
, fieldWithDescription "A list of all types supported by this server." $
|
||||
field "types" $
|
||||
nonNull $
|
||||
list $
|
||||
nonNull typeIntrospectionType
|
||||
, fieldWithDescription "The type that query operations will be rooted at." $
|
||||
field "queryType" $
|
||||
nonNull typeIntrospectionType
|
||||
, fieldWithDescription
|
||||
"If this server supports mutation, the type \
|
||||
\that mutation operations will be rooted at."
|
||||
$ field "mutationType" typeIntrospectionType
|
||||
, fieldWithDescription
|
||||
"If this server support subscription, the type \
|
||||
\that subscription operations will be rooted at."
|
||||
$ field "subscriptionType" typeIntrospectionType
|
||||
, fieldWithDescription "A list of all directives supported by this server." $
|
||||
field "directives" $
|
||||
nonNull $
|
||||
list $
|
||||
nonNull typeDirective
|
||||
]
|
||||
& withDescription
|
||||
"A GraphQL Schema defines the capabilities of a GraphQL server. \
|
||||
\It exposes all available types and directives on the server, \
|
||||
\as well as the entry points for \
|
||||
\query, mutation, and subscription operations."
|
||||
|
||||
|
||||
typeDirective :: IntrospectionType
|
||||
typeDirective =
|
||||
object
|
||||
"__Directive"
|
||||
[ field "name" typeString
|
||||
, field "description" typeString
|
||||
, field "args" $ nonNull $ list $ nonNull typeInputValue
|
||||
, field "isRepeatable" $ nonNull typeBool
|
||||
, field "locations" $ nonNull $ list $ nonNull typeDirectiveLocation
|
||||
]
|
||||
& withDescription
|
||||
"A Directive provides a way to describe alternate runtime execution \
|
||||
\and type validation behavior in a GraphQL document.\n\nIn some cases, \
|
||||
\you need to provide options to alter GraphQL's execution behavior in \
|
||||
\ways field arguments will not suffice, such as conditionally including \
|
||||
\or skipping a field. Directives provide this by describing additional \
|
||||
\information to the executor."
|
||||
|
||||
|
||||
typeDirectiveLocation :: IntrospectionType
|
||||
typeDirectiveLocation =
|
||||
enum
|
||||
"__DirectiveLocation"
|
||||
[ enumValue "QUERY"
|
||||
& enumValueWithDescription "Location adjacent to a query operation."
|
||||
, enumValue "MUTATION"
|
||||
& enumValueWithDescription "Location adjacent to a mutation operation."
|
||||
, enumValue "SUBSCRIPTION"
|
||||
& enumValueWithDescription
|
||||
"Location adjacent to a subscription operation."
|
||||
, enumValue "FIELD"
|
||||
& enumValueWithDescription "Location adjacent to a field."
|
||||
, enumValue "FRAGMENT_DEFINITION"
|
||||
& enumValueWithDescription "Location adjacent to a fragment definition."
|
||||
, enumValue "FRAGMENT_SPREAD"
|
||||
& enumValueWithDescription "Location adjacent to a fragment spread."
|
||||
, enumValue "INLINE_FRAGMENT"
|
||||
& enumValueWithDescription "Location adjacent to an inline fragment."
|
||||
, enumValue "VARIABLE_DEFINITION"
|
||||
& enumValueWithDescription "Location adjacent to a variable definition."
|
||||
, enumValue "SCHEMA"
|
||||
& enumValueWithDescription "Location adjacent to a schema definition."
|
||||
, enumValue "SCALAR"
|
||||
& enumValueWithDescription "Location adjacent to a scalar definition."
|
||||
, enumValue "OBJECT"
|
||||
& enumValueWithDescription
|
||||
"Location adjacent to an object type definition."
|
||||
, enumValue "FIELD_DEFINITION"
|
||||
& enumValueWithDescription "Location adjacent to a field definition."
|
||||
, enumValue "ARGUMENT_DEFINITION"
|
||||
& enumValueWithDescription
|
||||
"Location adjacent to an argument definition."
|
||||
, enumValue "INTERFACE"
|
||||
& enumValueWithDescription "Location adjacent to an interface definition."
|
||||
, enumValue "UNION"
|
||||
& enumValueWithDescription "Location adjacent to a union definition."
|
||||
, enumValue "ENUM"
|
||||
& enumValueWithDescription "Location adjacent to an enum definition."
|
||||
, enumValue "ENUM_VALUE"
|
||||
& enumValueWithDescription "Location adjacent to an enum value definition."
|
||||
, enumValue "INPUT_OBJECT"
|
||||
& enumValueWithDescription
|
||||
"Location adjacent to an input object type definition."
|
||||
, enumValue "INPUT_FIELD_DEFINITION"
|
||||
& enumValueWithDescription
|
||||
"Location adjacent to an input object field definition."
|
||||
]
|
||||
& withDescription
|
||||
"A Directive can be adjacent to many parts of the GraphQL language, \
|
||||
\a __DirectiveLocation describes one such possible adjacencies."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue