-
Notifications
You must be signed in to change notification settings - Fork 16
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
adding edit fields mutate to graphql #894
base: main
Are you sure you want to change the base?
Conversation
allowing: "bot data enabled" "bot data publicly downloadable" "bot zip publicly downloadable" "id" "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.
Good work @DrillableBit
Couple things to be addressed. Reach out to me for guidance if you want RE the tests.
from aiarena.graphql.types import BotType | ||
|
||
|
||
class UpdateBotInput(CleanedInputType): |
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.
Please flag any required fields here.
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 the syntax might be graphene.String(required=True)
, but check this.
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.
We actually have a custom way of marking fields as required (and also validating their correctness), that produces output that's easier to handle on the frontend side (ie {"id": ["Required field"]}
instead of just a text error).
Set it up for the UpdateBot
mutation and wrote a test for it.
|
||
|
||
class UpdateBotInput(CleanedInputType): | ||
name = graphene.String() |
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 bot name cannot be updated by it's owner, so this should probably be removed (unless we want to make the decision to change this at this time).
input_class = UpdateBotInput | ||
|
||
@classmethod | ||
def perform_mutate(cls, info: graphene.ResolveInfo, input_object: UpdateBotInput): |
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 would feel much more comfortable from my end if there were tests associated with this to assert both that it works in the way it's intended, both now and into the future.
I have added some examples in test_mutations.py
. Feel free to reach out to me for guidance and we can get it set up together.
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 created a helper class for GraphQL tests and actually implemented the example tests, so that we have something to look at when writing GraphQL tests in the future
@@ -225,3 +226,8 @@ def __init_subclass_with_meta__(cls, _meta=None, required_fields=None, **options | |||
_meta = CleanedInputTypeOptions(cls) | |||
_meta.required_fields = required_fields | |||
super().__init_subclass_with_meta__(_meta=_meta, **options) | |||
|
|||
|
|||
def raise_if_annonymous_user(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.
This would be good as part of a base class that all mutations (except the login one) use which always enforces authentication.
That way there's less risk we will accidentally forget to call this somewhere.
if bot.user.id != info.context.user.id: | ||
raise GraphQLError("This is not your bot") | ||
|
||
for attr, value in input_object.items(): |
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.
A test to assert that extra fields cannot be included in the payload would be great.
…not just Playwright
allowing:
"bot data enabled"
"bot data publicly downloadable"
"bot zip publicly downloadable"
"id"
"name"