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 Introspection Support #3348

Merged
merged 23 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup
  • Loading branch information
jamesagnew committed Feb 4, 2022
commit 8799dacd678fa8f097acf63dfcf7262aebbab212
Original file line number Diff line number Diff line change
Expand Up @@ -654,16 +654,6 @@ public static void beforeClassRandomizeLocale() {
doRandomizeLocaleAndTimezone();
}

@AfterAll
public static void afterClassShutdownDerby() {
// DriverManager.getConnection("jdbc:derby:;shutdown=true");
// try {
// DriverManager.getConnection("jdbc:derby:memory:myUnitTestDB;drop=true");
// } catch (SQLNonTransientConnectionException e) {
// // expected.. for some reason....
// }
}

public static String loadClasspath(String resource) throws IOException {
return new String(loadClasspathBytes(resource), Constants.CHARSET_UTF8);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.QuantityParam;
import ca.uhn.fhir.rest.param.ReferenceParam;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
Expand Down Expand Up @@ -102,6 +103,10 @@ public void testCreateLinkCreatesAppropriatePaths() {
.collect(Collectors.toList());
assertThat(paths.toString(), paths, contains("Observation.subject", "Observation.subject.where(resolve() is Patient)"));
});

myCaptureQueriesListener.clear();
assertEquals(1, myObservationDao.search(SearchParameterMap.newSynchronous("patient", new ReferenceParam("Patient/A"))).sizeOrThrowNpe());
myCaptureQueriesListener.logSelectQueries();
}

@Test
Expand Down
7 changes: 7 additions & 0 deletions hapi-fhir-jpaserver-uhnfhirtest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>

<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-jpaserver-base</artifactId>
Expand Down Expand Up @@ -102,6 +103,12 @@
</dependency>

