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

GraphQL resource instance level query #2628

Open
codyebberson opened this issue Aug 4, 2023 · 0 comments
Open

GraphQL resource instance level query #2628

codyebberson opened this issue Aug 4, 2023 · 0 comments
Labels
search Features and fixes related to search

Comments

@codyebberson
Copy link
Member

https://hl7.org/fhir/graphql.html#invoking

[base]/[Type]/[id]/$graphql

A Resource Instance level the query assumes a single resource is in scope, and just queries on the data available in the given resource.


Implementation notes:

This will mostly be in packages\fhir-router\src\graphql\graphql.ts

We currently only maintain one root schema:

let rootSchema: GraphQLSchema | undefined;

Which is lazily built on the first graphql operation.

We will need to create additional schemas for each FHIR resource type. That should not be as bad as it sounds. We already build a GraphQLOutputType for each resource type. So creating the schema should be something like:

let rootSchema: GraphQLSchema | undefined;

const instanceSchemas = new Map<string, GraphQLSchema>();

function getInstanceSchema(resourceType: string): GraphQLSchema {
  let result = instanceSchemas.get(resourceType);
  if (!result) {
    result = buildInstanceLevelSchema(resourceType);
    instanceSchemas.set(resourceType, result);
  }
  return result;
}

function buildInstanceLevelSchema(resourceType: string): GraphQLSchema {
  return new GraphQLSchema({
    query: buildGraphQLOutputType(resourceType),
  });
}

(untested)

And then add a route in packages\fhir-router\src\fhirrouter.ts

Similar to the existing GraphQL route:

    this.router.add('POST', '$graphql', graphqlHandler);

Except this will be an instance level route:

    this.router.add('POST', ':resourceType/:id/$graphql', graphqlHandler);

I don't know if it would be easier to reuse the existing graphqlHandler or to create a new similar one for instance level. That will require some quick experimentation.

@reshmakh reshmakh added the search Features and fixes related to search label Aug 4, 2023
@rahul1 rahul1 added this to the Milestone Quality milestone Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
search Features and fixes related to search
Projects
Status: No status
Development

No branches or pull requests

3 participants