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

Serve sumission schema files from backend #1172

Merged
merged 7 commits into from
Mar 8, 2024

Conversation

pkalita-lbl
Copy link
Collaborator

Fixes #1166

Summary

This is partially to support the Field Notes app, but I think it also has benefits for the main submission portal as well. The gist is to allow API clients (whether that's the submission portal or the app) to get submission schema artifacts from the API instead of bundling them in the client application. For the submission portal this hasn't been a major problem (other than the weirdness of having a PyPI artifact as a frontend dependency) since the frontend and backend are part of the same codebase and released at the same time. That won't necessarily be true for the Field Notes app so we want to be able to dynamically fetch the schema.

Details

  • A new module nmdc_server/static_files.py defines a path to hold static files and a function which knows how to introspect files provided by the nmdc_submission_schema package and write JSON files into the static file directory. In particular it produces a JSON file representing the whole submission schema (used by the submission portal), files representing individual classes of the schema (likely to be used by the Field Notes app), and the GOLD ecosystem tree (used by the submission portal and likely to be used by the Field Notes app).
  • When the backend app starts up, the function to generate the static files is called and the static file directory is mounted under the /static path.
  • The frontend app fetches the necessary JSON files from the /static routes instead of importing packaged files.
  • Include nmdc-submission-schema as a backend dependency, remove it as a frontend dependency.
  • Increment the nmdc-schema dependencies to the latest version.

Comments

I decided on the static file approach because FastAPI will serve the right headers (I think mayble Etag) in the responses to allow browsers to aggressively cache the responses.

In the future we could consider whether we can piggyback on this approach to also remove the nmdc-server frontend dependency.

@pkalita-lbl pkalita-lbl requested a review from naglepuff March 6, 2024 22:11
Copy link
Collaborator

@naglepuff naglepuff left a comment

Choose a reason for hiding this comment

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

I think this is a pretty elegant solution. I had one comment on the code, and I have additional questions about deployment - is there anything that needs to be done on the spin side to make sure there's no problem creating the static file directory?

@pkalita-lbl pkalita-lbl requested a review from naglepuff March 8, 2024 01:25
@pkalita-lbl
Copy link
Collaborator Author

is there anything that needs to be done on the spin side to make sure there's no problem creating the static file directory?

Not that I'm aware of, but we should find out as soon as this goes to dev if there is.

Copy link
Collaborator

@naglepuff naglepuff left a comment

Choose a reason for hiding this comment

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

Looks good. I tested this locally by visiting some of the /static urls and confirming that I got some neat json files as a response, and checking that the DH works correctly (i.e. expected columns, validation). As far as I could tell, things appear to be in working order.

@pkalita-lbl pkalita-lbl merged commit 2e07dfd into main Mar 8, 2024
2 checks passed
@pkalita-lbl pkalita-lbl deleted the issue-1166-schema-static-files branch March 8, 2024 21:59
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.

Add endpoint for retriving sample metadata schema
2 participants