<!-- TEST DEPS -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import ca.uhn.fhir.rest.server.interceptor.LoggingInterceptor;
import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
import ca.uhn.fhir.rest.server.provider.ResourceProviderFactory;
import ca.uhn.fhirtest.config.SqlCaptureInterceptor;
import ca.uhn.fhirtest.config.TestDstu2Config;
import ca.uhn.fhirtest.config.TestDstu3Config;
import ca.uhn.fhirtest.config.TestR4Config;
Expand Down Expand Up @@ -282,6 +283,8 @@ protected void initialize() throws ServletException {
loggingInterceptor.setMessageFormat("${operationType} Content-Type: ${requestHeader.content-type} - Accept: ${responseEncodingNoDefault} \"${requestHeader.accept}\" - Agent: ${requestHeader.user-agent}");
registerInterceptor(loggingInterceptor);

// SQL Capturing
registerInterceptor(myAppCtx.getBean(SqlCaptureInterceptor.class));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
package ca.uhn.fhirtest.config;

import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.api.model.HistoryCountModeEnum;
import ca.uhn.fhir.jpa.config.BaseJavaConfigDstu2;
import ca.uhn.fhir.jpa.model.dialect.HapiFhirH2Dialect;
import ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgres94Dialect;
import ca.uhn.fhir.jpa.model.entity.ModelConfig;
import ca.uhn.fhir.jpa.search.HapiLuceneAnalysisConfigurer;
import ca.uhn.fhir.jpa.util.CurrentThreadCaptureQueriesListener;
import ca.uhn.fhir.jpa.util.DerbyTenSevenHapiFhirDialect;
import ca.uhn.fhir.jpa.validation.ValidationSettings;
import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor;
import ca.uhn.fhir.validation.IValidatorModule;
import ca.uhn.fhir.validation.ResultSeverityEnum;
import ca.uhn.fhirtest.interceptor.PublicSecurityInterceptor;
import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder;
import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.commons.lang3.time.DateUtils;
import org.hibernate.dialect.PostgreSQL94Dialect;
import org.hibernate.search.backend.lucene.cfg.LuceneBackendSettings;
import org.hibernate.search.backend.lucene.cfg.LuceneIndexSettings;
import org.hibernate.search.engine.cfg.BackendSettings;
import org.hibernate.search.mapper.orm.cfg.HibernateOrmMapperSettings;
import org.hl7.fhir.dstu2.model.Subscription;
import org.hl7.fhir.r5.utils.validation.constants.ReferenceValidationPolicy;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -102,7 +97,7 @@ public ValidationSettings validationSettings() {
public DataSource dataSource() {
BasicDataSource retVal = new BasicDataSource();
if (CommonConfig.isLocalTestMode()) {
retVal.setUrl("jdbc:derby:memory:fhirtest_dstu2;create=true");
retVal.setUrl("jdbc:h2:mem:fhirtest_dstu2");
} else {
retVal.setDriver(new org.postgresql.Driver());
retVal.setUrl("jdbc:postgresql://localhost/fhirtest_dstu2");
Expand Down Expand Up @@ -144,7 +139,7 @@ public LocalContainerEntityManagerFactoryBean entityManagerFactory(ConfigurableL
private Properties jpaProperties() {
Properties extraProperties = new Properties();
if (CommonConfig.isLocalTestMode()) {
extraProperties.put("hibernate.dialect", DerbyTenSevenHapiFhirDialect.class.getName());
extraProperties.put("hibernate.dialect", HapiFhirH2Dialect.class.getName());
} else {
extraProperties.put("hibernate.dialect", HapiFhirPostgres94Dialect.class.getName());
}
Expand All @@ -168,6 +163,7 @@ private Properties jpaProperties() {

/**
* Bean which validates incoming requests
*
* @param theInstanceValidator
*/
@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,24 @@

import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.config.BaseJavaConfigDstu3;
import ca.uhn.fhir.jpa.model.dialect.HapiFhirH2Dialect;
import ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgres94Dialect;
import ca.uhn.fhir.jpa.model.entity.ModelConfig;
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
import ca.uhn.fhir.jpa.search.HapiLuceneAnalysisConfigurer;
import ca.uhn.fhir.jpa.util.CurrentThreadCaptureQueriesListener;
import ca.uhn.fhir.jpa.util.DerbyTenSevenHapiFhirDialect;
import ca.uhn.fhir.jpa.validation.ValidationSettings;
import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor;
import ca.uhn.fhir.validation.ResultSeverityEnum;
import ca.uhn.fhirtest.interceptor.PublicSecurityInterceptor;
import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder;
import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.commons.lang3.time.DateUtils;
import org.hibernate.dialect.PostgreSQL94Dialect;
import org.hibernate.search.backend.lucene.cfg.LuceneBackendSettings;
import org.hibernate.search.backend.lucene.cfg.LuceneIndexSettings;
import org.hibernate.search.engine.cfg.BackendSettings;
import org.hibernate.search.mapper.orm.cfg.HibernateOrmMapperSettings;
import org.hl7.fhir.dstu2.model.Subscription;
import org.hl7.fhir.r5.utils.validation.constants.ReferenceValidationPolicy;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -92,8 +88,6 @@ public ValidationSettings validationSettings() {
}




@Override
@Bean(autowire = Autowire.BY_TYPE)
public DatabaseBackedPagingProvider databaseBackedPagingProvider() {
Expand All @@ -103,8 +97,8 @@ public DatabaseBackedPagingProvider databaseBackedPagingProvider() {
return retVal;
}

@Bean

@Bean
public PublicSecurityInterceptor securityInterceptor() {
return new PublicSecurityInterceptor();
}
Expand All @@ -113,7 +107,7 @@ public PublicSecurityInterceptor securityInterceptor() {
public DataSource dataSource() {
BasicDataSource retVal = new BasicDataSource();
if (CommonConfig.isLocalTestMode()) {
retVal.setUrl("jdbc:derby:memory:fhirtest_dstu3;create=true");
retVal.setUrl("jdbc:h2:mem:fhirtest_dstu3");
} else {
retVal.setDriver(new org.postgresql.Driver());
retVal.setUrl("jdbc:postgresql://localhost/fhirtest_dstu3");
Expand Down Expand Up @@ -147,7 +141,7 @@ public LocalContainerEntityManagerFactoryBean entityManagerFactory(ConfigurableL
private Properties jpaProperties() {
Properties extraProperties = new Properties();
if (CommonConfig.isLocalTestMode()) {
extraProperties.put("hibernate.dialect", DerbyTenSevenHapiFhirDialect.class.getName());
extraProperties.put("hibernate.dialect", HapiFhirH2Dialect.class.getName());
} else {
extraProperties.put("hibernate.dialect", HapiFhirPostgres94Dialect.class.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.config.BaseJavaConfigR4;
import ca.uhn.fhir.jpa.model.dialect.HapiFhirH2Dialect;
import ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgres94Dialect;
import ca.uhn.fhir.jpa.model.entity.ModelConfig;
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
import ca.uhn.fhir.jpa.search.HapiLuceneAnalysisConfigurer;
import ca.uhn.fhir.jpa.util.CurrentThreadCaptureQueriesListener;
import ca.uhn.fhir.jpa.util.DerbyTenSevenHapiFhirDialect;
import ca.uhn.fhir.jpa.validation.ValidationSettings;
import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor;
import ca.uhn.fhir.validation.ResultSeverityEnum;
Expand All @@ -20,7 +20,6 @@
import org.hl7.fhir.dstu2.model.Subscription;
import org.hl7.fhir.r5.utils.validation.constants.ReferenceValidationPolicy;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -94,7 +93,7 @@ public ValidationSettings validationSettings() {
public DataSource dataSource() {
BasicDataSource retVal = new BasicDataSource();
if (CommonConfig.isLocalTestMode()) {
retVal.setUrl("jdbc:derby:memory:fhirtest_r4;create=true");
retVal.setUrl("jdbc:h2:mem:fhirtest_r4");
} else {
retVal.setDriver(new org.postgresql.Driver());
retVal.setUrl("jdbc:postgresql://localhost/fhirtest_r4");
Expand Down Expand Up @@ -137,7 +136,7 @@ public LocalContainerEntityManagerFactoryBean entityManagerFactory(ConfigurableL
private Properties jpaProperties() {
Properties extraProperties = new Properties();
if (CommonConfig.isLocalTestMode()) {
extraProperties.put("hibernate.dialect", DerbyTenSevenHapiFhirDialect.class.getName());
extraProperties.put("hibernate.dialect", HapiFhirH2Dialect.class.getName());
} else {
extraProperties.put("hibernate.dialect", HapiFhirPostgres94Dialect.class.getName());
}
Expand Down Expand Up @@ -196,5 +195,4 @@ public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderCon
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.config.BaseJavaConfigR5;
import ca.uhn.fhir.jpa.model.dialect.HapiFhirH2Dialect;
import ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgres94Dialect;
import ca.uhn.fhir.jpa.model.entity.ModelConfig;
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
Expand Down Expand Up @@ -99,7 +100,7 @@ public DataSource dataSource() {

BasicDataSource retVal = new BasicDataSource();
if (CommonConfig.isLocalTestMode()) {
retVal.setUrl("jdbc:derby:memory:fhirtest_r5;create=true");
retVal.setUrl("jdbc:h2:mem:fhirtest_r5");
} else {
retVal.setDriver(new org.postgresql.Driver());
retVal.setUrl("jdbc:postgresql://localhost/fhirtest_r5");
Expand Down Expand Up @@ -142,7 +143,7 @@ public LocalContainerEntityManagerFactoryBean entityManagerFactory(ConfigurableL
private Properties jpaProperties() {
Properties extraProperties = new Properties();
if (CommonConfig.isLocalTestMode()) {
extraProperties.put("hibernate.dialect", DerbyTenSevenHapiFhirDialect.class.getName());
extraProperties.put("hibernate.dialect", HapiFhirH2Dialect.class.getName());
} else {
extraProperties.put("hibernate.dialect", HapiFhirPostgres94Dialect.class.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public AuthorizedList addCodeInValueSet(String theResourceName, String theSearch
Validate.notBlank(theSearchParameterName, "theSearchParameterName must not be missing or null");
Validate.notBlank(theValueSetUrl, "theResourceUrl must not be missing or null");

myAllowedCodeInValueSets.add(new AllowedCodeInValueSet(theResourceName, theSearchParameterName, theValueSetUrl))
// myAllowedCodeInValueSets.add(new AllowedCodeInValueSet(theResourceName, theSearchParameterName, theValueSetUrl))

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import java.util.function.Supplier;

public class GraphQLProvider {
private Logger ourLog = LoggerFactory.getLogger(GraphQLProvider.class);
private static final Logger ourLog = LoggerFactory.getLogger(GraphQLProvider.class);

private final Supplier<IGraphQLEngine> myEngineFactory;
private final IGraphQLStorageServices myStorageServices;
Expand Down Expand Up @@ -137,7 +137,7 @@ public String processGraphQLRequest(ServletRequestDetails theRequestDetails, IId
try {
parsedGraphQLRequest = Parser.parse(theQuery);
} catch (Exception e) {
throw new InvalidRequestException("Unable to parse GraphQL Expression: " + e);
throw new InvalidRequestException(Msg.code(1146) + "Unable to parse GraphQL Expression: " + e);
}

return processGraphQLRequest(theRequestDetails, theId, parsedGraphQLRequest);
Expand All @@ -147,15 +147,7 @@ protected String processGraphQLRequest(ServletRequestDetails theRequestDetails,
IGraphQLEngine engine = myEngineFactory.get();
engine.setAppInfo(theRequestDetails);
engine.setServices(myStorageServices);
<<<<<<< HEAD
engine.setGraphQL(parsedGraphQLRequest);
=======
try {
engine.setGraphQL(Parser.parse(theQuery));
} catch (Exception theE) {
throw new InvalidRequestException(Msg.code(1146) + "Unable to parse GraphQL Expression: " + theE.toString());
}
>>>>>>> master

try {

Expand Down Expand Up @@ -185,7 +177,7 @@ protected String processGraphQLRequest(ServletRequestDetails theRequestDetails,
ourLog.error("Failure during GraphQL processing", e);
}
b.append(e.getMessage());
throw new UnclassifiedServerFailureException(statusCode, Msg.code(1147) + b.toString());
throw new UnclassifiedServerFailureException(statusCode, Msg.code(1147) + b);
}
}

Expand Down