Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add multipart support to the CreateEtchPacket mutation#41

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
aalmazan merged 13 commits intomasterfrommultipart-support
Jan 10, 2023

Conversation

@aalmazan
Copy link
Contributor

Adds multipart support for thecreateEtchPacket mutation via the spec here:https://github.com/jaydenseric/graphql-multipart-request-spec

@aalmazanaalmazan added the enhancementNew feature or request labelJan 10, 2023
@aalmazanaalmazan self-assigned thisJan 10, 2023
Comment on lines 205 to 237
defget_files_for_payload(self)->Tuple[List[AttachableEtchFile],List[Any]]:
"""Scan through and gather files for use in multipart requests.
During the process, files will be replaced with a dummy `Path`
instance as `Callable` instances and likely their returns of some
sort of IO reader is not serializable and not easily dealt with in
pydantic (the underlying model system for the types used in this
library). Closer to the actual request, when the multipart payload is
being constructed, the dummy instances will be replaced by their actual
file instances.
:return: Tuple containing a list of uploadable file types, and a list
of actual file references
:rtype: Tuple[List, List]
"""
contains_uploads=any([isinstance(f,DocumentUpload)forfinself.files])
ifnotcontains_uploads:
returnself.files, []

files= []
foridx,finenumerate(self.files):
ifnotisinstance(f,DocumentUpload):
continue

ifgetattr(f.Config,"contains_uploads",False):
attr_name=getattr(f.Config,"contains_uploads")
upload=getattr(f,attr_name)

ifnotisinstance(upload,Base64Upload):
files.append(upload)
setattr(f,attr_name,Path())

returnself.files,files
Copy link
ContributorAuthor

@aalmazanaalmazanJan 10, 2023
edited
Loading

Choose a reason for hiding this comment

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

Admittedly, this is a little funky, but it's the easiest way I can think of at the moment. Because of the multipart spec, we need to a way to check for files, but the file attribute also has to be nulled/None-ed out when we serialize this down to JSON. Because of this, I'm just using aPath instance as a marker since a multipart file can be a file path or function.

@@ -0,0 +1,34 @@
frompython_anvil.multipart_helpersimportget_extractable_files_from_payload
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Adding more tests shortly..


files=get_multipart_payload(mutation)

res=self.mutate_multipart(files,**kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

A few things:

  • This looks like it will always callmutatate_multipart, even if there are no binary uploads, and therfore no reason to usemulti-part. Is that right? Maybe only usemulti-part when necessary?
  • It feels like this decision to use multipart or not, and the few lines hre of what to do in that case are better abstracted away inside the internals ofself.mutate somehow. That way anything that is uploading binary in a mutation will just have that stuff handled implicitly.

returnself.file_payloads

defcreate_payload(self)->CreateEtchPacketPayload:
defget_files_for_payload(self)->Tuple[List[AttachableEtchFile],List[Any]]:
Copy link
Contributor

Choose a reason for hiding this comment

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

This also feels like something that belongs in a more shared, non-CreateEtchPacket specific spot.

This seem seems akin tohttps://www.npmjs.com/package/extract-files

Our node-anvil library has a decent pattern to follow where it figures out if there files to maphere and then makes a multi-part request if necessaryhere.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

The generalextract-files-like functionality is in the function here:https://github.com/anvilco/python-anvil/pull/41/files#diff-615974429dd7f7e34ce2e08e0012206ae6f47d86bcfc9338e6f72546e76436beR14

In this first pass, though, this is mainly to add multipart support oncreateEtchPacket since it's the only one that has underlying model support. Will have a more generic multipart mutation path after this PR.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@benoglebenogleAwaiting requested review from benogle

1 more reviewer

@newhousenewhousenewhouse approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

@aalmazanaalmazan

Labels

enhancementNew feature or request

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@aalmazan@newhouse

[8]ページ先頭

©2009-2025 Movatter.jp