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

Feature/gql exporter #433

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jdacoello
Copy link

This PR addresses the issue #431. It refactors entirely the GraphphQL exporter to offer a usable schema structure. For extended explanation, please see the updated documentation of the exporter docs/graphql.md.

src/vss_tools/exporters/jsonschema.py Outdated Show resolved Hide resolved
src/vss_tools/exporters/graphql.py Outdated Show resolved Hide resolved


# ========= String converters =========
def to_camel_case(text: str) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably should be in utils

Copy link
Author

Choose a reason for hiding this comment

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

There was some function for that, but it was not producing the expected output. I am not sure if any other exporter is using that, so I decided not to modify and write my own

return text[0].lower() + text[1:]


def to_pascal_case(text: str) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same, should be in utils

Copy link
Author

Choose a reason for hiding this comment

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

There was some function for that, but it was not producing the expected output. I am not sure if any other exporter is using that, so I decided not to modify and write my own

return "".join(word[0].upper() + word[1:] for word in words)


def to_screaming_snake_case(text: str) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same

Copy link
Author

Choose a reason for hiding this comment

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

There was some function for that, but it was not producing the expected output. I am not sure if any other exporter is using that, so I decided not to modify and write my own

field_dict[additional_field[0]] = field(node, f" {str(additional_field[1])}: ")
def get_gql_unit_enums() -> Dict[str, graphene.Enum]:
"""Get GraphQL enums for VSS units and quantity kinds."""
global mapping_quantity_kinds_df
Copy link
Collaborator

Choose a reason for hiding this comment

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

why does this need to be global and not just an argument / return value of the function?

Copy link
Author

Choose a reason for hiding this comment

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

For simplicity, to avoid passing that to many places. This variable is only modified once but accessed elsewhere

src/vss_tools/exporters/graphql.py Outdated Show resolved Hide resolved
src/vss_tools/exporters/graphql.py Outdated Show resolved Hide resolved
src/vss_tools/exporters/graphql.py Outdated Show resolved Hide resolved

def get_graphql_schema(tree: VSSNode) -> graphene.Schema:
"""Create a GraphQL schema from the VSS tree."""
global vss_metadata_df, vss_branches_df, vss_leaves_df, gql_unit_enums, gql_allowed_enums, gql_instance_enums
Copy link
Collaborator

Choose a reason for hiding this comment

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

So many globals. Isn't it possible to pass them through where needed?

Copy link
Author

Choose a reason for hiding this comment

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

It is possible, but as I have many functions, it will imply passing them over multiple times.

@erikbosch
Copy link
Collaborator

MoM:

):
"""
Export as GraphQL.
Export a VSS specification to a GraphQL schema.
"""
tree, _ = get_trees(
Copy link
Collaborator

Choose a reason for hiding this comment

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

what about the type tree aka structs?

src/vss_tools/exporters/graphql.py Outdated Show resolved Hide resolved
src/vss_tools/exporters/graphql.py Outdated Show resolved Hide resolved
src/vss_tools/exporters/graphql.py Outdated Show resolved Hide resolved
@jdacoello jdacoello force-pushed the feature/gql-exporter branch 3 times, most recently from 4bec393 to e864275 Compare November 28, 2024 09:10
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.

3 participants