Repository: hasura/graphql-engine
File: server/src-lib/Hasura/GraphQL/Schema.hs (Haskell)

Code before:
      Just (a, b) -> (Just a, Just b)
      Nothing     -> (Nothing, Nothing)

    -- the types for all enums that are /referenced/ by this table (not /defined/ by this table;
    -- there isn’t actually any need to generate a GraphQL enum type for an enum table if it’s
    -- never referenced anywhere else)
    referencedEnumTypes =
      let allColumnInfos =
               (selPermM ^.. _Just._2.traverse._SFPGColumn)
            <> (insPermM ^. _Just._1)
            <> (updColsM ^. _Just)
          allEnumReferences = allColumnInfos ^.. traverse.to pgiType._PGColumnEnumReference
      in flip map allEnumReferences $ \enumReference@(EnumReference referencedTableName _) ->
           let typeName = mkTableEnumType referencedTableName
           in TIEnum $ mkHsraEnumTyInfo Nothing typeName (EnumValuesReference enumReference)


    -- computed fields function args input objects
    mkComputedFieldRequiredTypes computedFieldInfo =
      let ComputedFieldFunction qf inputArgs _ _ = _cfFunction computedFieldInfo
          scalarArgs = map (_qptName . faType) $ toList inputArgs
      in (, scalarArgs) <$> mkFuncArgsInp qf inputArgs

    (computedFieldFuncArgsInps, computedFieldFuncArgScalars) =
      (map TIInpObj *** (Set.fromList . concat)) $ unzip $ catMaybes $
      maybe [] (map mkComputedFieldRequiredTypes . getComputedFields) selFldsM

getRootFldsRole'
  :: QualifiedTable
  -> [PGColumnInfo]
  -> [ConstraintName]
  -> FieldInfoMap PGColumnInfo
  -> [FunctionInfo]
  -> Maybe ([T.Text], Bool) -- insert perm
  -> Maybe (AnnBoolExpPartialSQL, Maybe Int, [T.Text], Bool) -- select filter
  -> Maybe ([PGColumnInfo], PreSetColsPartial, AnnBoolExpPartialSQL, [T.Text]) -- update filter
  -> Maybe (AnnBoolExpPartialSQL, [T.Text]) -- delete filter
  -> Maybe ViewInfo
  -> TableConfig -- custom config
  -> RootFields
getRootFldsRole' tn primCols constraints fields funcs insM
                 selM updM delM viM tableConfig =
  RootFields
    { rootQueryFields = makeFieldMap
        $  funcQueries
        <> funcAggQueries
        <> catMaybes
          [ getSelDet <$> selM
          , getSelAggDet selM
          , getPKeySelDet selM primCols
          ]

Review comment (suggestion):
This is personal preference, but I’d really probably just give the result of the `unzip` call a name so you can use it twice to define `computedFieldFuncArgsInps` and `computedFieldFuncArgScalars` instead of needing to use `(***)`, since there’s a lot going on in this expression!

Code after:
      Just (a, b) -> (Just a, Just b)
      Nothing     -> (Nothing, Nothing)

    -- the types for all enums that are /referenced/ by this table (not /defined/ by this table;
    -- there isn’t actually any need to generate a GraphQL enum type for an enum table if it’s
    -- never referenced anywhere else)
    referencedEnumTypes =
      let allColumnInfos =
               (selPermM ^.. _Just._2.traverse._SFPGColumn)
            <> (insPermM ^. _Just._1)
            <> (updColsM ^. _Just)
          allEnumReferences = allColumnInfos ^.. traverse.to pgiType._PGColumnEnumReference
      in flip map allEnumReferences $ \enumReference@(EnumReference referencedTableName _) ->
           let typeName = mkTableEnumType referencedTableName
           in TIEnum $ mkHsraEnumTyInfo Nothing typeName (EnumValuesReference enumReference)


    -- computed fields' function args input objects and scalar types
    mkComputedFieldRequiredTypes computedFieldInfo =
      let ComputedFieldFunction qf inputArgs _ _ = _cfFunction computedFieldInfo
          scalarArgs = map (_qptName . faType) $ toList inputArgs
      in (, scalarArgs) <$> mkFuncArgsInp qf inputArgs

    computedFieldReqTypes = catMaybes $
      maybe [] (map mkComputedFieldRequiredTypes . getComputedFields) selFldsM

    computedFieldFuncArgsInps = map (TIInpObj . fst) computedFieldReqTypes
    computedFieldFuncArgScalars = Set.fromList $ concatMap snd computedFieldReqTypes

getRootFldsRole'
  :: QualifiedTable
  -> [PGColumnInfo]
  -> [ConstraintName]
  -> FieldInfoMap PGColumnInfo
  -> [FunctionInfo]
  -> Maybe ([T.Text], Bool) -- insert perm
  -> Maybe (AnnBoolExpPartialSQL, Maybe Int, [T.Text], Bool) -- select filter
  -> Maybe ([PGColumnInfo], PreSetColsPartial, AnnBoolExpPartialSQL, [T.Text]) -- update filter
  -> Maybe (AnnBoolExpPartialSQL, [T.Text]) -- delete filter
  -> Maybe ViewInfo
  -> TableConfig -- custom config
  -> RootFields
getRootFldsRole' tn primCols constraints fields funcs insM
                 selM updM delM viM tableConfig =
  RootFields
    { rootQueryFields = makeFieldMap
        $  funcQueries
        <> funcAggQueries
        <> catMaybes
          [ getSelDet <$> selM
          , getSelAggDet selM