use of graphql.language.Argument in project graphql-java by graphql-java.
the class SchemaDiff method checkDirectives.
void checkDirectives(DiffCtx ctx, TypeDefinition old, List<Directive> oldDirectives, List<Directive> newDirectives) {
if (!options.enforceDirectives) {
return;
}
Map<String, Directive> oldDirectivesMap = sortedMap(oldDirectives, Directive::getName);
Map<String, Directive> newDirectivesMap = sortedMap(newDirectives, Directive::getName);
for (String directiveName : oldDirectivesMap.keySet()) {
Directive oldDirective = oldDirectivesMap.get(directiveName);
Optional<Directive> newDirective = Optional.ofNullable(newDirectivesMap.get(directiveName));
if (!newDirective.isPresent()) {
ctx.report(DiffEvent.apiBreakage().category(DiffCategory.MISSING).typeName(old.getName()).typeKind(getTypeKind(old)).components(directiveName).reasonMsg("The new API does not have a directive named '%s' on type '%s'", directiveName, old.getName()).build());
continue;
}
Map<String, Argument> oldArgumentsByName = new TreeMap<>(oldDirective.getArgumentsByName());
Map<String, Argument> newArgumentsByName = new TreeMap<>(newDirective.get().getArgumentsByName());
if (oldArgumentsByName.size() > newArgumentsByName.size()) {
ctx.report(DiffEvent.apiBreakage().category(DiffCategory.MISSING).typeName(old.getName()).typeKind(getTypeKind(old)).components(directiveName).reasonMsg("The new API has less arguments on directive '%s' on type '%s' than the old API", directiveName, old.getName()).build());
return;
}
for (String argName : oldArgumentsByName.keySet()) {
Argument oldArgument = oldArgumentsByName.get(argName);
Optional<Argument> newArgument = Optional.ofNullable(newArgumentsByName.get(argName));
if (!newArgument.isPresent()) {
ctx.report(DiffEvent.apiBreakage().category(DiffCategory.MISSING).typeName(old.getName()).typeKind(getTypeKind(old)).components(directiveName, argName).reasonMsg("The new API does not have an argument named '%s' on directive '%s' on type '%s'", argName, directiveName, old.getName()).build());
} else {
Value oldValue = oldArgument.getValue();
Value newValue = newArgument.get().getValue();
if (oldValue != null && newValue != null) {
if (!oldValue.getClass().equals(newValue.getClass())) {
ctx.report(DiffEvent.apiBreakage().category(DiffCategory.INVALID).typeName(old.getName()).typeKind(getTypeKind(old)).components(directiveName, argName).reasonMsg("The new API has changed value types on argument named '%s' on directive '%s' on type '%s'", argName, directiveName, old.getName()).build());
}
}
}
}
}
}
use of graphql.language.Argument in project graphql-java by graphql-java.
the class ValuesResolver method getArgumentValues.
public Map<String, Object> getArgumentValues(GraphqlFieldVisibility fieldVisibility, List<GraphQLArgument> argumentTypes, List<Argument> arguments, Map<String, Object> variables) {
if (argumentTypes.isEmpty()) {
return Collections.emptyMap();
}
Map<String, Object> result = new LinkedHashMap<>();
Map<String, Argument> argumentMap = argumentMap(arguments);
for (GraphQLArgument fieldArgument : argumentTypes) {
String argName = fieldArgument.getName();
Argument argument = argumentMap.get(argName);
Object value;
if (argument != null) {
value = coerceValueAst(fieldVisibility, fieldArgument.getType(), argument.getValue(), variables);
} else {
value = fieldArgument.getDefaultValue();
}
// the default value ended up being something non null
if (argumentMap.containsKey(argName) || value != null) {
result.put(argName, value);
}
}
return result;
}
use of graphql.language.Argument in project structr by structr.
the class QueryConfig method handleFieldArguments.
public void handleFieldArguments(final SecurityContext securityContext, final Class type, final Field parentField, final Field field) throws FrameworkException {
final ConfigurationProvider config = StructrApp.getConfiguration();
final PropertyKey parentKey = config.getPropertyKeyForJSONName(type, parentField.getName());
final PropertyKey key = config.getPropertyKeyForJSONName(type, field.getName(), false);
final List<SearchTuple> searchTuples = new LinkedList<>();
Occurrence occurrence = Occurrence.REQUIRED;
// parse arguments
for (final Argument argument : field.getArguments()) {
final String name = argument.getName();
final Value value = argument.getValue();
switch(name) {
case "_equals":
searchTuples.add(new SearchTuple(castValue(securityContext, key.relatedType(), key, value), true));
break;
case "_contains":
searchTuples.add(new SearchTuple(castValue(securityContext, key.relatedType(), key, value), false));
break;
case "_conj":
occurrence = getOccurrence(value);
break;
default:
break;
}
}
// only add field if a value was set
for (final SearchTuple tuple : searchTuples) {
addAttribute(parentKey, key.getSearchAttribute(securityContext, occurrence, tuple.value, tuple.exact, null), occurrence);
}
}
use of graphql.language.Argument in project structr by structr.
the class QueryConfig method handleTypeArguments.
public void handleTypeArguments(final SecurityContext securityContext, final Class type, final List<Argument> arguments) throws FrameworkException {
// parse arguments
for (final Argument argument : arguments) {
final String name = argument.getName();
final Value value = argument.getValue();
switch(name) {
case "_page":
this.page = getIntegerValue(value, 1);
break;
case "_pageSize":
case "_first":
this.pageSize = getIntegerValue(value, Integer.MAX_VALUE);
break;
case "_sort":
this.sortKeySource = getStringValue(value, "name");
this.sortKey = StructrApp.getConfiguration().getPropertyKeyForJSONName(type, sortKeySource, false);
break;
case "_desc":
this.sortDescending = getBooleanValue(value, false);
break;
default:
// handle simple selections like an _equals on the field
final PropertyKey key = StructrApp.getConfiguration().getPropertyKeyForJSONName(type, name, false);
if (key != null) {
addAttribute(key, key.getSearchAttribute(securityContext, Occurrence.REQUIRED, castValue(securityContext, type, key, value), true, null), Occurrence.REQUIRED);
}
break;
}
}
}
use of graphql.language.Argument 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;
}
Aggregations