Skip to content

Commit

Permalink
server: remove GraphQL.Utils
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 90639f9
  • Loading branch information
Antoine Leblanc authored and hasura-bot committed Jan 26, 2021
1 parent 62a3bb0 commit 353859d
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 91 deletions.
1 change: 0 additions & 1 deletion server/graphql-engine.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ library
, Hasura.GraphQL.Transport.WebSocket
, Hasura.GraphQL.Transport.WebSocket.Protocol
, Hasura.GraphQL.Transport.WebSocket.Server
, Hasura.GraphQL.Utils
, Hasura.Incremental.Internal.Cache
, Hasura.Incremental.Internal.Dependency
, Hasura.Incremental.Internal.Rule
Expand Down
28 changes: 13 additions & 15 deletions server/src-lib/Hasura/GraphQL/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,36 @@ import Hasura.Prelude
import qualified Data.Aeson as J
import qualified Data.Environment as Env
import qualified Data.HashMap.Strict as Map

import qualified Data.HashSet as HS
import qualified Language.GraphQL.Draft.Syntax as G
import qualified Network.HTTP.Client as HTTP
import qualified Network.HTTP.Types as HTTP
import qualified Network.Wai.Extended as Wai

import Hasura.EncJSON
import Hasura.GraphQL.Parser.Column (UnpreparedValue)
import Hasura.GraphQL.RemoteServer (execRemoteGQ)
import Hasura.GraphQL.Transport.HTTP.Protocol
import Hasura.GraphQL.Utils (showName)
import Hasura.Metadata.Class
import Hasura.RQL.Types
import Hasura.Server.Version (HasVersion)
import Hasura.Session
import Data.Text.Extended

import qualified Hasura.GraphQL.Context as C
import qualified Hasura.GraphQL.Execute.Action as EA
import qualified Hasura.GraphQL.Execute.Inline as EI

import qualified Hasura.GraphQL.Execute.LiveQuery as EL
import qualified Hasura.GraphQL.Execute.Mutation as EM
-- import qualified Hasura.GraphQL.Execute.Plan as EP
import qualified Hasura.GraphQL.Execute.Action as EA
import qualified Hasura.GraphQL.Execute.Prepare as EPr
import qualified Hasura.GraphQL.Execute.Query as EQ
import qualified Hasura.GraphQL.Execute.Types as ET

import qualified Hasura.Logging as L
import qualified Hasura.Server.Telemetry.Counters as Telem
import qualified Hasura.Tracing as Tracing

import Hasura.EncJSON
import Hasura.GraphQL.Parser.Column (UnpreparedValue)
import Hasura.GraphQL.RemoteServer (execRemoteGQ)
import Hasura.GraphQL.Transport.HTTP.Protocol
import Hasura.Metadata.Class
import Hasura.RQL.Types
import Hasura.Server.Version (HasVersion)
import Hasura.Session



type QueryParts = G.TypedOperationDefinition G.FragmentSpread G.Name

