-
Notifications
You must be signed in to change notification settings - Fork 1.2k
GraphQLApi support for sam deploy
#5294
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| """Helper functions to work with SAM GraphQLApi resource | ||
| """ | ||
|
|
||
| from typing import Any, Dict, List, Tuple, Union | ||
|
|
||
| SCHEMA_ARTIFACT_PROPERTY = "SchemaUri" | ||
| CODE_ARTIFACT_PROPERTY = "CodeUri" | ||
|
|
||
|
|
||
| def find_all_paths_and_values(property_name: str, graphql_dict: Dict[str, Any]) -> List[Tuple[str, Union[str, Dict]]]: | ||
| """Find paths to the all properties with property_name and their (properties) values. | ||
|
|
||
| It leverages the knowledge of GraphQLApi structure instead of doing generic search in the graph. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| property_name | ||
| Name of the property to look up, for example 'CodeUri' | ||
| graphql_dict | ||
| GraphQLApi resource dict | ||
|
|
||
| Returns | ||
| ------- | ||
| list of tuple (path, value) for all found properties which has property_name | ||
| """ | ||
| # need to look up only in "Resolvers" and "Functions" subtrees | ||
| resolvers_and_functions = {k: graphql_dict[k] for k in ("Resolvers", "Functions") if k in graphql_dict} | ||
| stack: List[Tuple[Dict[str, Any], str]] = [(resolvers_and_functions, "")] | ||
| paths_values: List[Tuple[str, Union[str, Dict]]] = [] | ||
|
|
||
| while stack: | ||
| node, path = stack.pop() | ||
| if isinstance(node, dict): | ||
| for key, value in node.items(): | ||
| if key == property_name: | ||
| paths_values.append((f"{path}{key}", value)) | ||
| elif isinstance(value, dict): | ||
| stack.append((value, f"{path}{key}.")) | ||
| # there is no need to handle lists because | ||
| # paths to "CodeUri" within "Resolvers" and "Functions" doesn't have lists | ||
| return paths_values |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
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.
nit: Can we import anything we need from
graphql_apidirectly instead of importing the module?Uh oh!
There was an error while loading. Please reload this page.
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.
Is the style I used is against SAM CLI practice? I import everything from that file anyway. But the main reason, I think that
graphql_api.SCHEMA_ARTIFACT_PROPERTYandgraphql_api.find_all_paths_and_values(self.PROPERTY_NAME, resource_dict)is easier to read than simplySCHEMA_ARTIFACT_PROPERTYandfind_all_paths_and_valueswhich show less "belonging". But if it's against the style, I can remove it. It's up to youThere 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 it's fine since
graphql_apiis not a huge module. And +1 for the point of "belonging".