Skip to content
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 relationship create api #2850

Conversation

tirumaraiselvan
Copy link
Contributor

@tirumaraiselvan tirumaraiselvan commented Sep 9, 2019

Description

Independent PR for Remote Joins (excludes execution)

Affected components

  • Server

Todo

  • Create API
  • Delete API
  • Update API
  • Schema generation
  • Migrations
  • Metadata

@netlify
Copy link

netlify bot commented Sep 9, 2019

Deploy preview for hasura-docs ready!

Built with commit c933b35

https://deploy-preview-2850--hasura-docs.netlify.com

@tirumaraiselvan tirumaraiselvan force-pushed the add-remote-relationship-no-op branch from 9676a16 to e7a23cd Compare September 17, 2019 13:49
@tirumaraiselvan tirumaraiselvan changed the title wip remote relationship create api remote relationship create api Sep 17, 2019
@hasura-bot
Copy link
Contributor

Review app for commit e7a23cd deployed to Heroku: https://hge-ci-pull-2850.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2850-e7a23cd9

@jberryman
Copy link
Collaborator

This seems fine, but it would be wonderful if we could get documentation on all exported functions and data types.

Is there anything specifically you think could use more review/attention?

@tirumaraiselvan
Copy link
Contributor Author

This seems fine, but it would be wonderful if we could get documentation on all exported functions and data types.

Is there anything specifically you think could use more review/attention?

  1. remote relationship create api #2850 (comment)
  2. Can we do some other general cleanup to reduce nesting etc?

nizar-m and others added 4 commits September 18, 2019 20:34
2) Run a GraphQL server per test thread
3) GraphQL proxy which sets a prefix to the types and top-level fields of the schema, and thus can be added a remote.
@hasura-bot
Copy link
Contributor

Review app for commit 1ddd4f2 deployed to Heroku: https://hge-ci-pull-2850.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2850-1ddd4f23

@tirumaraiselvan tirumaraiselvan force-pushed the add-remote-relationship-no-op branch from 21b9153 to dc35557 Compare September 24, 2019 09:52
@hasura-bot
Copy link
Contributor

Review app for commit dc35557 deployed to Heroku: https://hge-ci-pull-2850.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2850-dc355577

@tirumaraiselvan tirumaraiselvan force-pushed the add-remote-relationship-no-op branch from dc35557 to 6343d00 Compare September 24, 2019 10:34
@hasura-bot
Copy link
Contributor

Review app for commit 6343d00 deployed to Heroku: https://hge-ci-pull-2850.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2850-6343d00a

@tirumaraiselvan tirumaraiselvan force-pushed the add-remote-relationship-no-op branch from 6343d00 to 88427cb Compare September 24, 2019 11:35
Tests for creation of remote relationships  (close #60)
@@ -61,6 +61,7 @@ library
, wai
, postgresql-binary
, process
, validation
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

monad-validate might remove some boilerplate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried doing this and TBH it didn't make much of a difference. So just leaving this as is atm.

@hasura-bot
Copy link
Contributor

Review app for commit 6443125 deployed to Heroku: https://hge-ci-pull-2850.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2850-64431252

jberryman
jberryman previously approved these changes Sep 24, 2019
@jberryman
Copy link
Collaborator

@nizar-m Would you mind giving a quick summary of how the new test framework works, and what it can do?

Also is there any part in particular that you'd like closer review on?

@nizar-m
Copy link
Contributor

nizar-m commented Sep 25, 2019

@nizar-m Would you mind giving a quick summary of how the new test framework works, and what it can do?

Also is there any part in particular that you'd like closer review on?

1) Use Hasura GraphQL Engine as remote
What we were initially planning to do was running another Hasura GraphQL engine as a remote GraphQL server and attach that as remote. This way we can test with a very rich remote GraphQL schema with much lesser amount of configuration. So now, before any test, we will have to setup the remote Hasura GraphQL engine, which would be an extra configuration setup.

Then it evolved to why not create a proxy to GraphQL server which will add prefixes to the top-level fields of operations (query, mutation, subscription), and to the names of all object, input object and enum types. Then add this proxy as remote itself. That way we do not have to create another remote Hasura GraphQL engine, and so the current test configuration would work.

