use of graphql.language.Selection in project structr by structr.
the class GraphQLQuery method init.
// ----- private methods -----
private void init(final SecurityContext securityContext, final Class type, final Field field, final String path) throws FrameworkException {
final QueryConfig config = getConfig(path);
config.handleTypeArguments(securityContext, type, field.getArguments());
final SelectionSet selectionSet = field.getSelectionSet();
if (selectionSet != null) {
for (final Selection selection : selectionSet.getSelections()) {
if (selection instanceof Field) {
final Field childField = (Field) selection;
final SelectionSet childSet = childField.getSelectionSet();
final PropertyKey key = StructrApp.getConfiguration().getPropertyKeyForJSONName(type, childField.getName());
final Class relatedType = key.relatedType() != null ? key.relatedType() : type;
// add field to property set
config.addPropertyKey(key);
config.handleFieldArguments(securityContext, relatedType, field, childField);
// recurse
if (childSet != null) {
init(securityContext, relatedType, childField, path + "/" + childField.getName());
}
}
}
}
}
use of graphql.language.Selection in project nextprot-api by calipho-sib.
the class EntryDataFetcherImpl method get.
@Override
public Entry get(DataFetchingEnvironment environment) {
// TODO THIS IS A POC (Proof of Concept)
// If we decide to go ahead with GraphQL please try to adapt this terrible function using EntryQueryResolver that implements GraphQLQueryResolver
// graphql java tools allows to do newSchemaParser().file(schemaFile).resolvers(...).getSchemaObjects.getGraphqlSchema
String accession = environment.getArgument("accession");
Integer publicationLimit = -1;
Integer annotationLimit = -1;
String category = "";
// Searching for publication limit
Optional<Selection> publicationField = environment.getFields().get(0).getSelectionSet().getSelections().stream().filter(f -> ((Field) f).getName().equals("publications")).findAny();
if (publicationField.isPresent()) {
Optional<Argument> publicationLimitArg = ((Field) publicationField.get()).getArguments().stream().filter(f -> f.getName().equals("limit")).findAny();
if (publicationLimitArg.isPresent()) {
publicationLimit = Integer.valueOf(publicationLimitArg.get().getValue().toString().replace("IntValue{value=", "").replace("}", ""));
}
}
// Searching for annotation field
Optional<Selection> annotationField = environment.getFields().get(0).getSelectionSet().getSelections().stream().filter(f -> ((Field) f).getName().equals("annotations")).findAny();
if (annotationField.isPresent()) {
Optional<Argument> publicationLimitArg = ((Field) annotationField.get()).getArguments().stream().filter(f -> f.getName().equals("category")).findAny();
if (publicationLimitArg.isPresent()) {
category = publicationLimitArg.get().getValue().toString().replace("StringValue{value='", "").replace("'}", "");
}
Optional<Argument> annotationLimitArg = ((Field) annotationField.get()).getArguments().stream().filter(f -> f.getName().equals("limit")).findAny();
if (annotationLimitArg.isPresent()) {
annotationLimit = Integer.valueOf(annotationLimitArg.get().getValue().toString().replace("IntValue{value=", "").replace("}", ""));
}
}
Entry entry = entryBuilderService.build(EntryConfig.newConfig(accession).with(category).withPublications().withOverview().withTargetIsoforms());
if (publicationLimit != -1) {
List<Publication> publications = entry.getPublications();
List<Publication> publicationSubset = publications.subList(0, publicationLimit);
entry.setPublications(publicationSubset);
}
if (annotationLimit != -1) {
String cat = entry.getAnnotationsByCategory().keySet().iterator().next();
entry.setAnnotations(entry.getAnnotationsByCategory(AnnotationCategory.getDecamelizedAnnotationTypeName(cat)).subList(0, annotationLimit));
}
return entry;
}
use of graphql.language.Selection in project structr by structr.
the class GraphQLRequest method initialize.
// ----- private methods -----
private void initialize(final SecurityContext securityContext, Document document) throws FrameworkException {
for (final Node child : document.getChildren()) {
if (child instanceof OperationDefinition) {
final OperationDefinition operationDefinition = (OperationDefinition) child;
final SelectionSet selectionSet = operationDefinition.getSelectionSet();
for (final Selection selection : selectionSet.getSelections()) {
if (selection instanceof Field) {
queries.add(new GraphQLQuery(securityContext, (Field) selection));
} else {
logger.warn("Unknown selection set element {} in GraphQL query, ignoring.", selection.getClass());
}
}
} else {
logger.warn("Unknown document element {} in GraphQL query, ignoring.", child.getClass());
}
}
}
Aggregations