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.

@jdacoello jdacoello force-pushed the feature/gql-exporter branch from 8e6ef04 to dcde474 Compare November 26, 2024 00:01
src/vss_tools/exporters/jsonschema.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
src/vss_tools/exporters/graphql.py Outdated Show resolved Hide resolved
src/vss_tools/exporters/graphql.py Outdated Show resolved Hide resolved
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?

@jdacoello jdacoello force-pushed the feature/gql-exporter branch from 50cadb6 to a5728b5 Compare November 27, 2024 10:23
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 10 times, most recently from dc8acfa to 142797e Compare December 2, 2024 12:02
@jdacoello jdacoello force-pushed the feature/gql-exporter branch 9 times, most recently from ee4dcf1 to 9942f6c Compare December 2, 2024 22:15
@erikbosch
Copy link
Collaborator

erikbosch commented Dec 3, 2024

MoM:

docs/graphql.md Outdated Show resolved Hide resolved
@jdacoello jdacoello force-pushed the feature/gql-exporter branch from 9942f6c to 63095a8 Compare December 10, 2024 13:20
@jdacoello
Copy link
Author

There are other features or possible improvements to the GraphQL VSS counterpart. For example:

  • Mapping structs as types with mandatory fields with the ! character.
  • Adding identifiers with the scalar ID! for those concepts that must be unique in practice (e.g., multiple doors, etc.)
  • Defining a Query for all VSS leaves.
  • Defining a Mutation for all VSS actuators to indicate that the value of the property can be modified.
  • Shorten names for type, enum, etc. (e.g., Window instead of Vehicle.Cabin.Door.Window). This requires agreement on the name uniqueness for VSS branches. See, Branch names are not unique vehicle_signal_specification#790
  • Using a library to automatically create the plural name for a field. For example, doors instead of door_s.
  • etc.

I am happy to hear more feedback from the community in case there is any suggestion or observation about the modeling decisions and proposed structures to make this even better.

@erikbosch
Copy link
Collaborator

MoM:

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