private void checkDirectives(DiffCtx ctx, TypeDefinition oldDef, TypeDefinition newDef) { List<Directive> oldDirectives = oldDef.getDirectives(); List<Directive> newDirectives = newDef.getDirectives(); checkDirectives(ctx, oldDef, oldDirectives, newDirectives); }
GraphQLOutputType hasOutputType(TypeDefinition typeDefinition) { return outputGTypes.get(typeDefinition.getName()); }
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())); } }
List<Node> children = context.getChildren(); type.getDirectives().forEach(dir -> { if (dir.getName().equals("service")) { String getQueryUri = typeUri + "_GET"; List<Node> typeChildren = type.getChildren();
@Test public void testSchema() { GraphQLObjectType object = GraphQLAnnotations.object(TestObject.class); String schema = new SchemaPrinter().print(object); assertTrue(schema.contains("type TestObject {")); TypeDefinitionRegistry reg = new SchemaParser().parse(schema); assertTrue(reg.getType("TestObject").isPresent()); assertEquals(new SchemaParser().parse(schema).getType("TestObject").get().getChildren().size(), 8); }
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())); } }
List<Node> children = context.getChildren(); type.getDirectives().forEach(dir -> { if (dir.getName().equals("service")) { String getQueryUri = typeUri + "_GET"; List<Node> typeChildren = type.getChildren();
GraphQLInputType hasInputType(TypeDefinition typeDefinition) { return inputGTypes.get(typeDefinition.getName()); }
@SuppressWarnings("unchecked") private void checkTypeExtensionDirectiveRedefinition(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry, String name, List<? extends TypeDefinition> extensions, Class<? extends TypeDefinition> targetClass) { Optional<? extends TypeDefinition> typeDefinition = typeRegistry.getType(TypeName.newTypeName().name(name).build(), targetClass); if (typeDefinition.isPresent() && typeDefinition.get().getClass().equals(targetClass)) { List<Directive> directives = typeDefinition.get().getDirectives(); Map<String, Directive> directiveMap = FpKit.getByName(directives, Directive::getName, mergeFirst()); extensions.forEach(typeExt -> { List<Directive> extDirectives = typeExt.getDirectives(); extDirectives.forEach(directive -> { if (directiveMap.containsKey(directive.getName())) { errors.add(new TypeExtensionDirectiveRedefinitionError(typeDefinition.get(), directive)); } }); } ); } }
public MissingTypeResolverError(TypeDefinition typeDefinition) { super(typeDefinition, format("There is no type resolver defined for interface / union '%s' type", typeDefinition.getName())); }
private void checkDirectives(DiffCtx ctx, TypeDefinition oldDef, TypeDefinition newDef) { List<Directive> oldDirectives = oldDef.getDirectives(); List<Directive> newDirectives = newDef.getDirectives(); checkDirectives(ctx, oldDef, oldDirectives, newDirectives); }
private void removeFromList(Map source, TypeDefinition value) { List<TypeDefinition> list = (List<TypeDefinition>) source.get(value.getName()); if (list == null) { return; } list.remove(value); }
@SuppressWarnings("unchecked") private void checkTypeExtensionDirectiveRedefinition(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry, String name, List<? extends TypeDefinition> extensions, Class<? extends TypeDefinition> targetClass) { Optional<? extends TypeDefinition> typeDefinition = typeRegistry.getType(TypeName.newTypeName().name(name).build(), targetClass); if (typeDefinition.isPresent() && typeDefinition.get().getClass().equals(targetClass)) { List<Directive> directives = typeDefinition.get().getDirectives(); Map<String, Directive> directiveMap = FpKit.getByName(directives, Directive::getName, mergeFirst()); extensions.forEach(typeExt -> { List<Directive> extDirectives = typeExt.getDirectives(); extDirectives.forEach(directive -> { if (directiveMap.containsKey(directive.getName())) { errors.add(new TypeExtensionDirectiveRedefinitionError(typeDefinition.get(), directive)); } }); } ); } }
private <T extends TypeDefinition> Optional<GraphQLError> define(Map<String, T> source, Map<String, T> target, T newEntry) { String name = newEntry.getName(); T olderEntry = source.get(name); if (olderEntry != null) { return Optional.of(handleReDefinition(olderEntry, newEntry)); } else { target.put(name, newEntry); } return Optional.empty(); }
public TypeExtensionMissingBaseTypeError(TypeDefinition typeExtensionDefinition) { super(typeExtensionDefinition, format("The extension '%s' type %s is missing its base underlying type", typeExtensionDefinition.getName(), BaseError.lineCol(typeExtensionDefinition) )); } }
private String nonExecutableDefinitionMessage(Definition definition) { String definitionName; if (definition instanceof TypeDefinition) { definitionName = ((TypeDefinition) definition).getName(); } else if (definition instanceof SchemaDefinition) { definitionName = "schema"; } else { definitionName = "provided"; } return nonExecutableDefinitionMessage(definitionName); }
private <T extends TypeDefinition> Optional<T> getType(String typeName, Class<T> typeDefClass, Document doc) { if (typeName == null) { return Optional.empty(); } return doc.getDefinitions().stream() .filter(def -> typeDefClass.isAssignableFrom(def.getClass())) .map(typeDefClass::cast) .filter(defT -> defT.getName().equals(typeName)) .findFirst(); } }
public MissingInterfaceTypeError(String typeOfType, TypeDefinition typeDefinition, TypeName typeName) { super(typeDefinition, format("The %s type '%s' is not present when resolving type '%s' %s", typeOfType, typeName.getName(), typeDefinition.getName(), lineCol(typeDefinition))); } }
private static String formatMessage(TypeDefinition typeDefinition, String fieldName, AbstractNode<?> fieldDefinition) { return format("'%s' extension type %s tried to redefine field '%s' %s", typeDefinition.getName(), BaseError.lineCol(typeDefinition), fieldName, BaseError.lineCol(fieldDefinition) ); } }