-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remote relationships v2 #6060
Open
lirishatayal
wants to merge
292
commits into
master
Choose a base branch
from
remote-relationships-v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Remote relationships v2 #6060
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…emote_rel_input_types Update schema cache with remote rel input types
…phase Remote relationship generation phase
Tests need updating.
Running http server on 127.0.0.1:5000 ================================================= test session starts ================================================= platform linux -- Python 3.5.3, pytest-4.6.2, py-1.8.0, pluggy-0.12.0 -- /usr/bin/python3 cachedir: .pytest_cache rootdir: /home/chris/Work/hasura/graphql-engine/server/tests-py, inifile: pytest.ini plugins: forked-1.0.2, xdist-1.28.0 [gw0] linux Python 3.5.3 cwd: /home/chris/Work/hasura/graphql-engine/server/tests-py [gw0] Python 3.5.3 (default, Sep 27 2018, 17:25:39) -- [GCC 6.3.0 20170516] gw0 [6] scheduling tests via LoadFileScheduling test_remotes.py::TestTopLevelMixedFields::test_create_valid[http] [gw0] [ 16%] PASSED test_remotes.py::TestTopLevelMixedFields::test_create_valid[http] test_remotes.py::TestTopLevelMixedFields::test_create_valid[websocket] [gw0] [ 33%] PASSED test_remotes.py::TestTopLevelMixedFields::test_create_valid[websocket] test_remotes.py::TestTopLevelMixedFields::test_generation[http] [gw0] [ 50%] PASSED test_remotes.py::TestTopLevelMixedFields::test_generation[http] test_remotes.py::TestTopLevelMixedFields::test_generation[websocket] [gw0] [ 66%] PASSED test_remotes.py::TestTopLevelMixedFields::test_generation[websocket] test_remotes.py::TestTopLevelMixedFields::test_create_invalid[http] [gw0] [ 83%] PASSED test_remotes.py::TestTopLevelMixedFields::test_create_invalid[http] test_remotes.py::TestTopLevelMixedFields::test_create_invalid[websocket] [gw0] [100%] PASSED test_remotes.py::TestTopLevelMixedFields::test_create_invalid[websocket] ================================================== warnings summary =================================================== /usr/local/lib/python3.5/dist-packages/sqlalchemy/util/langhelpers.py:225 /usr/local/lib/python3.5/dist-packages/sqlalchemy/util/langhelpers.py:225: SADeprecationWarning: The 'postgres' dialect name has been renamed to 'postgresql' loader = self.auto_fn(name) -- Docs: https://docs.pytest.org/en/latest/warnings.html ======================================== 6 passed, 1 warnings in 9.24 seconds =========================================
Nested fields
Tentative commit.
…graphql-engine into issue-188
Limitations:- -> Mixing of top level fields with remote schema and postgres queries is not allowed (currently enforced in master) -> Remote joins are not possible via websockets. Resolve Conflicts: .circleci/server-builder.dockerfile cli/commands/migrate_test.go scripts/dev.sh server/Makefile server/graphql-engine.cabal server/src-lib/Data/Aeson/Ordered.hs server/src-lib/Hasura/Db.hs server/src-lib/Hasura/EncJSON.hs server/src-lib/Hasura/GraphQL/Execute.hs server/src-lib/Hasura/GraphQL/Explain.hs server/src-lib/Hasura/GraphQL/RemoteServer.hs server/src-lib/Hasura/GraphQL/Resolve/BoolExp.hs server/src-lib/Hasura/GraphQL/Resolve/Context.hs server/src-lib/Hasura/GraphQL/Resolve/Select.hs server/src-lib/Hasura/GraphQL/Resolve/Types.hs server/src-lib/Hasura/GraphQL/Schema.hs server/src-lib/Hasura/GraphQL/Schema/BoolExp.hs server/src-lib/Hasura/GraphQL/Schema/Common.hs server/src-lib/Hasura/GraphQL/Schema/OrderBy.hs server/src-lib/Hasura/GraphQL/Schema/Select.hs server/src-lib/Hasura/GraphQL/Transport/HTTP.hs server/src-lib/Hasura/GraphQL/Transport/WebSocket.hs server/src-lib/Hasura/GraphQL/Utils.hs server/src-lib/Hasura/GraphQL/Validate/Types.hs server/src-lib/Hasura/Prelude.hs server/src-lib/Hasura/RQL/DDL/Metadata.hs server/src-lib/Hasura/RQL/DDL/Relationship.hs server/src-lib/Hasura/RQL/DDL/Relationship/Types.hs server/src-lib/Hasura/RQL/DDL/RemoteSchema.hs server/src-lib/Hasura/RQL/DDL/Schema/Cache.hs server/src-lib/Hasura/RQL/DDL/Schema/Table.hs server/src-lib/Hasura/RQL/DML/Select.hs server/src-lib/Hasura/RQL/DML/Select/Internal.hs server/src-lib/Hasura/RQL/GBoolExp.hs server/src-lib/Hasura/RQL/Types.hs server/src-lib/Hasura/RQL/Types/Catalog.hs server/src-lib/Hasura/RQL/Types/Metadata.hs server/src-lib/Hasura/RQL/Types/RemoteSchema.hs server/src-lib/Hasura/RQL/Types/SchemaCache.hs server/src-lib/Hasura/RQL/Types/SchemaCacheTypes.hs server/src-lib/Hasura/SQL/Types.hs server/src-lib/Hasura/Server/Migrate/Version.hs server/src-lib/Hasura/Server/Query.hs server/src-lib/Hasura/Server/Telemetry.hs server/src-rsr/catalog_metadata.sql server/src-rsr/hdb_metadata.yaml server/src-rsr/migrations/25_to_26.sql server/tests-py/queries/v1/metadata/clear_metadata.yaml server/tests-py/queries/v1/metadata/export_metadata.yaml server/tests-py/validate.py
Resolve Conflicts: server/src-lib/Hasura/Server/Migrate/Version.hs
…elationships tests
…graphql-engine into remote-relationships-v2
Beep boop! 🤖 Hey @lirishatayal, thanks for your PR! One of my human friends will review this PR and get back to you as soon as possible. Stay awesome! 😎 |
Deploy preview for hasura-docs ready! Built with commit 3b78c79 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
module Hasura.GraphQL.Remote.Input
( substituteVariables
, SubstituteError(..)
, RemoteArguments(..)
) where
import Data.Aeson (FromJSON(..),ToJSON(..))
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Types as Aeson
import Data.Foldable
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HM
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as M
import Data.Scientific (floatingOrInteger)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Validation
import qualified Language.GraphQL.Draft.Syntax as GraphQL
import Language.Haskell.TH.Syntax (Lift)
import Prelude
-- Type definitions
newtype RemoteArguments =
RemoteArguments
{ getRemoteArguments :: [GraphQL.ObjectFieldG GraphQL.Value]
} deriving (Show, Eq, Lift)
instance ToJSON RemoteArguments where
toJSON = error "TODO: ToJSON: RemoteArguments"
instance FromJSON RemoteArguments where
parseJSON = parseRemoteArguments
-- | An error substituting variables into the argument list.
data SubstituteError
= ValueNotProvided !GraphQL.Variable
deriving (Show, Eq)
-- Operations
-- | Substitute values in the argument list.
substituteVariables ::
Map GraphQL.Variable GraphQL.ValueConst
-- ^ Values to use.
-> [GraphQL.ObjectFieldG GraphQL.Value]
-- ^ A template.
-> Validation [SubstituteError] [GraphQL.ObjectFieldG GraphQL.ValueConst]
substituteVariables values = traverse (traverse go)
where
go =
\case
GraphQL.VVariable variable ->
case M.lookup variable values of
Nothing -> Failure [ValueNotProvided variable]
Just valueConst -> pure valueConst
GraphQL.VInt int32 -> pure (GraphQL.VCInt int32)
GraphQL.VFloat double -> pure (GraphQL.VCFloat double)
GraphQL.VString stringValue -> pure (GraphQL.VCString stringValue)
GraphQL.VBoolean bool -> pure (GraphQL.VCBoolean bool)
GraphQL.VNull -> pure GraphQL.VCNull
GraphQL.VEnum enumValue -> pure (GraphQL.VCEnum enumValue)
GraphQL.VList (GraphQL.ListValueG listValue) ->
fmap (GraphQL.VCList . GraphQL.ListValueG) (traverse go listValue)
GraphQL.VObject (GraphQL.ObjectValueG objectValue) ->
fmap (GraphQL.VCObject . GraphQL.ObjectValueG) (traverse (traverse go) objectValue)
-- Parsing GraphQL input arguments from JSON
parseRemoteArguments :: Aeson.Value -> Aeson.Parser RemoteArguments
parseRemoteArguments j =
case j of
Aeson.Object hashMap -> fmap RemoteArguments (parseObjectFields hashMap)
_ -> fail "Remote arguments should be an object of keys."
parseObjectFields :: HashMap Text Aeson.Value -> Aeson.Parser [GraphQL.ObjectFieldG GraphQL.Value]
parseObjectFields hashMap =
traverse
((key, value) -> do
name <- parseJSON (Aeson.String key)
parsedValue <- parseValue value
pure GraphQL.ObjectFieldG {_ofName = name, _ofValue = parsedValue})
(HM.toList hashMap)
parseValue :: Aeson.Value -> Aeson.Parser GraphQL.Value
parseValue =
\case
Aeson.Object object ->
fmap (GraphQL.VObject . GraphQL.ObjectValueG) (parseObjectFields object)
Aeson.Array array ->
fmap (GraphQL.VList . GraphQL.ListValueG . toList) (traverse parseValue array)
Aeson.String text ->
case T.uncons text of
Just ('$', rest)
| T.null rest -> fail "Invalid variable name."
| otherwise -> pure (GraphQL.VVariable (GraphQL.Variable (GraphQL.Name rest)))
_ -> pure (GraphQL.VString (GraphQL.StringValue text))
Aeson.Number !scientific ->
pure (either GraphQL.VFloat GraphQL.VInt (floatingOrInteger scientific))
Aeson.Bool !bool -> pure (GraphQL.VBoolean bool)
Aeson.Null -> pure GraphQL.VNull