Expand Down Expand Up @@ -152,7 +150,7 @@ getExecPlanPartial userInfo sc queryType req =
let n = _unOperationName opName
opDefM = find (\opDef -> G._todName opDef == Just n) opDefs
onNothing opDefM $ throw400 ValidationFailed $
"no such operation found in the document: " <> showName n
"no such operation found in the document: " <> dquote n
(Just _, _, _) ->
throw400 ValidationFailed $ "operationName cannot be used when " <>
"an anonymous operation exists in the document"
Expand Down
3 changes: 1 addition & 2 deletions server/src-lib/Hasura/GraphQL/Execute/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import Hasura.Backends.Postgres.Translate.Select (asSingleRowJsonRes
import Hasura.EncJSON
import Hasura.GraphQL.Execute.Prepare
import Hasura.GraphQL.Parser
import Hasura.GraphQL.Utils (showNames)
import Hasura.HTTP
import Hasura.Metadata.Class
import Hasura.RQL.DDL.Headers
Expand Down Expand Up @@ -516,7 +515,7 @@ callWebhook env manager outputType outputFields reqHeaders confHeaders
-- Fields not specified in the output type shouldn't be present in the response
let extraFields = filter (not . flip Map.member outputFields) $ Map.keys obj
unless (null extraFields) $ throwUnexpected $
"unexpected fields in webhook response: " <> showNames extraFields
"unexpected fields in webhook response: " <> commaSeparated extraFields

void $ flip Map.traverseWithKey outputFields $ \fieldName fieldTy ->
-- When field is non-nullable, it has to present in the response with no null value
Expand Down
4 changes: 2 additions & 2 deletions server/src-lib/Hasura/GraphQL/Parser/Collect.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Language.GraphQL.Draft.Syntax
import Data.Text.Extended
import Hasura.GraphQL.Parser.Class
import Hasura.GraphQL.Parser.Schema
import Hasura.GraphQL.Utils (showNames)


-- | Collects the effective set of fields queried by a selection set by
-- flattening fragments and merging duplicate fields.
Expand Down Expand Up @@ -153,7 +153,7 @@ flattenSelectionSet objectTypeNames boolParser = fmap concat . traverse flattenS
Nothing -> pure ()
Just duplicatedDirectives -> parseError
$ "the following directives are used more than once: "
<> showNames duplicatedDirectives
<> commaSeparated duplicatedDirectives

-- | Merges fields according to the rules in the GraphQL specification, specifically
-- <§ 5.3.2 Field Selection Merging http://spec.graphql.org/June2018/#sec-Field-Selection-Merging>.
Expand Down
64 changes: 0 additions & 64 deletions server/src-lib/Hasura/GraphQL/Utils.hs

This file was deleted.

5 changes: 2 additions & 3 deletions server/src-lib/Hasura/RQL/DDL/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import Data.Text.Extended

import Hasura.Backends.Postgres.SQL.Types
import Hasura.EncJSON
import Hasura.GraphQL.Utils
import Hasura.Metadata.Class
import Hasura.RQL.DDL.CustomTypes (lookupPGScalar)
import Hasura.RQL.Types
Expand Down Expand Up @@ -105,14 +104,14 @@ resolveAction env AnnotatedCustomTypes{..} ActionDefinition{..} allPGScalars = d
pure nonObjectType
| otherwise ->
throw400 InvalidParams $
"the type: " <> showName argumentBaseType
"the type: " <> dquote argumentBaseType
<> " is not defined in custom types or it is not a scalar/enum/input_object"

-- Check if the response type is an object
let outputType = unGraphQLType _adOutputType
outputBaseType = G.getBaseType outputType
outputObject <- onNothing (Map.lookup outputBaseType _actObjects) $
throw400 NotExists $ "the type: " <> showName outputBaseType
throw400 NotExists $ "the type: " <> dquote outputBaseType
<> " is not an object type defined in custom types"
resolvedWebhook <- resolveWebhook env _adHandler
pure ( ActionDefinition resolvedArguments _adOutputType _adType
Expand Down
6 changes: 3 additions & 3 deletions server/src-lib/Hasura/RQL/DDL/Metadata/Generator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import Test.QuickCheck.Instances.Time ()
import Test.QuickCheck.Instances.UnorderedContainers ()

import Hasura.Backends.Postgres.SQL.Types
import Hasura.GraphQL.Utils (simpleGraphQLQuery)
import Hasura.RQL.DDL.Headers
import Hasura.RQL.DDL.Metadata.Types
import Hasura.RQL.Types


genMetadata :: Gen Metadata
genMetadata =
Metadata
Expand Down Expand Up @@ -205,11 +205,11 @@ instance Arbitrary AddRemoteSchemaQuery where
-- FIXME:- The GraphQL AST has 'Gen' by Hedgehog testing package which lacks the
-- 'Arbitrary' class implementation. For time being, a single query is generated every time.
instance Arbitrary GQLQueryWithText where
arbitrary = pure $ GQLQueryWithText ( simpleGraphQLQuery
arbitrary = pure $ GQLQueryWithText ( "query {author {id name}}"
, GQLQuery simpleQuery
)
where
simpleQuery = $(either (fail . T.unpack) TH.lift $ G.parseExecutableDoc simpleGraphQLQuery)
simpleQuery = $(either (fail . T.unpack) TH.lift $ G.parseExecutableDoc "query {author {id name}}")

instance Arbitrary ListedQuery where
arbitrary = genericArbitrary
Expand Down
10 changes: 9 additions & 1 deletion server/src-lib/Hasura/RQL/DDL/RemoteRelationship/Validate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import Data.Text.Extended
import Hasura.Backends.Postgres.SQL.Types
import Hasura.GraphQL.Parser.Column
import Hasura.GraphQL.Schema.Remote
import Hasura.GraphQL.Utils (getBaseTyWithNestedLevelsCount)
import Hasura.RQL.Types
import Hasura.SQL.Types

Expand Down Expand Up @@ -470,3 +469,12 @@ columnInfoToNamedType pci =
case pgiType pci of
ColumnScalar scalarType -> getPGScalarTypeName scalarType
_ -> throwError UnsupportedEnum

getBaseTyWithNestedLevelsCount :: G.GType -> (G.Name, Int)
getBaseTyWithNestedLevelsCount ty = go ty 0
where
go :: G.GType -> Int -> (G.Name, Int)
go gType ctr =
case gType of
G.TypeNamed _ n -> (n, ctr)
G.TypeList _ gType' -> go gType' (ctr + 1)

0 comments on commit 353859d

Please sign in to comment.