5276 the graphql request results in an http 400 error (#5278)

* fixed issue, added test

* added change logs

---------

Co-authored-by: Steven Li <steven@smilecdr.com>
This commit is contained in:
StevenXLi 2023-09-06 16:34:37 -04:00 committed by GitHub
parent 650fbe541c
commit 3e46f71542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 5276
title: "Previously, GraphQL queries will error when using base resource search parameters such as '_id' after search parameter rebuild.
This has been fixed."

View File

@ -237,6 +237,31 @@ public class GraphQLR4Test extends BaseResourceProviderR4Test {
myCaptureQueriesListener.logSelectQueries(); myCaptureQueriesListener.logSelectQueries();
} }
@Test
public void testId_Search_Patient() throws IOException {
initTestPatients();
String query = "{PatientList(_id: " + myPatientId0.getIdPart() + ") {id}}";
HttpGet httpGet = new HttpGet(myServerBase + "/$graphql?query=" + UrlUtil.escapeUrlParam(query));
try (CloseableHttpResponse response = ourHttpClient.execute(httpGet)) {
String resp = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
ourLog.info(resp);
@Language("json")
String expected = """
{
"PatientList":[{
"id":" """ + myPatientId0 + """
/_history/1"
}]
}""";
assertEquals(TestUtil.stripWhitespace(DATA_PREFIX +
expected +
DATA_SUFFIX), TestUtil.stripWhitespace(resp));
}
}
private void initTestPatients() { private void initTestPatients() {
Patient p = new Patient(); Patient p = new Patient();
p.addName() p.addName()

View File

@ -131,4 +131,21 @@ public interface ISearchParamRegistry {
} }
return availableSearchParamDef; return availableSearchParamDef;
} }
/**
* Get all the search params for a resource. First, check the resource itself, then check the top-level `Resource` resource and combine the two.
*
* @param theResourceType the resource type.
*
* @return the {@link ResourceSearchParams} that has all the search params.
*/
default ResourceSearchParams getRuntimeSearchParams(String theResourceType) {
ResourceSearchParams availableSearchParams =
getActiveSearchParams(theResourceType).makeCopy();
ResourceSearchParams resourceSearchParams = getActiveSearchParams("Resource");
resourceSearchParams
.getSearchParamNames()
.forEach(param -> availableSearchParams.addSearchParamIfAbsent(param, resourceSearchParams.get(param)));
return availableSearchParams;
}
} }

View File

@ -130,7 +130,7 @@ public class DaoRegistryGraphQLStorageServices implements IGraphQLStorageService
RuntimeResourceDefinition typeDef = fhirContext.getResourceDefinition(theType); RuntimeResourceDefinition typeDef = fhirContext.getResourceDefinition(theType);
SearchParameterMap params = new SearchParameterMap(); SearchParameterMap params = new SearchParameterMap();
ResourceSearchParams searchParams = mySearchParamRegistry.getActiveSearchParams(typeDef.getName()); ResourceSearchParams searchParams = mySearchParamRegistry.getRuntimeSearchParams(typeDef.getName());
for (Argument nextArgument : resourceSearchParam) { for (Argument nextArgument : resourceSearchParam) {