Cleanup post #3810

### Description

#3810 was merged with comments still open; this small PR does a few minute clean-ups to address some remaining nits.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3941
GitOrigin-RevId: 3d15eb399828123640a73247b848bc4ddff02c38
This commit is contained in:
Antoine Leblanc 2022-03-10 02:12:53 +00:00 committed by hasura-bot
parent 553ecf628b
commit 85b8753fde
3 changed files with 18 additions and 18 deletions

View File

@ -14,7 +14,7 @@ module Data.HashMap.Strict.NonEmpty
(!?),
keys,
-- * Compose
-- * Combine
unionWith,
-- * Transformations

View File

@ -8,7 +8,7 @@ module Hasura.GraphQL.Execute.RemoteJoin.Collect
)
where
import Control.Lens (Traversal', preview, (^?), _2)
import Control.Lens (Traversal', preview, _2)
import Control.Monad.Writer
import Data.HashMap.Strict qualified as Map
import Data.HashMap.Strict.InsOrd qualified as OMap
@ -532,6 +532,15 @@ transformActionFields fields = do
in Just (a, annotatedColumn)
in (fmap snd annotatedJoinColumns, phantomFields_)
-- | Constructs a 'JoinColumnAlias' for a given field in a selection set.
--
-- If the field was already requested, we leave it unchanged, to avoid
-- double-fetching the same information. However, if this field is a "phantom"
-- field, that we only add for the purpose of fetching a join key, we rename it
-- in a way that is guaranteed to avoid conflicts.
--
-- NOTE: if the @fieldName@ argument is a valid GraphQL name, then the
-- constructed alias MUST also be a valid GraphQL name.
getJoinColumnAlias ::
(Eq field, Hashable field) =>
FieldName ->
@ -549,7 +558,7 @@ getJoinColumnAlias fieldName field selectedFields allAliases =
--
-- If we generate a unique name for each field name which is longer than
-- the longest alias in the selection set, the generated name would be
-- unique
-- unique.
uniqueAlias :: FieldName
uniqueAlias =
let suffix =
@ -668,8 +677,12 @@ transformObjectSelectionSet typename selectionSet = do
annotateLHSJoinField fieldName lhsJoinField =
let columnAlias =
getJoinColumnAlias fieldName lhsJoinField noArgsGraphQLFields allAliases
-- This alias is generated in 'getJoinColumnAlias', and is guaranteed
-- to be a valid GraphQLName.
columnGraphQLName =
G.unsafeMkName $ getFieldNameTxt $ getAliasFieldName columnAlias
in ( mkGraphQLField
(Just $ G.unsafeMkName $ getFieldNameTxt $ getAliasFieldName columnAlias)
(Just columnGraphQLName)
lhsJoinField
mempty
mempty
@ -679,7 +692,7 @@ transformObjectSelectionSet typename selectionSet = do
(joinColumnAliases, phantomFields) =
let lhsJoinFields =
Map.unions $ map _srrsLHSJoinFields $ mapMaybe (^? _FieldRemote) $ toList selectionSet
Map.unions $ map _srrsLHSJoinFields $ mapMaybe (preview _FieldRemote) $ toList selectionSet
annotatedJoinColumns = Map.mapWithKey annotateLHSJoinField lhsJoinFields
in (fmap snd annotatedJoinColumns, fmap fst annotatedJoinColumns)

View File

@ -17,15 +17,12 @@ import Hasura.GraphQL.Parser.Internal.Parser qualified as P
import Hasura.GraphQL.Parser.Schema
import Hasura.GraphQL.Parser.TestUtils
import Hasura.GraphQL.RemoteServer (identityCustomizer)
import Hasura.GraphQL.Schema.Common
import Hasura.GraphQL.Schema.Remote
import Hasura.Prelude
import Hasura.RQL.IR.RemoteSchema
import Hasura.RQL.IR.Root
import Hasura.RQL.Types.RemoteSchema
import Hasura.RQL.Types.SchemaCache
import Hasura.RQL.Types.Source
import Hasura.RQL.Types.SourceCustomization
import Hasura.Session
import Language.GraphQL.Draft.Parser qualified as G
import Language.GraphQL.Draft.Syntax qualified as G
@ -107,16 +104,6 @@ buildQueryParsers ::
buildQueryParsers introspection = do
let introResult = IntrospectionResult introspection $$(G.litName "Query") Nothing Nothing
remoteSchemaInfo = RemoteSchemaInfo (ValidatedRemoteSchemaDef N.nullURI [] False 60 Nothing) identityCustomizer
sourceContext =
-- without relationships to sources, this won't be evaluated
( adminRoleName :: RoleName,
mempty :: SourceCache,
undefined :: QueryContext,
mempty :: CustomizeRemoteFieldName,
mempty :: RemoteSchemaMap,
mempty :: MkTypename,
mempty :: MkRootFieldName
)
ParsedIntrospection query _ _ <-
runError $
buildRemoteParser introResult remoteSchemaInfo