use of graphql.schema.GraphQLAppliedDirective in project graphql-java by graphql-java.
the class SchemaGeneratorHelper method buildInterfaceType.
GraphQLInterfaceType buildInterfaceType(BuildContext buildCtx, InterfaceTypeDefinition typeDefinition) {
GraphQLInterfaceType.Builder builder = GraphQLInterfaceType.newInterface();
builder.definition(buildCtx.isCaptureAstDefinitions() ? typeDefinition : null);
builder.name(typeDefinition.getName());
builder.description(buildDescription(buildCtx, typeDefinition, typeDefinition.getDescription()));
builder.comparatorRegistry(buildCtx.getComparatorRegistry());
List<InterfaceTypeExtensionDefinition> extensions = interfaceTypeExtensions(typeDefinition, buildCtx);
builder.extensionDefinitions(buildCtx.isCaptureAstDefinitions() ? extensions : emptyList());
Pair<List<GraphQLDirective>, List<GraphQLAppliedDirective>> appliedDirectives = buildAppliedDirectives(buildCtx, inputTypeFactory(buildCtx), typeDefinition.getDirectives(), directivesOf(extensions), OBJECT, buildCtx.getDirectives(), buildCtx.getComparatorRegistry());
buildAppliedDirectives(buildCtx, builder, appliedDirectives);
typeDefinition.getFieldDefinitions().forEach(fieldDef -> {
GraphQLFieldDefinition fieldDefinition = buildField(buildCtx, typeDefinition, fieldDef);
builder.field(fieldDefinition);
});
extensions.forEach(extension -> extension.getFieldDefinitions().forEach(fieldDef -> {
GraphQLFieldDefinition fieldDefinition = buildField(buildCtx, typeDefinition, fieldDef);
if (!builder.hasField(fieldDefinition.getName())) {
builder.field(fieldDefinition);
}
}));
buildInterfaceTypeInterfaces(buildCtx, typeDefinition, builder, extensions);
GraphQLInterfaceType interfaceType = builder.build();
if (!buildCtx.getCodeRegistry().hasTypeResolver(interfaceType.getName())) {
TypeResolver typeResolver = getTypeResolverForInterface(buildCtx, typeDefinition);
buildCtx.getCodeRegistry().typeResolver(interfaceType, typeResolver);
}
return directivesObserve(buildCtx, interfaceType);
}
use of graphql.schema.GraphQLAppliedDirective in project graphql-java by graphql-java.
the class SchemaGeneratorHelper method buildUnionType.
GraphQLUnionType buildUnionType(BuildContext buildCtx, UnionTypeDefinition typeDefinition) {
GraphQLUnionType.Builder builder = GraphQLUnionType.newUnionType();
builder.definition(buildCtx.isCaptureAstDefinitions() ? typeDefinition : null);
builder.name(typeDefinition.getName());
builder.description(buildDescription(buildCtx, typeDefinition, typeDefinition.getDescription()));
builder.comparatorRegistry(buildCtx.getComparatorRegistry());
List<UnionTypeExtensionDefinition> extensions = unionTypeExtensions(typeDefinition, buildCtx);
builder.extensionDefinitions(buildCtx.isCaptureAstDefinitions() ? extensions : emptyList());
typeDefinition.getMemberTypes().forEach(mt -> {
GraphQLOutputType outputType = buildOutputType(buildCtx, mt);
if (outputType instanceof GraphQLTypeReference) {
builder.possibleType((GraphQLTypeReference) outputType);
} else {
builder.possibleType((GraphQLObjectType) outputType);
}
});
Pair<List<GraphQLDirective>, List<GraphQLAppliedDirective>> appliedDirectives = buildAppliedDirectives(buildCtx, inputTypeFactory(buildCtx), typeDefinition.getDirectives(), directivesOf(extensions), UNION, buildCtx.getDirectives(), buildCtx.getComparatorRegistry());
buildAppliedDirectives(buildCtx, builder, appliedDirectives);
extensions.forEach(extension -> extension.getMemberTypes().forEach(mt -> {
GraphQLNamedOutputType outputType = buildOutputType(buildCtx, mt);
if (!builder.containType(outputType.getName())) {
if (outputType instanceof GraphQLTypeReference) {
builder.possibleType((GraphQLTypeReference) outputType);
} else {
builder.possibleType((GraphQLObjectType) outputType);
}
}
}));
GraphQLUnionType unionType = builder.build();
if (!buildCtx.getCodeRegistry().hasTypeResolver(unionType.getName())) {
TypeResolver typeResolver = getTypeResolverForUnion(buildCtx, typeDefinition);
buildCtx.getCodeRegistry().typeResolver(unionType, typeResolver);
}
return directivesObserve(buildCtx, unionType);
}
Aggregations