use of graphql.util.Pair in project graphql-java by graphql-java.
the class SchemaGeneratorHelper method buildObjectType.
GraphQLObjectType buildObjectType(BuildContext buildCtx, ObjectTypeDefinition typeDefinition) {
GraphQLObjectType.Builder builder = GraphQLObjectType.newObject();
builder.definition(buildCtx.isCaptureAstDefinitions() ? typeDefinition : null);
builder.name(typeDefinition.getName());
builder.description(buildDescription(buildCtx, typeDefinition, typeDefinition.getDescription()));
builder.comparatorRegistry(buildCtx.getComparatorRegistry());
List<ObjectTypeExtensionDefinition> extensions = objectTypeExtensions(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);
}
}));
buildObjectTypeInterfaces(buildCtx, typeDefinition, builder, extensions);
return directivesObserve(buildCtx, builder.build());
}
use of graphql.util.Pair in project graphql-java by graphql-java.
the class SchemaGeneratorHelper method buildScalar.
GraphQLScalarType buildScalar(BuildContext buildCtx, ScalarTypeDefinition typeDefinition) {
TypeDefinitionRegistry typeRegistry = buildCtx.getTypeRegistry();
RuntimeWiring runtimeWiring = buildCtx.getWiring();
WiringFactory wiringFactory = runtimeWiring.getWiringFactory();
List<ScalarTypeExtensionDefinition> extensions = scalarTypeExtensions(typeDefinition, buildCtx);
ScalarWiringEnvironment environment = new ScalarWiringEnvironment(typeRegistry, typeDefinition, extensions);
GraphQLScalarType scalar;
if (wiringFactory.providesScalar(environment)) {
scalar = wiringFactory.getScalar(environment);
} else {
scalar = buildCtx.getWiring().getScalars().get(typeDefinition.getName());
}
if (!ScalarInfo.isGraphqlSpecifiedScalar(scalar)) {
String description = getScalarDesc(scalar, typeDefinition);
Pair<List<GraphQLDirective>, List<GraphQLAppliedDirective>> appliedDirectives = buildAppliedDirectives(buildCtx, inputTypeFactory(buildCtx), typeDefinition.getDirectives(), directivesOf(extensions), SCALAR, buildCtx.getDirectives(), buildCtx.getComparatorRegistry());
scalar = scalar.transform(builder -> {
builder.description(description).definition(buildCtx.isCaptureAstDefinitions() ? typeDefinition : null).comparatorRegistry(buildCtx.getComparatorRegistry()).specifiedByUrl(getSpecifiedByUrl(typeDefinition, extensions));
buildAppliedDirectives(buildCtx, builder, appliedDirectives);
});
}
return directivesObserve(buildCtx, scalar);
}
use of graphql.util.Pair in project graphql-java by graphql-java.
the class SchemaGeneratorHelper method buildEnumType.
GraphQLEnumType buildEnumType(BuildContext buildCtx, EnumTypeDefinition typeDefinition) {
GraphQLEnumType.Builder builder = GraphQLEnumType.newEnum();
builder.definition(buildCtx.isCaptureAstDefinitions() ? typeDefinition : null);
builder.name(typeDefinition.getName());
builder.description(buildDescription(buildCtx, typeDefinition, typeDefinition.getDescription()));
builder.comparatorRegistry(buildCtx.getComparatorRegistry());
List<EnumTypeExtensionDefinition> extensions = enumTypeExtensions(typeDefinition, buildCtx);
builder.extensionDefinitions(buildCtx.isCaptureAstDefinitions() ? extensions : emptyList());
EnumValuesProvider enumValuesProvider = buildCtx.getWiring().getEnumValuesProviders().get(typeDefinition.getName());
typeDefinition.getEnumValueDefinitions().forEach(evd -> {
GraphQLEnumValueDefinition enumValueDefinition = buildEnumValue(buildCtx, typeDefinition, enumValuesProvider, evd);
builder.value(enumValueDefinition);
});
extensions.forEach(extension -> extension.getEnumValueDefinitions().forEach(evd -> {
GraphQLEnumValueDefinition enumValueDefinition = buildEnumValue(buildCtx, typeDefinition, enumValuesProvider, evd);
if (!builder.hasValue(enumValueDefinition.getName())) {
builder.value(enumValueDefinition);
}
}));
Pair<List<GraphQLDirective>, List<GraphQLAppliedDirective>> appliedDirectives = buildAppliedDirectives(buildCtx, inputTypeFactory(buildCtx), typeDefinition.getDirectives(), directivesOf(extensions), ENUM, buildCtx.getDirectives(), buildCtx.getComparatorRegistry());
buildAppliedDirectives(buildCtx, builder, appliedDirectives);
return directivesObserve(buildCtx, builder.build());
}
use of graphql.util.Pair 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.util.Pair 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