use of graphql.GraphQL in project nextprot-api by calipho-sib.
the class GraphQLTest method main.
public static void main(String[] args) {
String schema = "type Query{hello: String} schema{query: Query}";
SchemaParser schemaParser = new SchemaParser();
TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema);
RuntimeWiring runtimeWiring = newRuntimeWiring().type("Query", builder -> builder.dataFetcher("hello", new StaticDataFetcher("world"))).build();
SchemaGenerator schemaGenerator = new SchemaGenerator();
GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
GraphQL build = GraphQL.newGraphQL(graphQLSchema).build();
ExecutionResult executionResult = build.execute("{hello}");
System.out.println(executionResult.getData().toString());
// Prints: {hello=world}
}
use of graphql.GraphQL in project nextprot-api by calipho-sib.
the class GraphQlExecutorImpl method postConstruct.
@PostConstruct
private void postConstruct() {
SchemaParser schemaParser = new SchemaParser();
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("swapi.graphqls").getFile());
TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(file);
RuntimeWiring runtimeWiring = newRuntimeWiring().type("Query", builder -> builder.dataFetcher("entry", entryDataFetcher)).build();
SchemaGenerator schemaGenerator = new SchemaGenerator();
GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
graphQL = GraphQL.newGraphQL(graphQLSchema).build();
}
use of graphql.GraphQL in project engine by craftercms.
the class SiteContext method buildGraphQLSchema.
protected void buildGraphQLSchema() {
logger.info("Starting GraphQL schema build for site '{}'", siteName);
StopWatch stopWatch = new StopWatch();
stopWatch.start();
publishEvent(new GraphQLBuildStartedEvent(this));
try {
GraphQL graphQL = graphQLFactory.getInstance(this);
if (Objects.nonNull(graphQL)) {
this.graphQL = graphQL;
publishEvent(new GraphQLBuildCompletedEvent(this));
}
} catch (Exception e) {
logger.error("Error building the GraphQL schema for site '" + siteName + "'", e);
}
stopWatch.stop();
logger.info("GraphQL schema build completed for site '{}' in {} secs", siteName, stopWatch.getTime(TimeUnit.SECONDS));
}
use of graphql.GraphQL in project carbon-apimgt by wso2.
the class QueryAnalyzer method analyseQueryDepth.
/**
* This method analyses the query depth.
*
* @param maxQueryDepth maximum query depth
* @param payload payload of the request
* @return true, if the query depth does not exceed the maximum value or false, if query depth exceeds the maximum
*/
public QueryAnalyzerResponseDTO analyseQueryDepth(int maxQueryDepth, String payload) {
if (log.isDebugEnabled()) {
log.debug("Analyzing query depth for " + payload + " and max query depth:" + maxQueryDepth);
}
QueryAnalyzerResponseDTO queryAnalyzerResponseDTO = new QueryAnalyzerResponseDTO();
// If maxQueryDepth is a positive value, perform the depth limitation check. Otherwise, bypass the check.
if (maxQueryDepth > 0) {
MaxQueryDepthInstrumentation maxQueryDepthInstrumentation = new MaxQueryDepthInstrumentation(maxQueryDepth);
GraphQL runtime = GraphQL.newGraphQL(schema).instrumentation(maxQueryDepthInstrumentation).build();
ExecutionResult executionResult = runtime.execute(payload);
List<GraphQLError> errors = executionResult.getErrors();
if (errors.size() > 0) {
for (GraphQLError error : errors) {
queryAnalyzerResponseDTO.addErrorToList((error.getMessage()));
}
// TODO: https://github.com/wso2/carbon-apimgt/issues/8147
queryAnalyzerResponseDTO.getErrorList().removeIf(s -> s.contains("non-nullable"));
if (queryAnalyzerResponseDTO.getErrorList().size() == 0) {
if (log.isDebugEnabled()) {
log.debug("Maximum query depth of " + maxQueryDepth + " was not exceeded");
}
queryAnalyzerResponseDTO.setSuccess(true);
return queryAnalyzerResponseDTO;
}
log.error(queryAnalyzerResponseDTO.getErrorList().toString());
queryAnalyzerResponseDTO.setSuccess(false);
return queryAnalyzerResponseDTO;
}
}
queryAnalyzerResponseDTO.setSuccess(true);
return queryAnalyzerResponseDTO;
}
use of graphql.GraphQL in project vertx-examples by vert-x3.
the class Server method createGraphQL.
private GraphQL createGraphQL() {
String schema = vertx.fileSystem().readFileBlocking("links.graphqls").toString();
SchemaParser schemaParser = new SchemaParser();
TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema);
RuntimeWiring runtimeWiring = newRuntimeWiring().type("Query", builder -> {
VertxDataFetcher<List<Link>> getAllLinks = new VertxDataFetcher<>(this::getAllLinks);
return builder.dataFetcher("allLinks", getAllLinks);
}).build();
SchemaGenerator schemaGenerator = new SchemaGenerator();
GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
return GraphQL.newGraphQL(graphQLSchema).build();
}
Aggregations