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

feat: support LinkML field names with spaces. #75

Merged
merged 4 commits into from
Jul 10, 2024

Conversation

jgadling
Copy link
Contributor

Fixes #66

This adds support for LinkML fields with spaces. The spaces are converted to underscores when we write out snake_case field names, and then get converted to camelCase properly at word boundaries (basically just in the GQL interface)

@@ -25,19 +25,19 @@ def __getattr__(self, attr: str) -> str:
"""
Error if a property doesn't exist
"""
raise NotImplementedError(f"please define field property {attr}")
raise NotImplementedError(f"please define field property {self.wrapped_field.name}.{attr}")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just making the error messages a little more verbose / easier to debug.

@@ -507,7 +507,7 @@ async def create_{{ cls.snake_name }}(
cerbos_client: CerbosClient = Depends(get_cerbos_client),
principal: Principal = Depends(require_auth_principal),
is_system_user: bool = Depends(is_system_user),
) -> db.Entity:
) -> db.{{ cls.name }}:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These return the current type, there's no reason to tell the type checker that we return the base type. I think. 😅

@@ -293,6 +293,8 @@ classes:
annotations:
minimum_length: 3
maximum_length: 8
field with spaces:
range: string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

An example of a field with spaces in its name!

}
"""
output = await gql_client.query(query, user_id=user_id, member_projects=[project_id])
assert cct.field_with_spaces == output["data"]["constraintCheckedTypes"][0]["fieldWithSpaces"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check that this field is wired up properly from the test infrastructure all the way to the GQL interface!

@jgadling jgadling merged commit f7636ed into main Jul 10, 2024
3 checks passed
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.

Support field names with spaces (convert spaces to underscores)
2 participants