use of graphql.language.FieldDefinition in project graphql-java by graphql-java.
the class GraphqlAntlrToLanguage method visitNonNullType.
@Override
public Void visitNonNullType(GraphqlParser.NonNullTypeContext ctx) {
NonNullType nonNullType = new NonNullType();
newNode(nonNullType, ctx);
for (ContextEntry contextEntry : contextStack) {
if (contextEntry.value instanceof ListType) {
((ListType) contextEntry.value).setType(nonNullType);
break;
}
if (contextEntry.value instanceof VariableDefinition) {
((VariableDefinition) contextEntry.value).setType(nonNullType);
break;
}
if (contextEntry.value instanceof FieldDefinition) {
((FieldDefinition) contextEntry.value).setType(nonNullType);
break;
}
if (contextEntry.value instanceof InputValueDefinition) {
((InputValueDefinition) contextEntry.value).setType(nonNullType);
break;
}
}
addContextProperty(ContextProperty.NonNullType, nonNullType);
super.visitNonNullType(ctx);
popContext();
return null;
}
use of graphql.language.FieldDefinition in project graphql-java by graphql-java.
the class GraphqlAntlrToLanguage method visitFieldDefinition.
@Override
public Void visitFieldDefinition(GraphqlParser.FieldDefinitionContext ctx) {
FieldDefinition def = new FieldDefinition(ctx.name().getText());
newNode(def, ctx);
def.setDescription(newDescription(ctx.description()));
for (ContextEntry contextEntry : contextStack) {
if (contextEntry.contextProperty == ContextProperty.InterfaceTypeDefinition) {
((InterfaceTypeDefinition) contextEntry.value).getFieldDefinitions().add(def);
break;
}
if (contextEntry.contextProperty == ContextProperty.ObjectTypeDefinition) {
((ObjectTypeDefinition) contextEntry.value).getFieldDefinitions().add(def);
break;
}
}
addContextProperty(ContextProperty.FieldDefinition, def);
super.visitChildren(ctx);
popContext();
return null;
}
use of graphql.language.FieldDefinition in project graphql-java by graphql-java.
the class IntrospectionResultToSchema method createFields.
private List<FieldDefinition> createFields(List<Map<String, Object>> fields) {
List<FieldDefinition> result = new ArrayList<>();
for (Map<String, Object> field : fields) {
FieldDefinition fieldDefinition = new FieldDefinition((String) field.get("name"));
fieldDefinition.setComments(toComment((String) field.get("description")));
fieldDefinition.setType(createTypeIndirection((Map<String, Object>) field.get("type")));
createDeprecatedDirective(field, fieldDefinition.getDirectives());
List<Map<String, Object>> args = (List<Map<String, Object>>) field.get("args");
List<InputValueDefinition> inputValueDefinitions = createInputValueDefinitions(args);
fieldDefinition.getInputValueDefinitions().addAll(inputValueDefinitions);
result.add(fieldDefinition);
}
return result;
}
use of graphql.language.FieldDefinition in project graphql-java by graphql-java.
the class SchemaDiff method checkFieldRemovals.
private void checkFieldRemovals(DiffCtx ctx, TypeDefinition oldDef, Map<String, FieldDefinition> oldFields, Map<String, FieldDefinition> newFields) {
for (Map.Entry<String, FieldDefinition> entry : oldFields.entrySet()) {
String fieldName = entry.getKey();
ctx.report(DiffEvent.apiInfo().typeName(oldDef.getName()).typeKind(getTypeKind(oldDef)).fieldName(fieldName).reasonMsg("\tExamining field '%s' ...", mkDotName(oldDef.getName(), fieldName)).build());
FieldDefinition newField = newFields.get(fieldName);
if (newField == null) {
ctx.report(DiffEvent.apiBreakage().category(DiffCategory.MISSING).typeName(oldDef.getName()).typeKind(getTypeKind(oldDef)).fieldName(fieldName).reasonMsg("The new API is missing the field '%s'", mkDotName(oldDef.getName(), fieldName)).build());
} else {
checkField(ctx, oldDef, entry.getValue(), newField);
}
}
}
use of graphql.language.FieldDefinition in project graphql-java by graphql-java.
the class SchemaTypeChecker method checkInterfaceFields.
private void checkInterfaceFields(List<GraphQLError> errors, InterfaceTypeDefinition interfaceType, List<FieldDefinition> fieldDefinitions) {
// field unique ness
checkNamedUniqueness(errors, fieldDefinitions, FieldDefinition::getName, (name, fieldDef) -> new NonUniqueNameError(interfaceType, fieldDef));
// field arg unique ness
fieldDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getInputValueDefinitions(), InputValueDefinition::getName, (name, inputValueDefinition) -> new NonUniqueArgumentError(interfaceType, fld, name)));
// directive checks
fieldDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(interfaceType, fld, directiveName)));
fieldDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> {
checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(interfaceType, fld));
checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(interfaceType, fld, argumentName));
}));
}
Aggregations