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
[WIP]Allow to query Releases using GraphQL #4036
Conversation
This pull request introduces 9 alerts when merging 3ca6391 into e0fcce5 - view on LGTM.com new alerts:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job so far! I left some small comments.
bodhi/server/services/graphql.py
Outdated
@view_config() | ||
def graphql_view(request): | ||
context = {'session': request.session} | ||
return serve_graphql_request(request, schema, context_value=context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line can be deleted
bodhi/server/services/graphql.py
Outdated
|
||
|
||
class Query(graphene.ObjectType): | ||
release = graphene.List(Release) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you call this allReleases
or something similar then it will be more obvious to the user what this does
bodhi/server/services/graphql.py
Outdated
return serve_graphql_request(request, schema, context_value=context) | ||
|
||
# Setting graphiql=True | ||
return serve_graphql_request(request, schema, graphiql=True, context_value=context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think the flag here should be graphiql_enabled=True
.
It doesn't matter for now as the default is True
but it will matter once we set this based on a variable :)
Also, it looks like you have some unused imports in the schema and service file, so the CI will fail. If you need to fix those, you can run |
bodhi/server/graphql_schemas.py
Outdated
|
||
class Release(SQLAlchemyObjectType): | ||
""" | ||
Type object representing a distribution release, such as Fedora 27. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in the doc string here we should just reference that this is using the Release object from models.py so that we don't have to maintain the Attributes list and documentation here.
bodhi/server/services/graphql.py
Outdated
from cornice import Service | ||
from webob_graphql import serve_graphql_request | ||
import graphene |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this import at the top of the import
from cornice import Service | |
from webob_graphql import serve_graphql_request | |
import graphene | |
import graphene |
from cornice import Service | |
from webob_graphql import serve_graphql_request | |
import graphene | |
import graphene | |
from cornice import Service | |
from webob_graphql import serve_graphql_request |
bodhi/server/services/graphql.py
Outdated
Args: | ||
request (pyramid.Request): The current request. | ||
Returns: | ||
The response from Bodhi to the request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The graphql
response to the query
bodhi/server/services/graphql.py
Outdated
""" | ||
context = {'session': request.session} | ||
|
||
# Setting graphiql_enabled=True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this comment
bodhi/server/services/graphql.py
Outdated
context = {'session': request.session} | ||
|
||
# Setting graphiql_enabled=True | ||
return serve_graphql_request(request, schema, graphiql_enabled=True, context_value=context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to have the graphiql_enabled
value to be configure in the configuration so that we can have it set to True
in the development environment and False
in production.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For adding this in the configuration you can look at an example here -->
import the configuration :
https://github.com/fedora-infra/bodhi/blob/develop/bodhi/server/models.py#L47
get the value of a configuration key:
https://github.com/fedora-infra/bodhi/blob/develop/bodhi/server/models.py#L1094
add the configuration key to the file :
https://github.com/fedora-infra/bodhi/blob/develop/production.ini#L322
and https://github.com/fedora-infra/bodhi/blob/develop/devel/development.ini.example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the configuration key could be something like enable_graphiql
bodhi/server/services/graphql.py
Outdated
|
||
|
||
@graphql.post() | ||
def graphql_post(request): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not 100% sure here (@StephenCoady might look at that), but I am not sure that we need 2 function here we could have only one with the following declaration
@graphql.post()
@graphql.get()
def graphql_endpoint(request):
....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is correct, function with both post
and get
will work the same
We also need to update the tests 😄 |
@@ -109,6 +109,21 @@ | |||
name: jinja2-cli | |||
executable: pip3 | |||
|
|||
- name: pip install WebOb-GraphQL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you can use a loop in ansible instead of repeating the tasks 4 times. See https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#iterating-over-a-simple-list
Yes, I think a resolver function for each field is required to fetch the data. |
bodhi/server/services/graphql.py
Outdated
|
||
allReleases = graphene.List(Release) | ||
|
||
def resolve_releases(self, info): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like @cverna was right, graphene handles the mapping under the hood for us, so resolve_allReleases
will work here.
5ff3092
to
7237fd0
Compare
7237fd0
to
a971713
Compare
|
||
def test_allReleases(self): | ||
"""Testing allReleases""" | ||
client = Client(Release) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So Release
here isn't actually your schema. The schema
you want to pass to your test client here is the collection of queries and mutations you have created. Graphene sqlalchemy actually creates this for you when you call graphene.Schema(query=Query)
. If you check graphql.py
you've already done that there so you can use the schema
variable :)
a971713
to
1be960b
Compare
Riot isn't working on my end right now (Connectivity to server has been lost). :( I'll text there as soon as it works! |
3867fe0
to
58a0f74
Compare
bodhi/server/graphql_schemas.py
Outdated
|
||
|
||
class Release(SQLAlchemyObjectType): | ||
"""Type object representing a distribution release from bodhi.server.models, such as Fedora 27.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the line that is breaking your lint, if you make it multi-line the flake8 run should pass
self.db.add(release) | ||
self.db.commit() | ||
|
||
executed = client.execute("""{ allReleases{ name }}""") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to test for some of the trickier fields like state
or package_manager
(or both!). You could request it from allReleases and make sure it matched the value provided to db.add(). I think that could be a separate test.
bodhi/server/graphql_schemas.py
Outdated
|
||
|
||
class Release(SQLAlchemyObjectType): | ||
"""Type object representing a distribution release from bodhi.server.models, like Fedora 27""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the line that is breaking your lint, if you make it multi-line the flake8 run should pass
58a0f74
to
2160a94
Compare
… query allReleases that allows to fetch all Release objects from the database using GraphQL. Fixes fedora-infra#4024. Signed-off-by: Karma Dolkar <karmadolkar29@gmail.com>
6021a0e
to
9dd0590
Compare
This lgtm, @StephenCoady if you want to give it another look :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me. great work :)
ref #4024
Signed-off-by: Karma Dolkar karmadolkar29@gmail.com