The implementation of the prefixer proxy is in tests-py/gql_prefixer_proxy.py. In tests-py/graphql_server.py this proxy is linked to the path /graphql-prefixer-proxy. So now as remote GraphQL servers, we have those that are implemented in Graphene, plus this proxy.

1.1) Cascade effect 1: Separate remote GraphQL servers for each test thread
The GraphQL remote server is dependent on GraphQL engine now, which is different for the different parallel test threads. So separate remote GrapQL servers are required for each test thread, which should run on different ports. So we should generate a list of ports equal to the number of parallel threads and assign these ports to the remote servers of each thread (in conftest.py ).

Fixture remote_gql_server handles the setup of the remote graphql server. Factory fixture remote_get_url provides the full URL when the path to the remote schema is provided.

1.2) Cascade effect 2: Replace localhost:5000 with ${REMOTE_GRAPHQL_ROOT_URL}
The port of remote_gql_server in tests files cannot be the constant 5000 anymore. Any test file which uses the remote GraphQL server has to be templated now. The current implementation is as follows

  • The remote_gql_fixture sets the environmental variable REMOTE_GRAPHQL_ROOT_URL when the graphql server is running (and resets it when the server stops running).
  • Add resolver and constructor to yaml (yaml_utils.py) so that anything which looks like ${ENV_NAME} in yaml file will be replaced by ENV_VALUE

@nizar-m
Copy link
Contributor

nizar-m commented Sep 25, 2019

The last yaml templating part is something that should have a second look. The solution for now works, but it may be confusing for people who are writing tests for the first time. We may move the whole tests into the code, or we may use templating languages like jsonnet or dhall or ytt.

If we are using something like jsonnet, ytt or dhall, we need to look at whether they support insert ordering for objects.

Looks jsonnet and dhall would not support insert order for jsons for now. ytt on the other hand seems to support it, at least on their playground, but it lacks python bindings.

@hasura-bot
Copy link
Contributor

Review app for commit ba8f465 deployed to Heroku: https://hge-ci-pull-2850.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2850-ba8f4658

def get(self, request):
return Response(HTTPStatus.METHOD_NOT_ALLOWED)

def _assert_prefixes(self, introspect):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are ensuring that gql proxy is adding prefixes as intended.

@@ -308,7 +313,7 @@ def post(self, req):
if not req.json:
return Response(HTTPStatus.BAD_REQUEST)
res = character_interface_schema.execute(req.json['query'])
respDict = res.to_dict()
respDict = to_dict(res)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes exist because we upgraded to Graphene-3.
Some of the tests which we could not run because graphql-core was throwing error can be done now.
Also the errors are much more descriptive with Graphene 3, which includes stuff like the field name and the location of the field in the query.

@@ -11,6 +11,6 @@ query:
args:
name: err-missing-arg
definition:
url: http://localhost:5000/iface-graphql-err-missing-arg
url: ${REMOTE_GRAPHQL_ROOT_URL}/iface-graphql-err-missing-arg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take the root url of remote GraphQL server from the environmental variable ${REMOTE_GRAPHQL_ROOT_URL} instead. This will be set by the remote_gql_server fixture when the remote server is running.

@hasura-bot
Copy link
Contributor

Review app for commit 9433aa5 deployed to Heroku: https://hge-ci-pull-2850.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2850-9433aa53

let initFieldCalls = NE.init $ rrRemoteFields remoteRel
leafFieldCall = NE.last $ rrRemoteFields remoteRel
(leafParentTypeInfo, leafParentTypeMap) <-
foldl
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use foldl' (see: #2933 (comment))

@hasura-bot
Copy link
Contributor

Review app for commit 2d9b323 deployed to Heroku: https://hge-ci-pull-2850.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2850-2d9b3233

@hasura-bot
Copy link
Contributor

Review app for commit c933b35 deployed to Heroku: https://hge-ci-pull-2850.herokuapp.com
Docker image for server: hasura/graphql-engine:pull2850-c933b351

@hasura-bot
Copy link
Contributor

Review app https://hge-ci-pull-2850.herokuapp.com is deleted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants