private void checkObjectType(DiffCtx ctx, ObjectTypeDefinition oldDef, ObjectTypeDefinition newDef) { Map<String, FieldDefinition> oldFields = sortedMap(oldDef.getFieldDefinitions(), FieldDefinition::getName); Map<String, FieldDefinition> newFields = sortedMap(newDef.getFieldDefinitions(), FieldDefinition::getName); checkFields(ctx, oldDef, oldFields, newDef, newFields); checkImplements(ctx, oldDef, oldDef.getImplements(), newDef.getImplements()); checkDirectives(ctx, oldDef, newDef); }
private NodePrinter<ObjectTypeDefinition> objectTypeDefinition() { return (out, node) -> { out.printf("%s", comments(node)); out.printf("%s", spaced( "type", node.getName(), wrap("implements ", join(node.getImplements(), " & "), ""), directives(node.getDirectives()), block(node.getFieldDefinitions()) )); }; }
implementsTypes.forEach(checkInterfaceTypeExists(typeRegistry, errors, objectType)); checkFieldTypesPresent(typeRegistry, errors, objectType, objectType.getFieldDefinitions());
InterfaceTypeDefinition interfaceTypeDef = (InterfaceTypeDefinition) type.get(); Map<String, FieldDefinition> objectFields = objectTypeDef.getFieldDefinitions().stream() .collect(Collectors.toMap( FieldDefinition::getName, Function.identity(), mergeFirstValue()
private void checkFieldsAreSensible(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry) { Map<String, TypeDefinition> typesMap = typeRegistry.types(); // objects List<ObjectTypeDefinition> objectTypes = filterTo(typesMap, ObjectTypeDefinition.class); objectTypes.forEach(objectType -> checkObjTypeFields(errors, objectType, objectType.getFieldDefinitions())); // interfaces List<InterfaceTypeDefinition> interfaceTypes = filterTo(typesMap, InterfaceTypeDefinition.class); interfaceTypes.forEach(interfaceType -> checkInterfaceFields(errors, interfaceType, interfaceType.getFieldDefinitions())); // enum types List<EnumTypeDefinition> enumTypes = filterTo(typesMap, EnumTypeDefinition.class); enumTypes.forEach(enumType -> checkEnumValues(errors, enumType, enumType.getEnumValueDefinitions())); // input types List<InputObjectTypeDefinition> inputTypes = filterTo(typesMap, InputObjectTypeDefinition.class); inputTypes.forEach(inputType -> checkInputValues(errors, inputType, inputType.getInputValueDefinitions())); }
@Override public TraversalControl visitObjectTypeDefinition(ObjectTypeDefinition node, TraverserContext<Node> context) { ObjectTypeDefinition changedNode = node.transform(builder -> { builder.directives(sort(node.getDirectives(), comparing(Directive::getName))); builder.implementz(sort(node.getImplements(), comparingTypes())); builder.fieldDefinitions(sort(node.getFieldDefinitions(), comparing(FieldDefinition::getName))); }); return changeNode(context, changedNode); }
private Builder(ObjectTypeDefinition existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); this.description = existing.getDescription(); this.directives = existing.getDirectives(); this.implementz = existing.getImplements(); this.fieldDefinitions = existing.getFieldDefinitions(); this.ignoredChars = existing.getIgnoredChars(); }
private void checkDirectives(DirectiveLocation expectedLocation, List<GraphQLError> errors, TypeDefinition<?> typeDef) { checkDirectives(expectedLocation, errors, typeRegistry, typeDef, typeDef.getName(), typeDef.getDirectives()); if (typeDef instanceof ObjectTypeDefinition) { List<FieldDefinition> fieldDefinitions = ((ObjectTypeDefinition) typeDef).getFieldDefinitions(); checkFieldsDirectives(errors, typeRegistry, fieldDefinitions); } if (typeDef instanceof InterfaceTypeDefinition) { List<FieldDefinition> fieldDefinitions = ((InterfaceTypeDefinition) typeDef).getFieldDefinitions(); checkFieldsDirectives(errors, typeRegistry, fieldDefinitions); } if (typeDef instanceof EnumTypeDefinition) { List<EnumValueDefinition> enumValueDefinitions = ((EnumTypeDefinition) typeDef).getEnumValueDefinitions(); enumValueDefinitions.forEach(definition -> checkDirectives(ENUM_VALUE, errors, typeRegistry, definition, definition.getName(), definition.getDirectives())); } if (typeDef instanceof InputObjectTypeDefinition) { List<InputValueDefinition> inputValueDefinitions = ((InputObjectTypeDefinition) typeDef).getInputValueDefinitions(); inputValueDefinitions.forEach(definition -> checkDirectives(INPUT_FIELD_DEFINITION, errors, typeRegistry, definition, definition.getName(), definition.getDirectives())); } }
baseTypeOpt.ifPresent(baseTypeDef -> checkForFieldRedefinition(errors, extension, fieldDefinitions, baseTypeDef.getFieldDefinitions()));
typeDefinition.getFieldDefinitions().forEach(fieldDef -> { FieldDefAndDirectiveParams fieldAndParams = buildField(buildCtx, typeDefinition, fieldDef); builder.field(fieldAndParams.fieldDefinition);
public boolean hasIdField() { if ( definition instanceof ObjectTypeDefinition) { return ((ObjectTypeDefinition)definition).getFieldDefinitions() .stream() .anyMatch((field) -> "id".equals(field.getName())); } return false; }
private void addImports(Collection<String> imports, ObjectTypeDefinition def) { for ( FieldDefinition fieldDef : def.getFieldDefinitions() ) { addImports(imports, fieldDef.getType()); } }
private void checkObjectType(DiffCtx ctx, ObjectTypeDefinition oldDef, ObjectTypeDefinition newDef) { Map<String, FieldDefinition> oldFields = sortedMap(oldDef.getFieldDefinitions(), FieldDefinition::getName); Map<String, FieldDefinition> newFields = sortedMap(newDef.getFieldDefinitions(), FieldDefinition::getName); checkFields(ctx, oldDef, oldFields, newDef, newFields); checkImplements(ctx, oldDef, oldDef.getImplements(), newDef.getImplements()); checkDirectives(ctx, oldDef, newDef); }
private void checkFieldsAreSensible(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry) { Map<String, TypeDefinition> typesMap = typeRegistry.types(); // objects List<ObjectTypeDefinition> objectTypes = filterTo(typesMap, ObjectTypeDefinition.class); objectTypes.forEach(objectType -> checkObjTypeFields(errors, objectType, objectType.getFieldDefinitions())); // interfaces List<InterfaceTypeDefinition> interfaceTypes = filterTo(typesMap, InterfaceTypeDefinition.class); interfaceTypes.forEach(interfaceType -> checkInterfaceFields(errors, interfaceType, interfaceType.getFieldDefinitions())); // enum types List<EnumTypeDefinition> enumTypes = filterTo(typesMap, EnumTypeDefinition.class); enumTypes.forEach(enumType -> checkEnumValues(errors, enumType, enumType.getEnumValueDefinitions())); // input types List<InputObjectTypeDefinition> inputTypes = filterTo(typesMap, InputObjectTypeDefinition.class); inputTypes.forEach(inputType -> checkInputValues(errors, inputType, inputType.getInputValueDefinitions())); }
private NodePrinter<ObjectTypeDefinition> objectTypeDefinition() { return (out, node) -> { out.printf("%s", comments(node)); out.printf("%s", spaced( "type", node.getName(), wrap("implements ", join(node.getImplements(), " & "), ""), directives(node.getDirectives()), block(node.getFieldDefinitions()) )); }; }
private List<Field> getFields(ObjectTypeDefinition def) { List<Field> fields = new ArrayList<Field>(); for ( FieldDefinition fieldDef : def.getFieldDefinitions() ) { Field field = new Field(fieldDef.getName(), toJavaTypeName(fieldDef.getType())); field.graphQLType = toGraphQLType(fieldDef.getType()); field.dataResolver = toDataResolver(fieldDef.getType()); field.args = toArgs(fieldDef.getInputValueDefinitions()); fields.add(field); } return fields; }
@Override public TraversalControl visitObjectTypeDefinition(ObjectTypeDefinition node, TraverserContext<Node> context) { ObjectTypeDefinition changedNode = node.transform(builder -> { builder.directives(sort(node.getDirectives(), comparing(Directive::getName))); builder.implementz(sort(node.getImplements(), comparingTypes())); builder.fieldDefinitions(sort(node.getFieldDefinitions(), comparing(FieldDefinition::getName))); }); return changeNode(context, changedNode); }
private Builder(ObjectTypeDefinition existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); this.description = existing.getDescription(); this.directives = existing.getDirectives(); this.implementz = existing.getImplements(); this.fieldDefinitions = existing.getFieldDefinitions(); this.ignoredChars = existing.getIgnoredChars(); }
private void checkDirectives(DirectiveLocation expectedLocation, List<GraphQLError> errors, TypeDefinition<?> typeDef) { checkDirectives(expectedLocation, errors, typeRegistry, typeDef, typeDef.getName(), typeDef.getDirectives()); if (typeDef instanceof ObjectTypeDefinition) { List<FieldDefinition> fieldDefinitions = ((ObjectTypeDefinition) typeDef).getFieldDefinitions(); checkFieldsDirectives(errors, typeRegistry, fieldDefinitions); } if (typeDef instanceof InterfaceTypeDefinition) { List<FieldDefinition> fieldDefinitions = ((InterfaceTypeDefinition) typeDef).getFieldDefinitions(); checkFieldsDirectives(errors, typeRegistry, fieldDefinitions); } if (typeDef instanceof EnumTypeDefinition) { List<EnumValueDefinition> enumValueDefinitions = ((EnumTypeDefinition) typeDef).getEnumValueDefinitions(); enumValueDefinitions.forEach(definition -> checkDirectives(ENUM_VALUE, errors, typeRegistry, definition, definition.getName(), definition.getDirectives())); } if (typeDef instanceof InputObjectTypeDefinition) { List<InputValueDefinition> inputValueDefinitions = ((InputObjectTypeDefinition) typeDef).getInputValueDefinitions(); inputValueDefinitions.forEach(definition -> checkDirectives(INPUT_FIELD_DEFINITION, errors, typeRegistry, definition, definition.getName(), definition.getDirectives())); } }
typeDefinition.getFieldDefinitions().forEach(fieldDef -> { FieldDefAndDirectiveParams fieldAndParams = buildField(buildCtx, typeDefinition, fieldDef); builder.field(fieldAndParams.fieldDefinition);