use of graphql.schema.GraphQLType in project graphql-java by graphql-java.
the class OverlappingFieldsCanBeMerged method collectFieldsForInlineFragment.
private void collectFieldsForInlineFragment(Map<String, List<FieldAndType>> fieldMap, Set<String> visitedFragmentSpreads, GraphQLType parentType, InlineFragment inlineFragment) {
GraphQLType graphQLType = inlineFragment.getTypeCondition() != null ? (GraphQLOutputType) TypeFromAST.getTypeFromAST(getValidationContext().getSchema(), inlineFragment.getTypeCondition()) : parentType;
collectFields(fieldMap, inlineFragment.getSelectionSet(), graphQLType, visitedFragmentSpreads);
}
use of graphql.schema.GraphQLType in project graphql-java by graphql-java.
the class OverlappingFieldsCanBeMerged method findConflict.
@SuppressWarnings("ConstantConditions")
private Conflict findConflict(String responseName, FieldAndType fieldAndType1, FieldAndType fieldAndType2) {
Field field1 = fieldAndType1.field;
Field field2 = fieldAndType2.field;
GraphQLType type1 = fieldAndType1.graphQLType;
GraphQLType type2 = fieldAndType2.graphQLType;
String fieldName1 = field1.getName();
String fieldName2 = field2.getName();
if (isAlreadyChecked(field1, field2)) {
return null;
}
alreadyChecked.add(new FieldPair(field1, field2));
// thus may not safely diverge.
if (!sameType(fieldAndType1.parentType, fieldAndType1.parentType) && fieldAndType1.parentType instanceof GraphQLObjectType && fieldAndType2.parentType instanceof GraphQLObjectType) {
return null;
}
if (!fieldName1.equals(fieldName2)) {
String reason = String.format("%s: %s and %s are different fields", responseName, fieldName1, fieldName2);
return new Conflict(responseName, reason, field1, field2);
}
if (!sameType(type1, type2)) {
String name1 = type1 != null ? type1.getName() : "null";
String name2 = type2 != null ? type2.getName() : "null";
String reason = String.format("%s: they return differing types %s and %s", responseName, name1, name2);
return new Conflict(responseName, reason, field1, field2);
}
if (!sameArguments(field1.getArguments(), field2.getArguments())) {
String reason = String.format("%s: they have differing arguments", responseName);
return new Conflict(responseName, reason, field1, field2);
}
SelectionSet selectionSet1 = field1.getSelectionSet();
SelectionSet selectionSet2 = field2.getSelectionSet();
if (selectionSet1 != null && selectionSet2 != null) {
Set<String> visitedFragmentSpreads = new LinkedHashSet<>();
Map<String, List<FieldAndType>> subFieldMap = new LinkedHashMap<>();
collectFields(subFieldMap, selectionSet1, type1, visitedFragmentSpreads);
collectFields(subFieldMap, selectionSet2, type2, visitedFragmentSpreads);
List<Conflict> subConflicts = findConflicts(subFieldMap);
if (subConflicts.size() > 0) {
String reason = String.format("%s: %s", responseName, joinReasons(subConflicts));
List<Field> fields = new ArrayList<>();
fields.add(field1);
fields.add(field2);
fields.addAll(collectFields(subConflicts));
return new Conflict(responseName, reason, fields);
}
}
return null;
}
use of graphql.schema.GraphQLType in project graphql-java by graphql-java.
the class PossibleFragmentSpreads method checkFragmentSpread.
@Override
public void checkFragmentSpread(FragmentSpread fragmentSpread) {
FragmentDefinition fragment = getValidationContext().getFragment(fragmentSpread.getName());
if (fragment == null)
return;
GraphQLType typeCondition = TypeFromAST.getTypeFromAST(getValidationContext().getSchema(), fragment.getTypeCondition());
GraphQLCompositeType parentType = getValidationContext().getParentType();
if (typeCondition == null || parentType == null)
return;
if (!doTypesOverlap(typeCondition, parentType)) {
String message = String.format("Fragment %s cannot be spread here as objects of " + "type %s can never be of type %s", fragmentSpread.getName(), parentType, typeCondition);
addError(ValidationErrorType.InvalidFragmentType, fragmentSpread.getSourceLocation(), message);
}
}
use of graphql.schema.GraphQLType in project graphql-java by graphql-java.
the class VariablesAreInputTypes method checkVariableDefinition.
@Override
public void checkVariableDefinition(VariableDefinition variableDefinition) {
TypeName unmodifiedAstType = getValidationUtil().getUnmodifiedType(variableDefinition.getType());
GraphQLType type = getValidationContext().getSchema().getType(unmodifiedAstType.getName());
if (type == null)
return;
if (!schemaUtil.isInputType(type)) {
String message = "Wrong type for a variable";
addError(ValidationErrorType.NonInputTypeOnVariable, variableDefinition.getSourceLocation(), message);
}
}
use of graphql.schema.GraphQLType in project graphql-java by graphql-java.
the class TraversalContext method enterImpl.
private void enterImpl(VariableDefinition variableDefinition) {
GraphQLType type = TypeFromAST.getTypeFromAST(schema, variableDefinition.getType());
addInputType(type != null ? (GraphQLInputType) type : null);
}
Aggregations