use of graphql.language.InputValueDefinition in project graphql-java by graphql-java.
the class GraphqlAntlrToLanguage method visitInputValueDefinition.
@Override
public Void visitInputValueDefinition(GraphqlParser.InputValueDefinitionContext ctx) {
InputValueDefinition def = new InputValueDefinition(ctx.name().getText());
newNode(def, ctx);
def.setDescription(newDescription(ctx.description()));
if (ctx.defaultValue() != null) {
def.setDefaultValue(getValue(ctx.defaultValue().value()));
}
for (ContextEntry contextEntry : contextStack) {
if (contextEntry.contextProperty == ContextProperty.FieldDefinition) {
((FieldDefinition) contextEntry.value).getInputValueDefinitions().add(def);
break;
}
if (contextEntry.contextProperty == ContextProperty.InputObjectTypeDefinition) {
((InputObjectTypeDefinition) contextEntry.value).getInputValueDefinitions().add(def);
break;
}
if (contextEntry.contextProperty == ContextProperty.DirectiveDefinition) {
((DirectiveDefinition) contextEntry.value).getInputValueDefinitions().add(def);
break;
}
}
addContextProperty(ContextProperty.InputValueDefinition, def);
super.visitChildren(ctx);
popContext();
return null;
}
use of graphql.language.InputValueDefinition in project graphql-java by graphql-java.
the class GraphqlAntlrToLanguage method visitDirective.
@Override
public Void visitDirective(GraphqlParser.DirectiveContext ctx) {
Directive directive = new Directive(ctx.name().getText());
newNode(directive, ctx);
for (ContextEntry contextEntry : contextStack) {
if (contextEntry.contextProperty == ContextProperty.Field) {
((Field) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.FragmentDefinition) {
((FragmentDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.FragmentSpread) {
((FragmentSpread) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.InlineFragment) {
((InlineFragment) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.OperationDefinition) {
((OperationDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.EnumValueDefinition) {
((EnumValueDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.FieldDefinition) {
((FieldDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.InputValueDefinition) {
((InputValueDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.InterfaceTypeDefinition) {
((InterfaceTypeDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.EnumTypeDefinition) {
((EnumTypeDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.ObjectTypeDefinition) {
((ObjectTypeDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.ScalarTypeDefinition) {
((ScalarTypeDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.UnionTypeDefinition) {
((UnionTypeDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.InputObjectTypeDefinition) {
((InputObjectTypeDefinition) contextEntry.value).getDirectives().add(directive);
break;
} else if (contextEntry.contextProperty == ContextProperty.SchemaDefinition) {
((SchemaDefinition) contextEntry.value).getDirectives().add(directive);
break;
}
}
addContextProperty(ContextProperty.Directive, directive);
super.visitDirective(ctx);
popContext();
return null;
}
use of graphql.language.InputValueDefinition in project graphql-java by graphql-java.
the class IntrospectionResultToSchema method createInputValueDefinitions.
@SuppressWarnings("unchecked")
private List<InputValueDefinition> createInputValueDefinitions(List<Map<String, Object>> args) {
List<InputValueDefinition> result = new ArrayList<>();
for (Map<String, Object> arg : args) {
Type argType = createTypeIndirection((Map<String, Object>) arg.get("type"));
InputValueDefinition inputValueDefinition = new InputValueDefinition((String) arg.get("name"), argType);
inputValueDefinition.setComments(toComment((String) arg.get("description")));
String valueLiteral = (String) arg.get("defaultValue");
if (valueLiteral != null) {
Value defaultValue = AstValueHelper.valueFromAst(valueLiteral);
inputValueDefinition.setDefaultValue(defaultValue);
}
result.add(inputValueDefinition);
}
return result;
}
use of graphql.language.InputValueDefinition in project graphql-java by graphql-java.
the class SchemaDiff method checkInputFields.
private void checkInputFields(DiffCtx ctx, TypeDefinition old, List<InputValueDefinition> oldIVD, List<InputValueDefinition> newIVD) {
Map<String, InputValueDefinition> oldDefinitionMap = sortedMap(oldIVD, InputValueDefinition::getName);
Map<String, InputValueDefinition> newDefinitionMap = sortedMap(newIVD, InputValueDefinition::getName);
for (String inputFieldName : oldDefinitionMap.keySet()) {
InputValueDefinition oldField = oldDefinitionMap.get(inputFieldName);
Optional<InputValueDefinition> newField = Optional.ofNullable(newDefinitionMap.get(inputFieldName));
ctx.report(DiffEvent.apiInfo().typeName(old.getName()).typeKind(getTypeKind(old)).fieldName(oldField.getName()).reasonMsg("\tExamining input field '%s' ...", mkDotName(old.getName(), oldField.getName())).build());
if (!newField.isPresent()) {
ctx.report(DiffEvent.apiBreakage().category(DiffCategory.MISSING).typeName(old.getName()).typeKind(getTypeKind(old)).fieldName(oldField.getName()).reasonMsg("The new API is missing an input field '%s'", mkDotName(old.getName(), oldField.getName())).build());
} else {
DiffCategory category = checkTypeWithNonNullAndList(oldField.getType(), newField.get().getType());
if (category != null) {
ctx.report(DiffEvent.apiBreakage().category(category).typeName(old.getName()).typeKind(getTypeKind(old)).fieldName(oldField.getName()).components(getAstDesc(oldField.getType()), getAstDesc(newField.get().getType())).reasonMsg("The new API has changed input field '%s' from type '%s' to '%s'", oldField.getName(), getAstDesc(oldField.getType()), getAstDesc(newField.get().getType())).build());
}
}
}
// check new fields are not mandatory
for (String inputFieldName : newDefinitionMap.keySet()) {
InputValueDefinition newField = newDefinitionMap.get(inputFieldName);
Optional<InputValueDefinition> oldField = Optional.ofNullable(oldDefinitionMap.get(inputFieldName));
if (!oldField.isPresent()) {
// new fields MUST not be mandatory
if (typeInfo(newField.getType()).isNonNull()) {
ctx.report(DiffEvent.apiBreakage().category(DiffCategory.STRICTER).typeName(old.getName()).typeKind(getTypeKind(old)).fieldName(newField.getName()).reasonMsg("The new API has made the new input field '%s' non null and hence more strict for old consumers", newField.getName()).build());
}
}
}
}
Aggregations