{-# LANGUAGE ApplicativeDo #-}

module Hasura.GraphQL.Schema.Introspect
  ( buildIntrospectionSchema,
    schema,
    typeIntrospection,
  )
where

import Data.Aeson.Ordered qualified as J
import Data.HashMap.Strict qualified as HashMap
import Data.HashMap.Strict.InsOrd qualified as InsOrdHashMap
import Data.List.NonEmpty qualified as NE
import Data.Text qualified as T
import Data.Vector qualified as V
import Hasura.GraphQL.Parser.Class
import Hasura.GraphQL.Parser.Directives
import Hasura.GraphQL.Parser.Name qualified as GName
import Hasura.GraphQL.Schema.Parser as P
import Hasura.Prelude
import Language.GraphQL.Draft.Printer qualified as GP
import Language.GraphQL.Draft.Syntax qualified as G
import Text.Builder qualified as T

{-
Note [Basics of introspection schema generation]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We generate the introspection schema from the existing schema for queries,
mutations and subscriptions.  In other words, we generate one @Parser@ from some
other @Parser@s.  In this way, we avoid having to remember what types we have to
expose through introspection explicitly, as we did in a previous version of
graphql-engine.

However the schema information is obtained, the @Schema@ type stores it.  From a
@Schema@ object we then produce one @FieldParser@ that reads a `__schema` field,
and one that reads a `__type` field.  The idea is that these parsers simply
output a JSON value directly, and so indeed the type of @schema@, for instance,
is @FieldParser n J.Value@.

The idea of "just output the JSON object directly" breaks down when we want to
output a list of things, however, such as in the `types` field of `__schema`.
In the case of `types`, the JSON object to be generated is influenced by the
underlying selection set, so that, for instance,

```
query {
  __schema {
    types {
      name
    }
  }
}
```

means that we only output the _name_ of every type in our schema.  One naive
approach one might consider here would be to have a parser

```
typeField :: P.Type k -> Parser n J.Value
```

that takes a type, and is able to produce a JSON value for it, and then to apply
this parser to all the types in our schema.

However, we only have *one* selection set to parse: so which of the parsers we
obtained should we use to parse it?  And what should we do in the theoretical
case that we have a schema without any types?  (The latter is actually not
possible since we always have `query_root`, but it illustrates the problem that
there is no canonical choice of type to use to parse the selection set.)
Additionally, this would allow us to get the JSON output for *one* type, rather
than for our list of types.  After all, @Parser n@ is *not* a @Monad@ (it's not
even an @Applicative@), so we don't have a map @(a -> Parser n b) -> [a] -> m
[b]@.

In order to resolve this conundrum, let's consider what the ordinary Postgres
schema generates for a query such as follows.

```
query {
  author {
    articles {
      title
    }
  }
}
```

Now the @Parser@ for an article's title does not directly give the desired
output data: indeed, there would be many different titles, rather than any
single one we can return.  Instead, it returns a value that can, after parsing,
be used to build an output, along the lines of:

```
articleTitle :: FieldParser n SQLArticleTitle
```

(This is a heavily simplified representation of reality.)

These values can be thought of as an intermediate representation that can then
be used to generate and run SQL that gives the desired JSON output at a later
stage.  In other words, in the above example, @SQLArticleTitle@ can be thought
of as a function @Article -> Title@ that, given an article, gives back its
title.

Such an approach could help us as well, as, from instructions on how to generate
a JSON return for a given `__Type`, surely we can later simply apply this
construction to all types desired.

However, we don't _need_ to build an intermediate AST to do this: we can simply
output the conversion functions directly.  So the type of @typeField@ is closer
to:

```
typeField :: Parser n (P.Type k -> J.Value)
```

This says that we are always able to parse a selection set for a `__Type`, and
once we do, we obtain a map, which we refer to as `printer` in this module,
which can output a JSON object for a given GraphQL type from our schema.

To use `typeField` as part of another selection set, we build up a corresponding
`FieldParser`, thus obtaining a printer, then apply this printer to all desired
types, and output the final JSON object as a J.Array of the printed results,
like so (again, heavily simplified):

```
    types :: FieldParser n J.Value
    types = do
      printer <- P.subselection_ GName._types Nothing typeField
      return $ J.Array $ map printer $ allSchemaTypes
```

Upon reading this you may be bewildered how we are able to use do notation for
@FieldParser@, which does not have a @Monad@ instance, or even an @Applicative@
instance.  It just so happens that, as long as we write our do blocks carefully,
so that we only use the functoriality of @FieldParser@, the simplification rules
of GHC kick in just in time to avoid any application of @(>>=)@ or @return@.
Arguably the above notation is prettier than equivalent code that explicitly
reduces this to applications of @fmap@.  If you, dear reader, feel like the do
notation adds more confusion than value, you should feel free to change this, as
there is no deeper meaning to the application of do notation than ease of
reading.
-}

{- Note [What introspection exposes]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NB: By "introspection query", we mean a query making use of the __type or
__schema top-level fields.

It would be very convenient if we could simply build up our desired GraphQL
schema, without regard for introspection. Ideally, we would then extract the
data required for introspection from this complete GraphQL schema. There are,
however, some complications:

1. Of course, we _do_ need to include the introspection fields themselves into
   the query_root, so that we can deal with introspection queries
   appropriately. So we can't avoid thinking about introspection entirely while
   constructing the GraphQL schema.

2. The GraphQL specification says that although we must always expose __type and
   __schema fields as part of the query_root, they must not be visible fields of
   the query_root object type. See
   http://spec.graphql.org/June2018/#sec-Schema-Introspection

At this point, one might naively attempt to generate two GraphQL schemas:

- One without the __type and __schema fields, from which we generate the data
  required for responding to introspection queries.
- One with the __type and __schema fields, which is used to actually respond to
  queries.

However, this is also not GraphQL-compliant!

The problem here is that while __type and __schema are not visible fields of the
query root object, their *types*, __Type and __Schema respectively, *must be*
exposed through __type introspection, even though those types never appear as
(transitive) members of the query/mutation/subscription root fields.

So in order to gather the data required for introspection, we follow the
following recipe:

A. Collect type information from the introspection-free GraphQL schema

B. Collect type information from the introspection-only GraphQL schema

C. Stitch together the results of (A) and (B). In particular, the query_root
from (A) is used, and all types from (A) and (B) are used, except for the
query_root obtained in (B). -}

-- | Builds a @Schema@ from GraphQL types for the query_root, mutation_root and
-- subscription_root.
--
-- See Note [What introspection exposes]
buildIntrospectionSchema ::
  P.Type 'Output ->
  Maybe (P.Type 'Output) ->
  Maybe (P.Type 'Output) ->
  Either P.ConflictingDefinitions P.Schema
buildIntrospectionSchema :: Type 'Output
-> Maybe (Type 'Output)
-> Maybe (Type 'Output)
-> Either ConflictingDefinitions Schema
buildIntrospectionSchema Type 'Output
queryRoot' Maybe (Type 'Output)
mutationRoot' Maybe (Type 'Output)
subscriptionRoot' = do
  let -- The only directives that we currently expose over introspection are our
      -- statically defined ones.  So, for instance, we don't correctly expose
      -- directives from remote schemas.
      [DirectiveInfo]
directives :: [DirectiveInfo] = forall (m :: * -> *) origin. MonadParse m => [DirectiveInfo origin]
directivesInfo @P.Parse

  -- Collect type information of all fields
  --
  -- TODO: it may be worth looking at whether we can stop collecting
  -- introspection types monadically. They are independent of the user schema;
  -- the types here are always the same and specified by the GraphQL spec
  HashMap Name (SomeDefinitionTypeInfo MetadataObjId)
allTypes <-
    [TypeDefinitionsWrapper]
-> Either
     ConflictingDefinitions
     (HashMap Name (SomeDefinitionTypeInfo MetadataObjId))
forall origin a.
HasTypeDefinitions origin a =>
a
-> Either
     (ConflictingDefinitions origin)
     (HashMap Name (SomeDefinitionTypeInfo origin))
P.collectTypeDefinitions
      [ Type 'Output -> TypeDefinitionsWrapper
forall a. HasTypeDefinitions a => a -> TypeDefinitionsWrapper
P.TypeDefinitionsWrapper Type 'Output
queryRoot',
        Maybe (Type 'Output) -> TypeDefinitionsWrapper
forall a. HasTypeDefinitions a => a -> TypeDefinitionsWrapper
P.TypeDefinitionsWrapper Maybe (Type 'Output)
mutationRoot',
        Maybe (Type 'Output) -> TypeDefinitionsWrapper
forall a. HasTypeDefinitions a => a -> TypeDefinitionsWrapper
P.TypeDefinitionsWrapper Maybe (Type 'Output)
subscriptionRoot',
        [Definition MetadataObjId (InputFieldInfo MetadataObjId)]
-> TypeDefinitionsWrapper
forall a. HasTypeDefinitions a => a -> TypeDefinitionsWrapper
P.TypeDefinitionsWrapper ([Definition MetadataObjId (InputFieldInfo MetadataObjId)]
 -> TypeDefinitionsWrapper)
-> [Definition MetadataObjId (InputFieldInfo MetadataObjId)]
-> TypeDefinitionsWrapper
forall a b. (a -> b) -> a -> b
$ DirectiveInfo
-> [Definition MetadataObjId (InputFieldInfo MetadataObjId)]
forall origin.
DirectiveInfo origin -> [Definition origin (InputFieldInfo origin)]
P.diArguments (DirectiveInfo
 -> [Definition MetadataObjId (InputFieldInfo MetadataObjId)])
-> [DirectiveInfo]
-> [Definition MetadataObjId (InputFieldInfo MetadataObjId)]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< [DirectiveInfo]
directives,
        -- The __schema introspection field
        Definition MetadataObjId (FieldInfo MetadataObjId)
-> TypeDefinitionsWrapper
forall a. HasTypeDefinitions a => a -> TypeDefinitionsWrapper
P.TypeDefinitionsWrapper (Definition MetadataObjId (FieldInfo MetadataObjId)
 -> TypeDefinitionsWrapper)
-> Definition MetadataObjId (FieldInfo MetadataObjId)
-> TypeDefinitionsWrapper
forall a b. (a -> b) -> a -> b
$ FieldParser MetadataObjId Parse (Schema -> Value)
-> Definition MetadataObjId (FieldInfo MetadataObjId)
forall origin (m :: * -> *) a.
FieldParser origin m a -> Definition origin (FieldInfo origin)
fDefinition (forall (n :: * -> *).
MonadParse n =>
FieldParser n (Schema -> Value)
schema @Parse),
        -- The __type introspection field
        Definition MetadataObjId (FieldInfo MetadataObjId)
-> TypeDefinitionsWrapper
forall a. HasTypeDefinitions a => a -> TypeDefinitionsWrapper
P.TypeDefinitionsWrapper (Definition MetadataObjId (FieldInfo MetadataObjId)
 -> TypeDefinitionsWrapper)
-> Definition MetadataObjId (FieldInfo MetadataObjId)
-> TypeDefinitionsWrapper
forall a b. (a -> b) -> a -> b
$ FieldParser MetadataObjId Parse (Schema -> Value)
-> Definition MetadataObjId (FieldInfo MetadataObjId)
forall origin (m :: * -> *) a.
FieldParser origin m a -> Definition origin (FieldInfo origin)
fDefinition (forall (n :: * -> *).
MonadParse n =>
FieldParser n (Schema -> Value)
typeIntrospection @Parse)
      ]

  pure
    $ P.Schema
      { sDescription :: Maybe Description
sDescription = Maybe Description
forall a. Maybe a
Nothing,
        sTypes :: HashMap Name (SomeDefinitionTypeInfo MetadataObjId)
sTypes = HashMap Name (SomeDefinitionTypeInfo MetadataObjId)
allTypes,
        sQueryType :: Type 'Output
sQueryType = Type 'Output
queryRoot',
        sMutationType :: Maybe (Type 'Output)
sMutationType = Maybe (Type 'Output)
mutationRoot',
        sSubscriptionType :: Maybe (Type 'Output)
sSubscriptionType = Maybe (Type 'Output)
subscriptionRoot',
        sDirectives :: [DirectiveInfo]
sDirectives = [DirectiveInfo]
directives
      }

-- | Generate a __type introspection parser
typeIntrospection ::
  forall n.
  (MonadParse n) =>
  FieldParser n (Schema -> J.Value)
{-# INLINE typeIntrospection #-}
typeIntrospection :: forall (n :: * -> *).
MonadParse n =>
FieldParser n (Schema -> Value)
typeIntrospection = do
  let nameArg :: P.InputFieldsParser n Text
      nameArg :: InputFieldsParser n Text
nameArg = Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> InputFieldsParser n Text
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m a
P.field Name
GName._name Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
  ~(Text
nameText, SomeType -> Value
printer) <- Name
-> Maybe Description
-> InputFieldsParser n Text
-> Parser MetadataObjId 'Output n (SomeType -> Value)
-> FieldParser MetadataObjId n (Text, SomeType -> Value)
forall (m :: * -> *) origin a b.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Output m b
-> FieldParser origin m (a, b)
P.subselection Name
GName.___type Maybe Description
forall a. Maybe a
Nothing InputFieldsParser n Text
nameArg Parser MetadataObjId 'Output n (SomeType -> Value)
forall (n :: * -> *).
MonadParse n =>
Parser 'Output n (SomeType -> Value)
typeField
  -- We pass around the GraphQL schema information under the name `partialSchema`,
  -- because the GraphQL spec forces us to expose a hybrid between the
  -- specification of valid queries (including introspection) and an
  -- introspection-free GraphQL schema.  See Note [What introspection exposes].
  pure $ \Schema
partialSchema -> Value -> Maybe Value -> Value
forall a. a -> Maybe a -> a
fromMaybe Value
J.Null (Maybe Value -> Value) -> Maybe Value -> Value
forall a b. (a -> b) -> a -> b
$ do
    Name
name <- Text -> Maybe Name
G.mkName Text
nameText
    P.SomeDefinitionTypeInfo Definition MetadataObjId (TypeInfo MetadataObjId k)
def <- Name
-> HashMap Name (SomeDefinitionTypeInfo MetadataObjId)
-> Maybe (SomeDefinitionTypeInfo MetadataObjId)
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup Name
name (HashMap Name (SomeDefinitionTypeInfo MetadataObjId)
 -> Maybe (SomeDefinitionTypeInfo MetadataObjId))
-> HashMap Name (SomeDefinitionTypeInfo MetadataObjId)
-> Maybe (SomeDefinitionTypeInfo MetadataObjId)
forall a b. (a -> b) -> a -> b
$ Schema -> HashMap Name (SomeDefinitionTypeInfo MetadataObjId)
forall origin.
Schema origin -> HashMap Name (SomeDefinitionTypeInfo origin)
sTypes Schema
partialSchema
    Value -> Maybe Value
forall a. a -> Maybe a
Just (Value -> Maybe Value) -> Value -> Maybe Value
forall a b. (a -> b) -> a -> b
$ SomeType -> Value
printer (SomeType -> Value) -> SomeType -> Value
forall a b. (a -> b) -> a -> b
$ Type k -> SomeType
forall (k :: Kind). Type k -> SomeType
SomeType (Type k -> SomeType) -> Type k -> SomeType
forall a b. (a -> b) -> a -> b
$ Nullability
-> Definition MetadataObjId (TypeInfo MetadataObjId k) -> Type k
forall origin (k :: Kind).
Nullability
-> Definition origin (TypeInfo origin k) -> Type origin k
P.TNamed Nullability
P.Nullable Definition MetadataObjId (TypeInfo MetadataObjId k)
def

-- | Generate a __schema introspection parser.
schema ::
  forall n.
  (MonadParse n) =>
  FieldParser n (Schema -> J.Value)
{-# INLINE schema #-}
schema :: forall (n :: * -> *).
MonadParse n =>
FieldParser n (Schema -> Value)
schema = Name
-> Maybe Description
-> Parser MetadataObjId 'Output n (Schema -> Value)
-> FieldParser MetadataObjId n (Schema -> Value)
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Output m a
-> FieldParser origin m a
P.subselection_ Name
GName.___schema Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Output n (Schema -> Value)
forall (n :: * -> *).
MonadParse n =>
Parser 'Output n (Schema -> Value)
schemaSet

{-
type __Type {
  kind: __TypeKind!
  name: String
  description: String

  # should be non-null for OBJECT and INTERFACE only, must be null for the others
  fields(includeDeprecated: Boolean = false): [__Field!]

  # should be non-null for OBJECT and INTERFACE only, must be null for the others
  interfaces: [__Type!]

  # should be non-null for INTERFACE and UNION only, always null for the others
  possibleTypes: [__Type!]

  # should be non-null for ENUM only, must be null for the others
  enumValues(includeDeprecated: Boolean = false): [__EnumValue!]

  # should be non-null for INPUT_OBJECT only, must be null for the others
  inputFields: [__InputValue!]

  # should be non-null for NON_NULL and LIST only, must be null for the others
  ofType: __Type
}
-}

data SomeType = forall k. SomeType (P.Type k)

typeField ::
  forall n.
  (MonadParse n) =>
  Parser 'Output n (SomeType -> J.Value)
typeField :: forall (n :: * -> *).
MonadParse n =>
Parser 'Output n (SomeType -> Value)
typeField =
  let includeDeprecated :: P.InputFieldsParser n Bool
      includeDeprecated :: InputFieldsParser n Bool
includeDeprecated =
        Name
-> Maybe Description
-> Value Void
-> Parser MetadataObjId 'Both n (Maybe Bool)
-> InputFieldsParser MetadataObjId n (Maybe Bool)
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Value Void
-> Parser origin k m a
-> InputFieldsParser origin m a
P.fieldWithDefault Name
GName._includeDeprecated Maybe Description
forall a. Maybe a
Nothing (Bool -> Value Void
forall var. Bool -> Value var
G.VBoolean Bool
False) (Parser MetadataObjId 'Both n Bool
-> Parser MetadataObjId 'Both n (Maybe Bool)
forall origin (k :: Kind) (m :: * -> *) a.
(MonadParse m, 'Input <: k) =>
Parser origin k m a -> Parser origin k m (Maybe a)
P.nullable Parser MetadataObjId 'Both n Bool
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Bool
P.boolean)
          InputFieldsParser MetadataObjId n (Maybe Bool)
-> (Maybe Bool -> Bool) -> InputFieldsParser n Bool
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> Bool -> Maybe Bool -> Bool
forall a. a -> Maybe a -> a
fromMaybe Bool
False
      kind :: FieldParser n (SomeType -> J.Value)
      kind :: FieldParser n (SomeType -> Value)
kind =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n ()
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._kind Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n ()
forall (n :: * -> *). MonadParse n => Parser 'Both n ()
typeKind
          FieldParser MetadataObjId n ()
-> (SomeType -> Value) -> FieldParser n (SomeType -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> \case
            SomeType Type k
tp ->
              case Type k
tp of
                P.TList Nullability
P.NonNullable Type k
_ ->
                  Text -> Value
J.String Text
"NON_NULL"
                P.TNamed Nullability
P.NonNullable Definition MetadataObjId (TypeInfo MetadataObjId k)
_ ->
                  Text -> Value
J.String Text
"NON_NULL"
                P.TList Nullability
P.Nullable Type k
_ ->
                  Text -> Value
J.String Text
"LIST"
                P.TNamed Nullability
P.Nullable (P.Definition Name
_ Maybe Description
_ Maybe MetadataObjId
_ [Directive Void]
_ TypeInfo MetadataObjId k
P.TIScalar) ->
                  Text -> Value
J.String Text
"SCALAR"
                P.TNamed Nullability
P.Nullable (P.Definition Name
_ Maybe Description
_ Maybe MetadataObjId
_ [Directive Void]
_ (P.TIEnum NonEmpty (Definition MetadataObjId EnumValueInfo)
_)) ->
                  Text -> Value
J.String Text
"ENUM"
                P.TNamed Nullability
P.Nullable (P.Definition Name
_ Maybe Description
_ Maybe MetadataObjId
_ [Directive Void]
_ (P.TIInputObject InputObjectInfo MetadataObjId
_)) ->
                  Text -> Value
J.String Text
"INPUT_OBJECT"
                P.TNamed Nullability
P.Nullable (P.Definition Name
_ Maybe Description
_ Maybe MetadataObjId
_ [Directive Void]
_ (P.TIObject ObjectInfo MetadataObjId
_)) ->
                  Text -> Value
J.String Text
"OBJECT"
                P.TNamed Nullability
P.Nullable (P.Definition Name
_ Maybe Description
_ Maybe MetadataObjId
_ [Directive Void]
_ (P.TIInterface InterfaceInfo MetadataObjId
_)) ->
                  Text -> Value
J.String Text
"INTERFACE"
                P.TNamed Nullability
P.Nullable (P.Definition Name
_ Maybe Description
_ Maybe MetadataObjId
_ [Directive Void]
_ (P.TIUnion UnionInfo MetadataObjId
_)) ->
                  Text -> Value
J.String Text
"UNION"
      name :: FieldParser n (SomeType -> J.Value)
      name :: FieldParser n (SomeType -> Value)
name =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._name Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
          FieldParser MetadataObjId n ()
-> (SomeType -> Value) -> FieldParser n (SomeType -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> \case
            SomeType Type k
tp ->
              case Type k
tp of
                P.TNamed Nullability
P.Nullable (P.Definition Name
name' Maybe Description
_ Maybe MetadataObjId
_ [Directive Void]
_ TypeInfo MetadataObjId k
_) ->
                  Name -> Value
forall a. HasName a => a -> Value
nameAsJSON Name
name'
                Type k
_ -> Value
J.Null
      description :: FieldParser n (SomeType -> J.Value)
      description :: FieldParser n (SomeType -> Value)
description =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._description Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
          FieldParser MetadataObjId n ()
-> (SomeType -> Value) -> FieldParser n (SomeType -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> \case
            SomeType (P.TNamed Nullability
_ (P.Definition Name
_ (Just Description
desc) Maybe MetadataObjId
_ [Directive Void]
_ TypeInfo MetadataObjId k
_)) ->
              Text -> Value
J.String (Description -> Text
G.unDescription Description
desc)
            SomeType
_ -> Value
J.Null
      fields :: FieldParser n (SomeType -> J.Value)
      fields :: FieldParser n (SomeType -> Value)
fields = do
        -- TODO handle the value of includeDeprecated
        ~(Bool
_includeDeprecated, Definition MetadataObjId (FieldInfo MetadataObjId) -> Value
printer) <- Name
-> Maybe Description
-> InputFieldsParser n Bool
-> Parser
     MetadataObjId
     'Output
     n
     (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
-> FieldParser
     MetadataObjId
     n
     (Bool, Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
forall (m :: * -> *) origin a b.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Output m b
-> FieldParser origin m (a, b)
P.subselection Name
GName._fields Maybe Description
forall a. Maybe a
Nothing InputFieldsParser n Bool
includeDeprecated Parser
  MetadataObjId
  'Output
  n
  (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
forall (n :: * -> *).
MonadParse n =>
Parser
  'Output
  n
  (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
fieldField
        return
          $ \case
            SomeType Type k
tp ->
              case Type k
tp of
                P.TNamed Nullability
P.Nullable (P.Definition Name
_ Maybe Description
_ Maybe MetadataObjId
_ [Directive Void]
_ (P.TIObject (P.ObjectInfo [Definition MetadataObjId (FieldInfo MetadataObjId)]
fields' [Definition MetadataObjId (InterfaceInfo MetadataObjId)]
_interfaces'))) ->
                  Array -> Value
J.Array (Array -> Value) -> Array -> Value
forall a b. (a -> b) -> a -> b
$ [Value] -> Array
forall a. [a] -> Vector a
V.fromList ([Value] -> Array) -> [Value] -> Array
forall a b. (a -> b) -> a -> b
$ Definition MetadataObjId (FieldInfo MetadataObjId) -> Value
printer (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
-> [Definition MetadataObjId (FieldInfo MetadataObjId)] -> [Value]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Definition MetadataObjId (FieldInfo MetadataObjId)]
fields'
                P.TNamed Nullability
P.Nullable (P.Definition Name
_ Maybe Description
_ Maybe MetadataObjId
_ [Directive Void]
_ (P.TIInterface (P.InterfaceInfo [Definition MetadataObjId (FieldInfo MetadataObjId)]
fields' [Definition MetadataObjId (ObjectInfo MetadataObjId)]
_objects'))) ->
                  Array -> Value
J.Array (Array -> Value) -> Array -> Value
forall a b. (a -> b) -> a -> b
$ [Value] -> Array
forall a. [a] -> Vector a
V.fromList ([Value] -> Array) -> [Value] -> Array
forall a b. (a -> b) -> a -> b
$ Definition MetadataObjId (FieldInfo MetadataObjId) -> Value
printer (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
-> [Definition MetadataObjId (FieldInfo MetadataObjId)] -> [Value]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Definition MetadataObjId (FieldInfo MetadataObjId)]
fields'
                Type k
_ -> Value
J.Null
      interfaces :: FieldParser n (SomeType -> J.Value)
      interfaces :: FieldParser n (SomeType -> Value)
interfaces = do
        SomeType -> Value
printer <- Name
-> Maybe Description
-> Parser MetadataObjId 'Output n (SomeType -> Value)
-> FieldParser n (SomeType -> Value)
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Output m a
-> FieldParser origin m a
P.subselection_ Name
GName._interfaces Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Output n (SomeType -> Value)
forall (n :: * -> *).
MonadParse n =>
Parser 'Output n (SomeType -> Value)
typeField
        return
          $ \case
            SomeType Type k
tp ->
              case Type k
tp of
                P.TNamed Nullability
P.Nullable (P.Definition Name
_ Maybe Description
_ Maybe MetadataObjId
_ [Directive Void]
_ (P.TIObject (P.ObjectInfo [Definition MetadataObjId (FieldInfo MetadataObjId)]
_fields' [Definition MetadataObjId (InterfaceInfo MetadataObjId)]
interfaces'))) ->
                  Array -> Value
J.Array (Array -> Value) -> Array -> Value
forall a b. (a -> b) -> a -> b
$ [Value] -> Array
forall a. [a] -> Vector a
V.fromList ([Value] -> Array) -> [Value] -> Array
forall a b. (a -> b) -> a -> b
$ SomeType -> Value
printer (SomeType -> Value)
-> (Definition MetadataObjId (InterfaceInfo MetadataObjId)
    -> SomeType)
-> Definition MetadataObjId (InterfaceInfo MetadataObjId)
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type 'Output -> SomeType
forall (k :: Kind). Type k -> SomeType
SomeType (Type 'Output -> SomeType)
-> (Definition MetadataObjId (InterfaceInfo MetadataObjId)
    -> Type 'Output)
-> Definition MetadataObjId (InterfaceInfo MetadataObjId)
-> SomeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Nullability
-> Definition MetadataObjId (TypeInfo MetadataObjId 'Output)
-> Type 'Output
forall origin (k :: Kind).
Nullability
-> Definition origin (TypeInfo origin k) -> Type origin k
P.TNamed Nullability
P.Nullable (Definition MetadataObjId (TypeInfo MetadataObjId 'Output)
 -> Type 'Output)
-> (Definition MetadataObjId (InterfaceInfo MetadataObjId)
    -> Definition MetadataObjId (TypeInfo MetadataObjId 'Output))
-> Definition MetadataObjId (InterfaceInfo MetadataObjId)
-> Type 'Output
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (InterfaceInfo MetadataObjId -> TypeInfo MetadataObjId 'Output)
-> Definition MetadataObjId (InterfaceInfo MetadataObjId)
-> Definition MetadataObjId (TypeInfo MetadataObjId 'Output)
forall a b.
(a -> b)
-> Definition MetadataObjId a -> Definition MetadataObjId b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap InterfaceInfo MetadataObjId -> TypeInfo MetadataObjId 'Output
forall origin. InterfaceInfo origin -> TypeInfo origin 'Output
P.TIInterface (Definition MetadataObjId (InterfaceInfo MetadataObjId) -> Value)
-> [Definition MetadataObjId (InterfaceInfo MetadataObjId)]
-> [Value]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Definition MetadataObjId (InterfaceInfo MetadataObjId)]
interfaces'
                Type k
_ -> Value
J.Null
      possibleTypes :: FieldParser n (SomeType -> J.Value)
      possibleTypes :: FieldParser n (SomeType -> Value)
possibleTypes = do
        SomeType -> Value
printer <- Name
-> Maybe Description
-> Parser MetadataObjId 'Output n (SomeType -> Value)
-> FieldParser n (SomeType -> Value)
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Output m a
-> FieldParser origin m a
P.subselection_ Name
GName._possibleTypes Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Output n (SomeType -> Value)
forall (n :: * -> *).
MonadParse n =>
Parser 'Output n (SomeType -> Value)
typeField
        return
          $ \case
            SomeType Type k
tp ->
              case Type k
tp of
                P.TNamed Nullability
P.Nullable (P.Definition Name
_ Maybe Description
_ Maybe MetadataObjId
_ [Directive Void]
_ (P.TIInterface (P.InterfaceInfo [Definition MetadataObjId (FieldInfo MetadataObjId)]
_fields' [Definition MetadataObjId (ObjectInfo MetadataObjId)]
objects'))) ->
                  Array -> Value
J.Array (Array -> Value) -> Array -> Value
forall a b. (a -> b) -> a -> b
$ [Value] -> Array
forall a. [a] -> Vector a
V.fromList ([Value] -> Array) -> [Value] -> Array
forall a b. (a -> b) -> a -> b
$ SomeType -> Value
printer (SomeType -> Value)
-> (Definition MetadataObjId (ObjectInfo MetadataObjId)
    -> SomeType)
-> Definition MetadataObjId (ObjectInfo MetadataObjId)
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type 'Output -> SomeType
forall (k :: Kind). Type k -> SomeType
SomeType (Type 'Output -> SomeType)
-> (Definition MetadataObjId (ObjectInfo MetadataObjId)
    -> Type 'Output)
-> Definition MetadataObjId (ObjectInfo MetadataObjId)
-> SomeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Nullability
-> Definition MetadataObjId (TypeInfo MetadataObjId 'Output)
-> Type 'Output
forall origin (k :: Kind).
Nullability
-> Definition origin (TypeInfo origin k) -> Type origin k
P.TNamed Nullability
P.Nullable (Definition MetadataObjId (TypeInfo MetadataObjId 'Output)
 -> Type 'Output)
-> (Definition MetadataObjId (ObjectInfo MetadataObjId)
    -> Definition MetadataObjId (TypeInfo MetadataObjId 'Output))
-> Definition MetadataObjId (ObjectInfo MetadataObjId)
-> Type 'Output
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ObjectInfo MetadataObjId -> TypeInfo MetadataObjId 'Output)
-> Definition MetadataObjId (ObjectInfo MetadataObjId)
-> Definition MetadataObjId (TypeInfo MetadataObjId 'Output)
forall a b.
(a -> b)
-> Definition MetadataObjId a -> Definition MetadataObjId b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ObjectInfo MetadataObjId -> TypeInfo MetadataObjId 'Output
forall origin. ObjectInfo origin -> TypeInfo origin 'Output
P.TIObject (Definition MetadataObjId (ObjectInfo MetadataObjId) -> Value)
-> [Definition MetadataObjId (ObjectInfo MetadataObjId)] -> [Value]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Definition MetadataObjId (ObjectInfo MetadataObjId)]
objects'
                P.TNamed Nullability
P.Nullable (P.Definition Name
_ Maybe Description
_ Maybe MetadataObjId
_ [Directive Void]
_ (P.TIUnion (P.UnionInfo [Definition MetadataObjId (ObjectInfo MetadataObjId)]
objects'))) ->
                  Array -> Value
J.Array (Array -> Value) -> Array -> Value
forall a b. (a -> b) -> a -> b
$ [Value] -> Array
forall a. [a] -> Vector a
V.fromList ([Value] -> Array) -> [Value] -> Array
forall a b. (a -> b) -> a -> b
$ SomeType -> Value
printer (SomeType -> Value)
-> (Definition MetadataObjId (ObjectInfo MetadataObjId)
    -> SomeType)
-> Definition MetadataObjId (ObjectInfo MetadataObjId)
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type 'Output -> SomeType
forall (k :: Kind). Type k -> SomeType
SomeType (Type 'Output -> SomeType)
-> (Definition MetadataObjId (ObjectInfo MetadataObjId)
    -> Type 'Output)
-> Definition MetadataObjId (ObjectInfo MetadataObjId)
-> SomeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Nullability
-> Definition MetadataObjId (TypeInfo MetadataObjId 'Output)
-> Type 'Output
forall origin (k :: Kind).
Nullability
-> Definition origin (TypeInfo origin k) -> Type origin k
P.TNamed Nullability
P.Nullable (Definition MetadataObjId (TypeInfo MetadataObjId 'Output)
 -> Type 'Output)
-> (Definition MetadataObjId (ObjectInfo MetadataObjId)
    -> Definition MetadataObjId (TypeInfo MetadataObjId 'Output))
-> Definition MetadataObjId (ObjectInfo MetadataObjId)
-> Type 'Output
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ObjectInfo MetadataObjId -> TypeInfo MetadataObjId 'Output)
-> Definition MetadataObjId (ObjectInfo MetadataObjId)
-> Definition MetadataObjId (TypeInfo MetadataObjId 'Output)
forall a b.
(a -> b)
-> Definition MetadataObjId a -> Definition MetadataObjId b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ObjectInfo MetadataObjId -> TypeInfo MetadataObjId 'Output
forall origin. ObjectInfo origin -> TypeInfo origin 'Output
P.TIObject (Definition MetadataObjId (ObjectInfo MetadataObjId) -> Value)
-> [Definition MetadataObjId (ObjectInfo MetadataObjId)] -> [Value]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Definition MetadataObjId (ObjectInfo MetadataObjId)]
objects'
                Type k
_ -> Value
J.Null
      enumValues :: FieldParser n (SomeType -> J.Value)
      enumValues :: FieldParser n (SomeType -> Value)
enumValues = do
        -- TODO handle the value of includeDeprecated
        ~(Bool
_includeDeprecated, Definition MetadataObjId EnumValueInfo -> Value
printer) <- Name
-> Maybe Description
-> InputFieldsParser n Bool
-> Parser
     MetadataObjId
     'Output
     n
     (Definition MetadataObjId EnumValueInfo -> Value)
-> FieldParser
     MetadataObjId
     n
     (Bool, Definition MetadataObjId EnumValueInfo -> Value)
forall (m :: * -> *) origin a b.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Output m b
-> FieldParser origin m (a, b)
P.subselection Name
GName._enumValues Maybe Description
forall a. Maybe a
Nothing InputFieldsParser n Bool
includeDeprecated Parser
  MetadataObjId
  'Output
  n
  (Definition MetadataObjId EnumValueInfo -> Value)
forall (n :: * -> *).
MonadParse n =>
Parser 'Output n (Definition MetadataObjId EnumValueInfo -> Value)
enumValue
        return
          $ \case
            SomeType Type k
tp ->
              case Type k
tp of
                P.TNamed Nullability
P.Nullable (P.Definition Name
_ Maybe Description
_ Maybe MetadataObjId
_ [Directive Void]
_ (P.TIEnum NonEmpty (Definition MetadataObjId EnumValueInfo)
vals)) ->
                  Array -> Value
J.Array (Array -> Value) -> Array -> Value
forall a b. (a -> b) -> a -> b
$ [Value] -> Array
forall a. [a] -> Vector a
V.fromList ([Value] -> Array) -> [Value] -> Array
forall a b. (a -> b) -> a -> b
$ (Definition MetadataObjId EnumValueInfo -> Value)
-> [Definition MetadataObjId EnumValueInfo] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Definition MetadataObjId EnumValueInfo -> Value
printer ([Definition MetadataObjId EnumValueInfo] -> [Value])
-> [Definition MetadataObjId EnumValueInfo] -> [Value]
forall a b. (a -> b) -> a -> b
$ NonEmpty (Definition MetadataObjId EnumValueInfo)
-> [Definition MetadataObjId EnumValueInfo]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty (Definition MetadataObjId EnumValueInfo)
vals
                Type k
_ -> Value
J.Null
      inputFields :: FieldParser n (SomeType -> J.Value)
      inputFields :: FieldParser n (SomeType -> Value)
inputFields = do
        Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value
printer <- Name
-> Maybe Description
-> Parser
     MetadataObjId
     'Output
     n
     (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
-> FieldParser
     MetadataObjId
     n
     (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Output m a
-> FieldParser origin m a
P.subselection_ Name
GName._inputFields Maybe Description
forall a. Maybe a
Nothing Parser
  MetadataObjId
  'Output
  n
  (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
forall (n :: * -> *).
MonadParse n =>
Parser
  'Output
  n
  (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
inputValue
        return
          $ \case
            SomeType Type k
tp ->
              case Type k
tp of
                P.TNamed Nullability
P.Nullable (P.Definition Name
_ Maybe Description
_ Maybe MetadataObjId
_ [Directive Void]
_ (P.TIInputObject (P.InputObjectInfo [Definition MetadataObjId (InputFieldInfo MetadataObjId)]
fieldDefs))) ->
                  Array -> Value
J.Array (Array -> Value) -> Array -> Value
forall a b. (a -> b) -> a -> b
$ [Value] -> Array
forall a. [a] -> Vector a
V.fromList ([Value] -> Array) -> [Value] -> Array
forall a b. (a -> b) -> a -> b
$ (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
-> [Definition MetadataObjId (InputFieldInfo MetadataObjId)]
-> [Value]
forall a b. (a -> b) -> [a] -> [b]
map Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value
printer [Definition MetadataObjId (InputFieldInfo MetadataObjId)]
fieldDefs
                Type k
_ -> Value
J.Null
      -- ofType peels modalities off of types
      ofType :: FieldParser n (SomeType -> J.Value)
      ofType :: FieldParser n (SomeType -> Value)
ofType = do
        SomeType -> Value
printer <- Name
-> Maybe Description
-> Parser MetadataObjId 'Output n (SomeType -> Value)
-> FieldParser n (SomeType -> Value)
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Output m a
-> FieldParser origin m a
P.subselection_ Name
GName._ofType Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Output n (SomeType -> Value)
forall (n :: * -> *).
MonadParse n =>
Parser 'Output n (SomeType -> Value)
typeField
        return $ \case
          -- kind = "NON_NULL": !a -> a
          SomeType (P.TNamed Nullability
P.NonNullable Definition MetadataObjId (TypeInfo MetadataObjId k)
x) ->
            SomeType -> Value
printer (SomeType -> Value) -> SomeType -> Value
forall a b. (a -> b) -> a -> b
$ Type MetadataObjId k -> SomeType
forall (k :: Kind). Type k -> SomeType
SomeType (Type MetadataObjId k -> SomeType)
-> Type MetadataObjId k -> SomeType
forall a b. (a -> b) -> a -> b
$ Nullability
-> Definition MetadataObjId (TypeInfo MetadataObjId k)
-> Type MetadataObjId k
forall origin (k :: Kind).
Nullability
-> Definition origin (TypeInfo origin k) -> Type origin k
P.TNamed Nullability
P.Nullable Definition MetadataObjId (TypeInfo MetadataObjId k)
x
          -- kind = "NON_NULL": ![a] -> [a], and ![!a] -> [!a]
          SomeType (P.TList Nullability
P.NonNullable Type MetadataObjId k
x) ->
            SomeType -> Value
printer (SomeType -> Value) -> SomeType -> Value
forall a b. (a -> b) -> a -> b
$ Type MetadataObjId k -> SomeType
forall (k :: Kind). Type k -> SomeType
SomeType (Type MetadataObjId k -> SomeType)
-> Type MetadataObjId k -> SomeType
forall a b. (a -> b) -> a -> b
$ Nullability -> Type MetadataObjId k -> Type MetadataObjId k
forall origin (k :: Kind).
Nullability -> Type origin k -> Type origin k
P.TList Nullability
P.Nullable Type MetadataObjId k
x
          -- kind = "LIST": [a] -> a
          SomeType (P.TList Nullability
P.Nullable Type MetadataObjId k
x) ->
            SomeType -> Value
printer (SomeType -> Value) -> SomeType -> Value
forall a b. (a -> b) -> a -> b
$ Type MetadataObjId k -> SomeType
forall (k :: Kind). Type k -> SomeType
SomeType Type MetadataObjId k
x
          SomeType
_ -> Value
J.Null
   in InsOrdHashMap Name (ParsedSelection (SomeType -> Value))
-> SomeType -> Value
forall a.
InsOrdHashMap Name (ParsedSelection (a -> Value)) -> a -> Value
applyPrinter
        (InsOrdHashMap Name (ParsedSelection (SomeType -> Value))
 -> SomeType -> Value)
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap Name (ParsedSelection (SomeType -> Value)))
-> Parser MetadataObjId 'Output n (SomeType -> Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name
-> Maybe Description
-> [FieldParser n (SomeType -> Value)]
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap Name (ParsedSelection (SomeType -> Value)))
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> [FieldParser origin m a]
-> Parser origin 'Output m (InsOrdHashMap Name (ParsedSelection a))
P.selectionSet
          Name
GName.___Type
          Maybe Description
forall a. Maybe a
Nothing
          [ FieldParser n (SomeType -> Value)
kind,
            FieldParser n (SomeType -> Value)
name,
            FieldParser n (SomeType -> Value)
description,
            FieldParser n (SomeType -> Value)
fields,
            FieldParser n (SomeType -> Value)
interfaces,
            FieldParser n (SomeType -> Value)
possibleTypes,
            FieldParser n (SomeType -> Value)
enumValues,
            FieldParser n (SomeType -> Value)
inputFields,
            FieldParser n (SomeType -> Value)
ofType
          ]

{-
type __InputValue {
  name: String!
  description: String
  type: __Type!
  defaultValue: String
}
-}
inputValue ::
  forall n.
  (MonadParse n) =>
  Parser 'Output n (P.Definition P.InputFieldInfo -> J.Value)
inputValue :: forall (n :: * -> *).
MonadParse n =>
Parser
  'Output
  n
  (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
inputValue =
  let name :: FieldParser n (P.Definition P.InputFieldInfo -> J.Value)
      name :: FieldParser
  n
  (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
name =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._name Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
          FieldParser MetadataObjId n ()
-> (Definition MetadataObjId (InputFieldInfo MetadataObjId)
    -> Value)
-> FieldParser
     n
     (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Name -> Value
forall a. HasName a => a -> Value
nameAsJSON
          (Name -> Value)
-> (Definition MetadataObjId (InputFieldInfo MetadataObjId)
    -> Name)
-> Definition MetadataObjId (InputFieldInfo MetadataObjId)
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Name
forall origin a. Definition origin a -> Name
P.dName
      description :: FieldParser n (P.Definition P.InputFieldInfo -> J.Value)
      description :: FieldParser
  n
  (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
description =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._description Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
          FieldParser MetadataObjId n ()
-> (Definition MetadataObjId (InputFieldInfo MetadataObjId)
    -> Value)
-> FieldParser
     n
     (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Value -> (Description -> Value) -> Maybe Description -> Value
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Value
J.Null (Text -> Value
J.String (Text -> Value) -> (Description -> Text) -> Description -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Description -> Text
G.unDescription)
          (Maybe Description -> Value)
-> (Definition MetadataObjId (InputFieldInfo MetadataObjId)
    -> Maybe Description)
-> Definition MetadataObjId (InputFieldInfo MetadataObjId)
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Definition MetadataObjId (InputFieldInfo MetadataObjId)
-> Maybe Description
forall origin a. Definition origin a -> Maybe Description
P.dDescription
      typeF :: FieldParser n (P.Definition P.InputFieldInfo -> J.Value)
      typeF :: FieldParser
  n
  (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
typeF = do
        SomeType -> Value
printer <- Name
-> Maybe Description
-> Parser MetadataObjId 'Output n (SomeType -> Value)
-> FieldParser MetadataObjId n (SomeType -> Value)
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Output m a
-> FieldParser origin m a
P.subselection_ Name
GName._type Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Output n (SomeType -> Value)
forall (n :: * -> *).
MonadParse n =>
Parser 'Output n (SomeType -> Value)
typeField
        return $ \Definition MetadataObjId (InputFieldInfo MetadataObjId)
defInfo -> case Definition MetadataObjId (InputFieldInfo MetadataObjId)
-> InputFieldInfo MetadataObjId
forall origin a. Definition origin a -> a
P.dInfo Definition MetadataObjId (InputFieldInfo MetadataObjId)
defInfo of
          P.InputFieldInfo Type MetadataObjId k
tp Maybe (Value Void)
_ -> SomeType -> Value
printer (SomeType -> Value) -> SomeType -> Value
forall a b. (a -> b) -> a -> b
$ Type MetadataObjId k -> SomeType
forall (k :: Kind). Type k -> SomeType
SomeType Type MetadataObjId k
tp
      defaultValue :: FieldParser n (P.Definition P.InputFieldInfo -> J.Value)
      defaultValue :: FieldParser
  n
  (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
defaultValue =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._defaultValue Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
          FieldParser MetadataObjId n ()
-> (Definition MetadataObjId (InputFieldInfo MetadataObjId)
    -> Value)
-> FieldParser
     n
     (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> \Definition MetadataObjId (InputFieldInfo MetadataObjId)
defInfo -> case Definition MetadataObjId (InputFieldInfo MetadataObjId)
-> InputFieldInfo MetadataObjId
forall origin a. Definition origin a -> a
P.dInfo Definition MetadataObjId (InputFieldInfo MetadataObjId)
defInfo of
            P.InputFieldInfo Type MetadataObjId k
_ (Just Value Void
val) -> Text -> Value
J.String (Text -> Value) -> Text -> Value
forall a b. (a -> b) -> a -> b
$ Builder -> Text
T.run (Builder -> Text) -> Builder -> Text
forall a b. (a -> b) -> a -> b
$ Value Void -> Builder
forall var a. (Print var, Printer a) => Value var -> a
GP.value Value Void
val
            InputFieldInfo MetadataObjId
_ -> Value
J.Null
   in InsOrdHashMap
  Name
  (ParsedSelection
     (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value))
-> Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value
forall a.
InsOrdHashMap Name (ParsedSelection (a -> Value)) -> a -> Value
applyPrinter
        (InsOrdHashMap
   Name
   (ParsedSelection
      (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value))
 -> Definition MetadataObjId (InputFieldInfo MetadataObjId)
 -> Value)
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap
        Name
        (ParsedSelection
           (Definition MetadataObjId (InputFieldInfo MetadataObjId)
            -> Value)))
-> Parser
     MetadataObjId
     'Output
     n
     (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name
-> Maybe Description
-> [FieldParser
      n
      (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)]
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap
        Name
        (ParsedSelection
           (Definition MetadataObjId (InputFieldInfo MetadataObjId)
            -> Value)))
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> [FieldParser origin m a]
-> Parser origin 'Output m (InsOrdHashMap Name (ParsedSelection a))
P.selectionSet
          Name
GName.___InputValue
          Maybe Description
forall a. Maybe a
Nothing
          [ FieldParser
  n
  (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
name,
            FieldParser
  n
  (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
description,
            FieldParser
  n
  (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
typeF,
            FieldParser
  n
  (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
defaultValue
          ]

{-
type __EnumValue {
  name: String!
  description: String
  isDeprecated: Boolean!
  deprecationReason: String
}
-}
enumValue ::
  forall n.
  (MonadParse n) =>
  Parser 'Output n (P.Definition P.EnumValueInfo -> J.Value)
enumValue :: forall (n :: * -> *).
MonadParse n =>
Parser 'Output n (Definition MetadataObjId EnumValueInfo -> Value)
enumValue =
  let name :: FieldParser n (P.Definition P.EnumValueInfo -> J.Value)
      name :: FieldParser n (Definition MetadataObjId EnumValueInfo -> Value)
name =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._name Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
          FieldParser MetadataObjId n ()
-> (Definition MetadataObjId EnumValueInfo -> Value)
-> FieldParser n (Definition MetadataObjId EnumValueInfo -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Name -> Value
forall a. HasName a => a -> Value
nameAsJSON
          (Name -> Value)
-> (Definition MetadataObjId EnumValueInfo -> Name)
-> Definition MetadataObjId EnumValueInfo
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Definition MetadataObjId EnumValueInfo -> Name
forall origin a. Definition origin a -> Name
P.dName
      description :: FieldParser n (P.Definition P.EnumValueInfo -> J.Value)
      description :: FieldParser n (Definition MetadataObjId EnumValueInfo -> Value)
description =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._description Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
          FieldParser MetadataObjId n ()
-> (Definition MetadataObjId EnumValueInfo -> Value)
-> FieldParser n (Definition MetadataObjId EnumValueInfo -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Value -> (Description -> Value) -> Maybe Description -> Value
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Value
J.Null (Text -> Value
J.String (Text -> Value) -> (Description -> Text) -> Description -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Description -> Text
G.unDescription)
          (Maybe Description -> Value)
-> (Definition MetadataObjId EnumValueInfo -> Maybe Description)
-> Definition MetadataObjId EnumValueInfo
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Definition MetadataObjId EnumValueInfo -> Maybe Description
forall origin a. Definition origin a -> Maybe Description
P.dDescription
      -- TODO We don't seem to support enum value deprecation
      isDeprecated :: FieldParser n (P.Definition P.EnumValueInfo -> J.Value)
      isDeprecated :: FieldParser n (Definition MetadataObjId EnumValueInfo -> Value)
isDeprecated =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._isDeprecated Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
          FieldParser MetadataObjId n ()
-> (Definition MetadataObjId EnumValueInfo -> Value)
-> FieldParser n (Definition MetadataObjId EnumValueInfo -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Value -> Definition MetadataObjId EnumValueInfo -> Value
forall a b. a -> b -> a
const (Bool -> Value
J.Bool Bool
False)
      deprecationReason :: FieldParser n (P.Definition P.EnumValueInfo -> J.Value)
      deprecationReason :: FieldParser n (Definition MetadataObjId EnumValueInfo -> Value)
deprecationReason =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._deprecationReason Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
          FieldParser MetadataObjId n ()
-> (Definition MetadataObjId EnumValueInfo -> Value)
-> FieldParser n (Definition MetadataObjId EnumValueInfo -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Value -> Definition MetadataObjId EnumValueInfo -> Value
forall a b. a -> b -> a
const Value
J.Null
   in InsOrdHashMap
  Name
  (ParsedSelection (Definition MetadataObjId EnumValueInfo -> Value))
-> Definition MetadataObjId EnumValueInfo -> Value
forall a.
InsOrdHashMap Name (ParsedSelection (a -> Value)) -> a -> Value
applyPrinter
        (InsOrdHashMap
   Name
   (ParsedSelection (Definition MetadataObjId EnumValueInfo -> Value))
 -> Definition MetadataObjId EnumValueInfo -> Value)
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap
        Name
        (ParsedSelection
           (Definition MetadataObjId EnumValueInfo -> Value)))
-> Parser
     MetadataObjId
     'Output
     n
     (Definition MetadataObjId EnumValueInfo -> Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name
-> Maybe Description
-> [FieldParser
      n (Definition MetadataObjId EnumValueInfo -> Value)]
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap
        Name
        (ParsedSelection
           (Definition MetadataObjId EnumValueInfo -> Value)))
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> [FieldParser origin m a]
-> Parser origin 'Output m (InsOrdHashMap Name (ParsedSelection a))
P.selectionSet
          Name
GName.___EnumValue
          Maybe Description
forall a. Maybe a
Nothing
          [ FieldParser n (Definition MetadataObjId EnumValueInfo -> Value)
name,
            FieldParser n (Definition MetadataObjId EnumValueInfo -> Value)
description,
            FieldParser n (Definition MetadataObjId EnumValueInfo -> Value)
isDeprecated,
            FieldParser n (Definition MetadataObjId EnumValueInfo -> Value)
deprecationReason
          ]

{-
enum __TypeKind {
  ENUM
  INPUT_OBJECT
  INTERFACE
  LIST
  NON_NULL
  OBJECT
  SCALAR
  UNION
}
-}
typeKind ::
  forall n.
  (MonadParse n) =>
  Parser 'Both n ()
typeKind :: forall (n :: * -> *). MonadParse n => Parser 'Both n ()
typeKind =
  Name
-> Maybe Description
-> NonEmpty (Definition MetadataObjId EnumValueInfo, ())
-> Parser MetadataObjId 'Both n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> NonEmpty (Definition origin EnumValueInfo, a)
-> Parser origin 'Both m a
P.enum
    Name
GName.___TypeKind
    Maybe Description
forall a. Maybe a
Nothing
    ( [(Definition MetadataObjId EnumValueInfo, ())]
-> NonEmpty (Definition MetadataObjId EnumValueInfo, ())
forall a. HasCallStack => [a] -> NonEmpty a
NE.fromList
        [ Name -> (Definition MetadataObjId EnumValueInfo, ())
forall {origin}. Name -> (Definition origin EnumValueInfo, ())
mkDefinition Name
GName._ENUM,
          Name -> (Definition MetadataObjId EnumValueInfo, ())
forall {origin}. Name -> (Definition origin EnumValueInfo, ())
mkDefinition Name
GName._INPUT_OBJECT,
          Name -> (Definition MetadataObjId EnumValueInfo, ())
forall {origin}. Name -> (Definition origin EnumValueInfo, ())
mkDefinition Name
GName._INTERFACE,
          Name -> (Definition MetadataObjId EnumValueInfo, ())
forall {origin}. Name -> (Definition origin EnumValueInfo, ())
mkDefinition Name
GName._LIST,
          Name -> (Definition MetadataObjId EnumValueInfo, ())
forall {origin}. Name -> (Definition origin EnumValueInfo, ())
mkDefinition Name
GName._NON_NULL,
          Name -> (Definition MetadataObjId EnumValueInfo, ())
forall {origin}. Name -> (Definition origin EnumValueInfo, ())
mkDefinition Name
GName._OBJECT,
          Name -> (Definition MetadataObjId EnumValueInfo, ())
forall {origin}. Name -> (Definition origin EnumValueInfo, ())
mkDefinition Name
GName._SCALAR,
          Name -> (Definition MetadataObjId EnumValueInfo, ())
forall {origin}. Name -> (Definition origin EnumValueInfo, ())
mkDefinition Name
GName._UNION
        ]
    )
  where
    mkDefinition :: Name -> (Definition origin EnumValueInfo, ())
mkDefinition Name
name = (Name
-> Maybe Description
-> Maybe origin
-> [Directive Void]
-> EnumValueInfo
-> Definition origin EnumValueInfo
forall origin a.
Name
-> Maybe Description
-> Maybe origin
-> [Directive Void]
-> a
-> Definition origin a
P.Definition Name
name Maybe Description
forall a. Maybe a
Nothing Maybe origin
forall a. Maybe a
Nothing [] EnumValueInfo
P.EnumValueInfo, ())

{-
type __Field {
  name: String!
  description: String
  args: [__InputValue!]!
  type: __Type!
  isDeprecated: Boolean!
  deprecationReason: String
}
-}
fieldField ::
  forall n.
  (MonadParse n) =>
  Parser 'Output n (P.Definition P.FieldInfo -> J.Value)
fieldField :: forall (n :: * -> *).
MonadParse n =>
Parser
  'Output
  n
  (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
fieldField =
  let name :: FieldParser n (P.Definition P.FieldInfo -> J.Value)
      name :: FieldParser
  n (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
name =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._name Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
          FieldParser MetadataObjId n ()
-> (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
-> FieldParser
     n (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Name -> Value
forall a. HasName a => a -> Value
nameAsJSON
          (Name -> Value)
-> (Definition MetadataObjId (FieldInfo MetadataObjId) -> Name)
-> Definition MetadataObjId (FieldInfo MetadataObjId)
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Definition MetadataObjId (FieldInfo MetadataObjId) -> Name
forall origin a. Definition origin a -> Name
P.dName
      description :: FieldParser n (P.Definition P.FieldInfo -> J.Value)
      description :: FieldParser
  n (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
description =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._description Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string FieldParser MetadataObjId n ()
-> (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
-> FieldParser
     n (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> \Definition MetadataObjId (FieldInfo MetadataObjId)
defInfo ->
          case Definition MetadataObjId (FieldInfo MetadataObjId)
-> Maybe Description
forall origin a. Definition origin a -> Maybe Description
P.dDescription Definition MetadataObjId (FieldInfo MetadataObjId)
defInfo of
            Maybe Description
Nothing -> Value
J.Null
            Just Description
desc -> Text -> Value
J.String (Description -> Text
G.unDescription Description
desc)
      args :: FieldParser n (P.Definition P.FieldInfo -> J.Value)
      args :: FieldParser
  n (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
args = do
        Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value
printer <- Name
-> Maybe Description
-> Parser
     MetadataObjId
     'Output
     n
     (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
-> FieldParser
     MetadataObjId
     n
     (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Output m a
-> FieldParser origin m a
P.subselection_ Name
GName._args Maybe Description
forall a. Maybe a
Nothing Parser
  MetadataObjId
  'Output
  n
  (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
forall (n :: * -> *).
MonadParse n =>
Parser
  'Output
  n
  (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
inputValue
        return $ Array -> Value
J.Array (Array -> Value)
-> (Definition MetadataObjId (FieldInfo MetadataObjId) -> Array)
-> Definition MetadataObjId (FieldInfo MetadataObjId)
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Value] -> Array
forall a. [a] -> Vector a
V.fromList ([Value] -> Array)
-> (Definition MetadataObjId (FieldInfo MetadataObjId) -> [Value])
-> Definition MetadataObjId (FieldInfo MetadataObjId)
-> Array
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
-> [Definition MetadataObjId (InputFieldInfo MetadataObjId)]
-> [Value]
forall a b. (a -> b) -> [a] -> [b]
map Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value
printer ([Definition MetadataObjId (InputFieldInfo MetadataObjId)]
 -> [Value])
-> (Definition MetadataObjId (FieldInfo MetadataObjId)
    -> [Definition MetadataObjId (InputFieldInfo MetadataObjId)])
-> Definition MetadataObjId (FieldInfo MetadataObjId)
-> [Value]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Name)
-> [Definition MetadataObjId (InputFieldInfo MetadataObjId)]
-> [Definition MetadataObjId (InputFieldInfo MetadataObjId)]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Name
forall origin a. Definition origin a -> Name
P.dName ([Definition MetadataObjId (InputFieldInfo MetadataObjId)]
 -> [Definition MetadataObjId (InputFieldInfo MetadataObjId)])
-> (Definition MetadataObjId (FieldInfo MetadataObjId)
    -> [Definition MetadataObjId (InputFieldInfo MetadataObjId)])
-> Definition MetadataObjId (FieldInfo MetadataObjId)
-> [Definition MetadataObjId (InputFieldInfo MetadataObjId)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldInfo MetadataObjId
-> [Definition MetadataObjId (InputFieldInfo MetadataObjId)]
forall origin.
FieldInfo origin -> [Definition origin (InputFieldInfo origin)]
P.fArguments (FieldInfo MetadataObjId
 -> [Definition MetadataObjId (InputFieldInfo MetadataObjId)])
-> (Definition MetadataObjId (FieldInfo MetadataObjId)
    -> FieldInfo MetadataObjId)
-> Definition MetadataObjId (FieldInfo MetadataObjId)
-> [Definition MetadataObjId (InputFieldInfo MetadataObjId)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Definition MetadataObjId (FieldInfo MetadataObjId)
-> FieldInfo MetadataObjId
forall origin a. Definition origin a -> a
P.dInfo
      typeF :: FieldParser n (P.Definition P.FieldInfo -> J.Value)
      typeF :: FieldParser
  n (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
typeF = do
        SomeType -> Value
printer <- Name
-> Maybe Description
-> Parser MetadataObjId 'Output n (SomeType -> Value)
-> FieldParser MetadataObjId n (SomeType -> Value)
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Output m a
-> FieldParser origin m a
P.subselection_ Name
GName._type Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Output n (SomeType -> Value)
forall (n :: * -> *).
MonadParse n =>
Parser 'Output n (SomeType -> Value)
typeField
        return $ SomeType -> Value
printer (SomeType -> Value)
-> (Definition MetadataObjId (FieldInfo MetadataObjId) -> SomeType)
-> Definition MetadataObjId (FieldInfo MetadataObjId)
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\case P.FieldInfo [Definition MetadataObjId (InputFieldInfo MetadataObjId)]
_ Type MetadataObjId k
tp -> Type MetadataObjId k -> SomeType
forall (k :: Kind). Type k -> SomeType
SomeType Type MetadataObjId k
tp) (FieldInfo MetadataObjId -> SomeType)
-> (Definition MetadataObjId (FieldInfo MetadataObjId)
    -> FieldInfo MetadataObjId)
-> Definition MetadataObjId (FieldInfo MetadataObjId)
-> SomeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Definition MetadataObjId (FieldInfo MetadataObjId)
-> FieldInfo MetadataObjId
forall origin a. Definition origin a -> a
P.dInfo
      -- TODO We don't seem to track deprecation info
      isDeprecated :: FieldParser n (P.Definition P.FieldInfo -> J.Value)
      isDeprecated :: FieldParser
  n (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
isDeprecated =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._isDeprecated Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
          FieldParser MetadataObjId n ()
-> (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
-> FieldParser
     n (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Value
-> Definition MetadataObjId (FieldInfo MetadataObjId) -> Value
forall a b. a -> b -> a
const (Bool -> Value
J.Bool Bool
False)
      deprecationReason :: FieldParser n (P.Definition P.FieldInfo -> J.Value)
      deprecationReason :: FieldParser
  n (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
deprecationReason =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._deprecationReason Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
          FieldParser MetadataObjId n ()
-> (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
-> FieldParser
     n (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Value
-> Definition MetadataObjId (FieldInfo MetadataObjId) -> Value
forall a b. a -> b -> a
const Value
J.Null
   in InsOrdHashMap
  Name
  (ParsedSelection
     (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value))
-> Definition MetadataObjId (FieldInfo MetadataObjId) -> Value
forall a.
InsOrdHashMap Name (ParsedSelection (a -> Value)) -> a -> Value
applyPrinter
        (InsOrdHashMap
   Name
   (ParsedSelection
      (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value))
 -> Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap
        Name
        (ParsedSelection
           (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)))
-> Parser
     MetadataObjId
     'Output
     n
     (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name
-> Maybe Description
-> [FieldParser
      n (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)]
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap
        Name
        (ParsedSelection
           (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)))
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> [FieldParser origin m a]
-> Parser origin 'Output m (InsOrdHashMap Name (ParsedSelection a))
P.selectionSet
          Name
GName.___Field
          Maybe Description
forall a. Maybe a
Nothing
          [ FieldParser
  n (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
name,
            FieldParser
  n (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
description,
            FieldParser
  n (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
args,
            FieldParser
  n (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
typeF,
            FieldParser
  n (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
isDeprecated,
            FieldParser
  n (Definition MetadataObjId (FieldInfo MetadataObjId) -> Value)
deprecationReason
          ]

{-
type __Directive {
  name: String!
  description: String
  locations: [__DirectiveLocation!]!
  args: [__InputValue!]!
  isRepeatable: Boolean!
}
-}

directiveSet ::
  forall n.
  (MonadParse n) =>
  Parser 'Output n (P.DirectiveInfo -> J.Value)
directiveSet :: forall (n :: * -> *).
MonadParse n =>
Parser 'Output n (DirectiveInfo -> Value)
directiveSet =
  let name :: FieldParser n (P.DirectiveInfo -> J.Value)
      name :: FieldParser n (DirectiveInfo -> Value)
name =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._name Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
          FieldParser MetadataObjId n ()
-> (DirectiveInfo -> Value)
-> FieldParser n (DirectiveInfo -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> (Name -> Value
forall a. ToJSON a => a -> Value
J.toOrdered (Name -> Value)
-> (DirectiveInfo -> Name) -> DirectiveInfo -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DirectiveInfo -> Name
forall origin. DirectiveInfo origin -> Name
P.diName)
      description :: FieldParser n (P.DirectiveInfo -> J.Value)
      description :: FieldParser n (DirectiveInfo -> Value)
description =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._description Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
          FieldParser MetadataObjId n ()
-> (DirectiveInfo -> Value)
-> FieldParser n (DirectiveInfo -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> (Maybe Description -> Value
forall a. ToJSON a => a -> Value
J.toOrdered (Maybe Description -> Value)
-> (DirectiveInfo -> Maybe Description) -> DirectiveInfo -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DirectiveInfo -> Maybe Description
forall origin. DirectiveInfo origin -> Maybe Description
P.diDescription)
      locations :: FieldParser n (P.DirectiveInfo -> J.Value)
      locations :: FieldParser n (DirectiveInfo -> Value)
locations =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._locations Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
          FieldParser MetadataObjId n ()
-> (DirectiveInfo -> Value)
-> FieldParser n (DirectiveInfo -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ([Text] -> Value
forall a. ToJSON a => a -> Value
J.toOrdered ([Text] -> Value)
-> (DirectiveInfo -> [Text]) -> DirectiveInfo -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DirectiveLocation -> Text) -> [DirectiveLocation] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map DirectiveLocation -> Text
showDirLoc ([DirectiveLocation] -> [Text])
-> (DirectiveInfo -> [DirectiveLocation])
-> DirectiveInfo
-> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DirectiveInfo -> [DirectiveLocation]
forall origin. DirectiveInfo origin -> [DirectiveLocation]
P.diLocations)
      args :: FieldParser n (P.DirectiveInfo -> J.Value)
      args :: FieldParser n (DirectiveInfo -> Value)
args = do
        Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value
printer <- Name
-> Maybe Description
-> Parser
     MetadataObjId
     'Output
     n
     (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
-> FieldParser
     MetadataObjId
     n
     (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Output m a
-> FieldParser origin m a
P.subselection_ Name
GName._args Maybe Description
forall a. Maybe a
Nothing Parser
  MetadataObjId
  'Output
  n
  (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
forall (n :: * -> *).
MonadParse n =>
Parser
  'Output
  n
  (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
inputValue
        pure $ [Value] -> Value
J.array ([Value] -> Value)
-> (DirectiveInfo -> [Value]) -> DirectiveInfo -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value)
-> [Definition MetadataObjId (InputFieldInfo MetadataObjId)]
-> [Value]
forall a b. (a -> b) -> [a] -> [b]
map Definition MetadataObjId (InputFieldInfo MetadataObjId) -> Value
printer ([Definition MetadataObjId (InputFieldInfo MetadataObjId)]
 -> [Value])
-> (DirectiveInfo
    -> [Definition MetadataObjId (InputFieldInfo MetadataObjId)])
-> DirectiveInfo
-> [Value]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DirectiveInfo
-> [Definition MetadataObjId (InputFieldInfo MetadataObjId)]
forall origin.
DirectiveInfo origin -> [Definition origin (InputFieldInfo origin)]
P.diArguments
      isRepeatable :: FieldParser n (P.DirectiveInfo -> J.Value)
      isRepeatable :: FieldParser n (DirectiveInfo -> Value)
isRepeatable =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._isRepeatable Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
          FieldParser MetadataObjId n ()
-> (DirectiveInfo -> Value)
-> FieldParser n (DirectiveInfo -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Value -> DirectiveInfo -> Value
forall a b. a -> b -> a
const Value
J.Null
   in InsOrdHashMap Name (ParsedSelection (DirectiveInfo -> Value))
-> DirectiveInfo -> Value
forall a.
InsOrdHashMap Name (ParsedSelection (a -> Value)) -> a -> Value
applyPrinter
        (InsOrdHashMap Name (ParsedSelection (DirectiveInfo -> Value))
 -> DirectiveInfo -> Value)
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap Name (ParsedSelection (DirectiveInfo -> Value)))
-> Parser MetadataObjId 'Output n (DirectiveInfo -> Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name
-> Maybe Description
-> [FieldParser n (DirectiveInfo -> Value)]
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap Name (ParsedSelection (DirectiveInfo -> Value)))
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> [FieldParser origin m a]
-> Parser origin 'Output m (InsOrdHashMap Name (ParsedSelection a))
P.selectionSet
          Name
GName.___Directive
          Maybe Description
forall a. Maybe a
Nothing
          [ FieldParser n (DirectiveInfo -> Value)
name,
            FieldParser n (DirectiveInfo -> Value)
description,
            FieldParser n (DirectiveInfo -> Value)
locations,
            FieldParser n (DirectiveInfo -> Value)
args,
            FieldParser n (DirectiveInfo -> Value)
isRepeatable
          ]
  where
    showDirLoc :: G.DirectiveLocation -> Text
    showDirLoc :: DirectiveLocation -> Text
showDirLoc = \case
      G.DLExecutable ExecutableDirectiveLocation
edl -> String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Int -> String -> String
forall a. Int -> [a] -> [a]
drop Int
3 (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ ExecutableDirectiveLocation -> String
forall a. Show a => a -> String
show ExecutableDirectiveLocation
edl
      G.DLTypeSystem TypeSystemDirectiveLocation
tsdl -> String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Int -> String -> String
forall a. Int -> [a] -> [a]
drop Int
4 (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ TypeSystemDirectiveLocation -> String
forall a. Show a => a -> String
show TypeSystemDirectiveLocation
tsdl

{-
type __Schema {
  description: String
  types: [__Type!]!
  queryType: __Type!
  mutationType: __Type
  subscriptionType: __Type
  directives: [__Directive!]!
}
-}
schemaSet ::
  forall n.
  (MonadParse n) =>
  Parser 'Output n (Schema -> J.Value)
{-# INLINE schemaSet #-}
schemaSet :: forall (n :: * -> *).
MonadParse n =>
Parser 'Output n (Schema -> Value)
schemaSet =
  let description :: FieldParser n (Schema -> J.Value)
      description :: FieldParser n (Schema -> Value)
description =
        Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Text
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
GName._description Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Text
P.string
          FieldParser MetadataObjId n ()
-> (Schema -> Value) -> FieldParser n (Schema -> Value)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> \Schema
partialSchema -> case Schema -> Maybe Description
forall origin. Schema origin -> Maybe Description
sDescription Schema
partialSchema of
            Maybe Description
Nothing -> Value
J.Null
            Just Description
s -> Text -> Value
J.String (Text -> Value) -> Text -> Value
forall a b. (a -> b) -> a -> b
$ Description -> Text
G.unDescription Description
s
      types :: FieldParser n (Schema -> J.Value)
      types :: FieldParser n (Schema -> Value)
types = do
        SomeType -> Value
printer <- Name
-> Maybe Description
-> Parser MetadataObjId 'Output n (SomeType -> Value)
-> FieldParser MetadataObjId n (SomeType -> Value)
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Output m a
-> FieldParser origin m a
P.subselection_ Name
GName._types Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Output n (SomeType -> Value)
forall (n :: * -> *).
MonadParse n =>
Parser 'Output n (SomeType -> Value)
typeField
        return
          $ \Schema
partialSchema ->
            Array -> Value
J.Array
              (Array -> Value) -> Array -> Value
forall a b. (a -> b) -> a -> b
$ [Value] -> Array
forall a. [a] -> Vector a
V.fromList
              ([Value] -> Array) -> [Value] -> Array
forall a b. (a -> b) -> a -> b
$ (SomeDefinitionTypeInfo MetadataObjId -> Value)
-> [SomeDefinitionTypeInfo MetadataObjId] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map (SomeType -> Value
printer (SomeType -> Value)
-> (SomeDefinitionTypeInfo MetadataObjId -> SomeType)
-> SomeDefinitionTypeInfo MetadataObjId
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SomeDefinitionTypeInfo MetadataObjId -> SomeType
schemaTypeToSomeType)
              ([SomeDefinitionTypeInfo MetadataObjId] -> [Value])
-> [SomeDefinitionTypeInfo MetadataObjId] -> [Value]
forall a b. (a -> b) -> a -> b
$ (SomeDefinitionTypeInfo MetadataObjId -> Name)
-> [SomeDefinitionTypeInfo MetadataObjId]
-> [SomeDefinitionTypeInfo MetadataObjId]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn SomeDefinitionTypeInfo MetadataObjId -> Name
forall a. HasName a => a -> Name
P.getName
              ([SomeDefinitionTypeInfo MetadataObjId]
 -> [SomeDefinitionTypeInfo MetadataObjId])
-> [SomeDefinitionTypeInfo MetadataObjId]
-> [SomeDefinitionTypeInfo MetadataObjId]
forall a b. (a -> b) -> a -> b
$ HashMap Name (SomeDefinitionTypeInfo MetadataObjId)
-> [SomeDefinitionTypeInfo MetadataObjId]
forall k v. HashMap k v -> [v]
HashMap.elems
              (HashMap Name (SomeDefinitionTypeInfo MetadataObjId)
 -> [SomeDefinitionTypeInfo MetadataObjId])
-> HashMap Name (SomeDefinitionTypeInfo MetadataObjId)
-> [SomeDefinitionTypeInfo MetadataObjId]
forall a b. (a -> b) -> a -> b
$ Schema -> HashMap Name (SomeDefinitionTypeInfo MetadataObjId)
forall origin.
Schema origin -> HashMap Name (SomeDefinitionTypeInfo origin)
sTypes Schema
partialSchema
        where
          schemaTypeToSomeType :: P.SomeDefinitionTypeInfo -> SomeType
          schemaTypeToSomeType :: SomeDefinitionTypeInfo MetadataObjId -> SomeType
schemaTypeToSomeType (P.SomeDefinitionTypeInfo Definition MetadataObjId (TypeInfo MetadataObjId k)
def) =
            Type k -> SomeType
forall (k :: Kind). Type k -> SomeType
SomeType (Type k -> SomeType) -> Type k -> SomeType
forall a b. (a -> b) -> a -> b
$ Nullability
-> Definition MetadataObjId (TypeInfo MetadataObjId k) -> Type k
forall origin (k :: Kind).
Nullability
-> Definition origin (TypeInfo origin k) -> Type origin k
P.TNamed Nullability
P.Nullable Definition MetadataObjId (TypeInfo MetadataObjId k)
def
      queryType :: FieldParser n (Schema -> J.Value)
      queryType :: FieldParser n (Schema -> Value)
queryType = do
        SomeType -> Value
printer <- Name
-> Maybe Description
-> Parser MetadataObjId 'Output n (SomeType -> Value)
-> FieldParser MetadataObjId n (SomeType -> Value)
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Output m a
-> FieldParser origin m a
P.subselection_ Name
GName._queryType Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Output n (SomeType -> Value)
forall (n :: * -> *).
MonadParse n =>
Parser 'Output n (SomeType -> Value)
typeField
        return $ \Schema
partialSchema -> SomeType -> Value
printer (SomeType -> Value) -> SomeType -> Value
forall a b. (a -> b) -> a -> b
$ Type 'Output -> SomeType
forall (k :: Kind). Type k -> SomeType
SomeType (Type 'Output -> SomeType) -> Type 'Output -> SomeType
forall a b. (a -> b) -> a -> b
$ Schema -> Type 'Output
forall origin. Schema origin -> Type origin 'Output
sQueryType Schema
partialSchema
      mutationType :: FieldParser n (Schema -> J.Value)
      mutationType :: FieldParser n (Schema -> Value)
mutationType = do
        SomeType -> Value
printer <- Name
-> Maybe Description
-> Parser MetadataObjId 'Output n (SomeType -> Value)
-> FieldParser MetadataObjId n (SomeType -> Value)
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Output m a
-> FieldParser origin m a
P.subselection_ Name
GName._mutationType Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Output n (SomeType -> Value)
forall (n :: * -> *).
MonadParse n =>
Parser 'Output n (SomeType -> Value)
typeField
        return $ \Schema
partialSchema -> case Schema -> Maybe (Type 'Output)
forall origin. Schema origin -> Maybe (Type origin 'Output)
sMutationType Schema
partialSchema of
          Maybe (Type 'Output)
Nothing -> Value
J.Null
          Just Type 'Output
tp -> SomeType -> Value
printer (SomeType -> Value) -> SomeType -> Value
forall a b. (a -> b) -> a -> b
$ Type 'Output -> SomeType
forall (k :: Kind). Type k -> SomeType
SomeType Type 'Output
tp
      subscriptionType :: FieldParser n (Schema -> J.Value)
      subscriptionType :: FieldParser n (Schema -> Value)
subscriptionType = do
        SomeType -> Value
printer <- Name
-> Maybe Description
-> Parser MetadataObjId 'Output n (SomeType -> Value)
-> FieldParser MetadataObjId n (SomeType -> Value)
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Output m a
-> FieldParser origin m a
P.subselection_ Name
GName._subscriptionType Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Output n (SomeType -> Value)
forall (n :: * -> *).
MonadParse n =>
Parser 'Output n (SomeType -> Value)
typeField
        return $ \Schema
partialSchema -> case Schema -> Maybe (Type 'Output)
forall origin. Schema origin -> Maybe (Type origin 'Output)
sSubscriptionType Schema
partialSchema of
          Maybe (Type 'Output)
Nothing -> Value
J.Null
          Just Type 'Output
tp -> SomeType -> Value
printer (SomeType -> Value) -> SomeType -> Value
forall a b. (a -> b) -> a -> b
$ Type 'Output -> SomeType
forall (k :: Kind). Type k -> SomeType
SomeType Type 'Output
tp
      directives :: FieldParser n (Schema -> J.Value)
      directives :: FieldParser n (Schema -> Value)
directives = do
        DirectiveInfo -> Value
printer <- Name
-> Maybe Description
-> Parser MetadataObjId 'Output n (DirectiveInfo -> Value)
-> FieldParser MetadataObjId n (DirectiveInfo -> Value)
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Output m a
-> FieldParser origin m a
P.subselection_ Name
GName._directives Maybe Description
forall a. Maybe a
Nothing Parser MetadataObjId 'Output n (DirectiveInfo -> Value)
forall (n :: * -> *).
MonadParse n =>
Parser 'Output n (DirectiveInfo -> Value)
directiveSet
        return $ \Schema
partialSchema -> [Value] -> Value
J.array ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$ (DirectiveInfo -> Value) -> [DirectiveInfo] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map DirectiveInfo -> Value
printer ([DirectiveInfo] -> [Value]) -> [DirectiveInfo] -> [Value]
forall a b. (a -> b) -> a -> b
$ Schema -> [DirectiveInfo]
forall origin. Schema origin -> [DirectiveInfo origin]
sDirectives Schema
partialSchema
   in InsOrdHashMap Name (ParsedSelection (Schema -> Value))
-> Schema -> Value
forall a.
InsOrdHashMap Name (ParsedSelection (a -> Value)) -> a -> Value
applyPrinter
        (InsOrdHashMap Name (ParsedSelection (Schema -> Value))
 -> Schema -> Value)
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap Name (ParsedSelection (Schema -> Value)))
-> Parser MetadataObjId 'Output n (Schema -> Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name
-> Maybe Description
-> [FieldParser n (Schema -> Value)]
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap Name (ParsedSelection (Schema -> Value)))
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> [FieldParser origin m a]
-> Parser origin 'Output m (InsOrdHashMap Name (ParsedSelection a))
P.selectionSet
          Name
GName.___Schema
          Maybe Description
forall a. Maybe a
Nothing
          [ FieldParser n (Schema -> Value)
description,
            FieldParser n (Schema -> Value)
types,
            FieldParser n (Schema -> Value)
queryType,
            FieldParser n (Schema -> Value)
mutationType,
            FieldParser n (Schema -> Value)
subscriptionType,
            FieldParser n (Schema -> Value)
directives
          ]

selectionSetToJSON ::
  InsOrdHashMap.InsOrdHashMap G.Name J.Value ->
  J.Value
selectionSetToJSON :: InsOrdHashMap Name Value -> Value
selectionSetToJSON = [(Text, Value)] -> Value
J.object ([(Text, Value)] -> Value)
-> (InsOrdHashMap Name Value -> [(Text, Value)])
-> InsOrdHashMap Name Value
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Name, Value) -> (Text, Value))
-> [(Name, Value)] -> [(Text, Value)]
forall a b. (a -> b) -> [a] -> [b]
map ((Name -> Text) -> (Name, Value) -> (Text, Value)
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first Name -> Text
G.unName) ([(Name, Value)] -> [(Text, Value)])
-> (InsOrdHashMap Name Value -> [(Name, Value)])
-> InsOrdHashMap Name Value
-> [(Text, Value)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InsOrdHashMap Name Value -> [(Name, Value)]
forall k v. InsOrdHashMap k v -> [(k, v)]
InsOrdHashMap.toList

applyPrinter ::
  InsOrdHashMap.InsOrdHashMap G.Name (P.ParsedSelection (a -> J.Value)) ->
  a ->
  J.Value
applyPrinter :: forall a.
InsOrdHashMap Name (ParsedSelection (a -> Value)) -> a -> Value
applyPrinter = (a -> InsOrdHashMap Name (ParsedSelection (a -> Value)) -> Value)
-> InsOrdHashMap Name (ParsedSelection (a -> Value)) -> a -> Value
forall a b c. (a -> b -> c) -> b -> a -> c
flip (\a
x -> InsOrdHashMap Name Value -> Value
selectionSetToJSON (InsOrdHashMap Name Value -> Value)
-> (InsOrdHashMap Name (ParsedSelection (a -> Value))
    -> InsOrdHashMap Name Value)
-> InsOrdHashMap Name (ParsedSelection (a -> Value))
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ParsedSelection (a -> Value) -> Value)
-> InsOrdHashMap Name (ParsedSelection (a -> Value))
-> InsOrdHashMap Name Value
forall a b.
(a -> b) -> InsOrdHashMap Name a -> InsOrdHashMap Name b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (((a -> Value) -> a -> Value
forall a b. (a -> b) -> a -> b
$ a
x) ((a -> Value) -> Value)
-> (ParsedSelection (a -> Value) -> a -> Value)
-> ParsedSelection (a -> Value)
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Name -> a -> Value) -> ParsedSelection (a -> Value) -> a -> Value
forall a. (Name -> a) -> ParsedSelection a -> a
P.handleTypename (Value -> a -> Value
forall a b. a -> b -> a
const (Value -> a -> Value) -> (Name -> Value) -> Name -> a -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> Value
forall a. HasName a => a -> Value
nameAsJSON)))

nameAsJSON :: (P.HasName a) => a -> J.Value
nameAsJSON :: forall a. HasName a => a -> Value
nameAsJSON = Text -> Value
J.String (Text -> Value) -> (a -> Text) -> a -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> Text
G.unName (Name -> Text) -> (a -> Name) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Name
forall a. HasName a => a -> Name
P.getName