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/fhir json schema + Remove Elasticsearch support from Grip #318

Merged
merged 35 commits into from
Jan 3, 2025

Conversation

matthewpeterkort
Copy link
Collaborator

@matthewpeterkort matthewpeterkort commented Oct 23, 2024

This PR does a few things:

Add support for storing jsonschema as a grip graph
grip schema post --graphName CALIPER --jsonSchema test.json

The protobuf for this is defined as:

  rpc AddJsonSchema(RawJson) returns (EditResult) {
    option (google.api.http) = {
        post: "/v1/graph/{graph}/jsonschema"
        body: "*"
    };
  }

Add support for loading FHIR json directly into grip via new proto method:
grip caliperload schema-test/Observation.ndjson CALIPER test-data2

message RawJson {
  string graph = 1;
  google.protobuf.Struct extra_args = 2;
  google.protobuf.Struct data = 3;
}


  rpc BulkAddRaw (stream RawJson) returns (BulkJsonEditResult) {
    option (google.api.http) = {
      post: "/v1/rawJson"
    };
  }

Note also BulkJsonEditResult is also added, adding support for returning messages back to the client so that an HTTP code can be generated from the error messages or the lack of error messages.

message BulkJsonEditResult{
    int32 insert_count = 1;
    repeated string errors = 2;
}

Reorganize schema files into schema dir. Those files were previously in gripql directory.

Also removes all instances of elasticSearch from Grip. This include the website too.

Proto spec now abstracts project_id into extraArgs

func (server *GripServer) LoadSchemas(project_id string, sch *gripql.Graph, out *graph.GraphSchema) (*graph.GraphSchema, error) {
schcompiler := jsonschema.NewCompiler()
schcompiler.ExtractAnnotations = true
schcompiler.RegisterExtension(compile.GraphExtensionTag, compile.GraphExtMeta, compile.GraphExtCompiler{})
Copy link
Collaborator Author

@matthewpeterkort matthewpeterkort Nov 18, 2024

Choose a reason for hiding this comment

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

Our graph extension is hard coded into the loader here. An extension argument could get abstracted out as an argument to the load schema protobuf method.

@matthewpeterkort matthewpeterkort changed the title [WIP] Feature/fhir json schema Feature/fhir json schema + Remove Elasticsearch support from Grip Nov 20, 2024
@@ -171,7 +173,7 @@ var Cmd = &cobra.Command{

if yamlFile != "" {
log.Infof("Loading YAML file: %s", yamlFile)
graphs, err := gripql.ParseYAMLGraphsFile(yamlFile)
graphs, err := schema.ParseYAMLGraphsFile(yamlFile)
Copy link
Member

Choose a reason for hiding this comment

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

Why isn't this graphSchema?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@@ -2,13 +2,10 @@
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Categories on GRIP</title>
<link>https://bmeg.github.io/grip/categories/</link>
<link>http://localhost:1313/grip/categories/</link>
Copy link
Member

Choose a reason for hiding this comment

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

The doc build was done with the wrong hostname

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

addressed in newest commit

@matthewpeterkort
Copy link
Collaborator Author

matthewpeterkort commented Dec 3, 2024

ok localhost paths should be fixed now. When hugo --source ./website -w server is run it changes the files to point to localhost but when hugo --source ./website is run it rebuilds the site to point to the actual domain name. so just had to run hugo --source ./website again

…aphql conversion scripts into jsonschemagraph package
@matthewpeterkort
Copy link
Collaborator Author

Moved out graphql code. This branch should be cleaned up now and ready for merge


def test_post_json_schema(man):
errors = []
G = man.setGraph("swapi")
Copy link
Member

Choose a reason for hiding this comment

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

For cases where the unit test is a write option, you get the graph using

G = man.writeTest()

errors = []
G = man.setGraph("swapi")
# Probably don't want to add a 2MB schema file to the repo so get it via requests instead
res = requests.get("https://raw.githubusercontent.com/bmeg/iceberg/f1724941fe47df24846135fb515d1b89e791cee3/schemas/graph/graph-fhir.json")
Copy link
Member

Choose a reason for hiding this comment

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

This probably isn't ideal in the long run. We can think about a paired down sample schema that can be used for unit tests in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@kellrott
Copy link
Member

Is there a way to load a directory of JsonSchema YAML files? I only see single file JSON post for the schema post command.

sflags.BoolVar(&manual, "manual", manual, "Use client side schema sampling")
sflags.StringSliceVar(&excludeLabels, "exclude-label", excludeLabels, "exclude vertex/edge label from schema")
pflags.StringVar(&jsonSchemaFile, "jsonSchema", "", "Json Schema")
pflags.StringVar(&graphName, "graphName", "", "Name of schemaGraph")
Copy link
Member

Choose a reason for hiding this comment

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

For the other sub commands, graphName is defined via fixed argument and not a flag.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@matthewpeterkort
Copy link
Collaborator Author

matthewpeterkort commented Jan 2, 2025

Is there a way to load a directory of JsonSchema YAML files? I only see single file JSON post for the schema post command.

This new feature has been added see tests, cmd line option --yamlSchemaPath supports loading individual yaml schema as files or loading entire yaml schema directories of files.

Additionally the AddSchema API has been changed from a delete and replace strategy to a upsert strategy so that schemas can now be added to / edited with multiple AddSchema calls.

@matthewpeterkort
Copy link
Collaborator Author

Should be ready for another review / merge now

@kellrott
Copy link
Member

kellrott commented Jan 3, 2025

LGTM

@kellrott kellrott merged commit a231289 into develop Jan 3, 2025
10 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.

2 participants