public String getName() { return typeName.getName(); }
@Override public TypeName deepCopy() { return new TypeName(name, getSourceLocation(), getComments(), getIgnoredChars()); }
TypeName query = TypeName.newTypeName().name((String) queryType.get("name")).build(); boolean nonDefaultQueryName = !"Query".equals(query.getName()); boolean nonDefaultMutationName = false; if (mutationType != null) { TypeName mutation = TypeName.newTypeName().name((String) mutationType.get("name")).build(); nonDefaultMutationName = !"Mutation".equals(mutation.getName()); schemaDefinition.operationTypeDefinition(OperationTypeDefinition.newOperationTypeDefinition().name("mutation").typeName(mutation).build()); boolean nonDefaultSubscriptionName = false; if (subscriptionType != null) { TypeName subscription = TypeName.newTypeName().name(((String) subscriptionType.get("name"))).build(); nonDefaultSubscriptionName = !"Subscription".equals(subscription.getName()); schemaDefinition.operationTypeDefinition(OperationTypeDefinition.newOperationTypeDefinition().name("subscription").typeName(subscription).build());
private Builder(TypeName existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); }
@Override public void checkTypeName(TypeName typeName) { if ((getValidationContext().getSchema().getType(typeName.getName())) == null) { String message = String.format("Unknown type %s", typeName.getName()); addError(ValidationErrorType.UnknownType, typeName.getSourceLocation(), message); } } }
private void checkTypeExtensionHasCorrespondingType(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry, String name, List<? extends TypeDefinition> extTypeList, Class<? extends TypeDefinition> targetClass) { TypeDefinition extensionDefinition = extTypeList.get(0); Optional<? extends TypeDefinition> typeDefinition = typeRegistry.getType(TypeName.newTypeName().name(name).build(), targetClass); if (!typeDefinition.isPresent()) { errors.add(new TypeExtensionMissingBaseTypeError(extensionDefinition)); } }
public TypeName build() { TypeName typeName = new TypeName(name, sourceLocation, comments, ignoredChars); return typeName; } }
private Builder(TypeName existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); }
@Override public void checkTypeName(TypeName typeName) { if ((getValidationContext().getSchema().getType(typeName.getName())) == null) { String message = String.format("Unknown type %s", typeName.getName()); addError(ValidationErrorType.UnknownType, typeName.getSourceLocation(), message); } } }
@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 TypeName build() { TypeName typeName = new TypeName(name, sourceLocation, comments, ignoredChars); return typeName; } }
public boolean hasType(TypeName typeName) { String name = typeName.getName(); return types.containsKey(name) || ScalarInfo.STANDARD_SCALAR_DEFINITIONS.containsKey(name) || scalarTypes.containsKey(name) || objectTypeExtensions.containsKey(name); }
TypeName query = TypeName.newTypeName().name((String) queryType.get("name")).build(); boolean nonDefaultQueryName = !"Query".equals(query.getName()); boolean nonDefaultMutationName = false; if (mutationType != null) { TypeName mutation = TypeName.newTypeName().name((String) mutationType.get("name")).build(); nonDefaultMutationName = !"Mutation".equals(mutation.getName()); schemaDefinition.operationTypeDefinition(OperationTypeDefinition.newOperationTypeDefinition().name("mutation").typeName(mutation).build()); boolean nonDefaultSubscriptionName = false; if (subscriptionType != null) { TypeName subscription = TypeName.newTypeName().name(((String) subscriptionType.get("name"))).build(); nonDefaultSubscriptionName = !"Subscription".equals(subscription.getName()); schemaDefinition.operationTypeDefinition(OperationTypeDefinition.newOperationTypeDefinition().name("subscription").typeName(subscription).build());
@Override public TypeName deepCopy() { return new TypeName(name, getSourceLocation(), getComments(), getIgnoredChars()); }
@SuppressWarnings("unchecked") UnionTypeDefinition createUnion(Map<String, Object> input) { assertTrue(input.get("kind").equals("UNION"), "wrong input"); UnionTypeDefinition.Builder unionTypeDefinition = UnionTypeDefinition.newUnionTypeDefinition(); unionTypeDefinition.name((String) input.get("name")); unionTypeDefinition.comments(toComment((String) input.get("description"))); List<Map<String, Object>> possibleTypes = (List<Map<String, Object>>) input.get("possibleTypes"); for (Map<String, Object> possibleType : possibleTypes) { TypeName typeName = TypeName.newTypeName().name((String) possibleType.get("name")).build(); unionTypeDefinition.memberType(typeName); } return unionTypeDefinition.build(); }
public MissingTypeError(String typeOfType, Node node, String name, TypeName typeName) { super(node, format("The %s type '%s' is not present when resolving type '%s' %s", typeOfType, typeName.getName(), name, lineCol(node))); } }
private Optional<OperationTypeDefinition> synthOperationTypeDefinition(Function<Type, Optional<ObjectTypeDefinition>> typeReteriver, String opName) { TypeName type = TypeName.newTypeName().name(capitalize(opName)).build(); Optional<ObjectTypeDefinition> typeDef = typeReteriver.apply(type); return typeDef.map(objectTypeDefinition -> OperationTypeDefinition.newOperationTypeDefinition().name(opName).typeName(type).build()); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; TypeInfo typeInfo = (TypeInfo) o; return isNonNull() == typeInfo.isNonNull() && isList() == typeInfo.isList() && Objects.equals(typeName.getName(), typeInfo.typeName.getName()); }
/** * We build the query / mutation / subscription path as a tree of referenced types * but then we build the rest of the types specified and put them in as additional types * * @param buildCtx the context we need to work out what we are doing * * @return the additional types not referenced from the top level operations */ private Set<GraphQLType> buildAdditionalTypes(BuildContext buildCtx) { Set<GraphQLType> additionalTypes = new LinkedHashSet<>(); TypeDefinitionRegistry typeRegistry = buildCtx.getTypeRegistry(); typeRegistry.types().values().forEach(typeDefinition -> { TypeName typeName = TypeName.newTypeName().name(typeDefinition.getName()).build(); if (typeDefinition instanceof InputObjectTypeDefinition) { if (buildCtx.hasInputType(typeDefinition) == null) { additionalTypes.add(buildInputType(buildCtx, typeName)); } } else { if (buildCtx.hasOutputType(typeDefinition) == null) { additionalTypes.add(buildOutputType(buildCtx, typeName)); } } }); return additionalTypes; }
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))); } }