use of io.kgraph.kgiraffe.util.proto.NamedProtobufSchema in project kgiraffe by rayokota.
the class GraphQLProtobufConverter method createInputRecord.
private GraphQLInputType createInputRecord(SchemaContext ctx, Descriptor schema) {
switch(schema.getFullName()) {
case PROTOBUF_ANY_TYPE:
case PROTOBUF_STRUCT_TYPE:
case PROTOBUF_VALUE_TYPE:
case PROTOBUF_EMPTY_TYPE:
return ctx.isOrderBy() ? orderByEnum : ExtendedScalars.Json;
case PROTOBUF_LIST_VALUE_TYPE:
return ctx.isOrderBy() ? orderByEnum : new GraphQLList(ExtendedScalars.Json);
case PROTOBUF_TIMESTAMP_TYPE:
case PROTOBUF_DURATION_TYPE:
case PROTOBUF_FIELD_MASK_TYPE:
return ctx.isOrderBy() ? orderByEnum : Scalars.GraphQLString;
}
FieldDescriptor unwrapped = unwrapType(schema);
if (unwrapped != null) {
return createInputType(ctx, unwrapped);
}
String name = ctx.qualify(schema.getFullName());
GraphQLTypeReference type = ctx.cacheIfAbsent(new NamedProtobufSchema(schema), name);
if (type != null) {
return type;
}
boolean isRoot = ctx.isRoot();
if (isRoot) {
ctx.setRoot(false);
}
List<GraphQLInputObjectField> fields = schema.getFields().stream().map(f -> createInputField(ctx, f)).collect(Collectors.toList());
List<GraphQLInputObjectField> oneofs = schema.getRealOneofs().stream().flatMap(o -> o.getFields().stream()).map(f -> createInputField(ctx, f)).collect(Collectors.toList());
GraphQLInputObjectType.Builder builder = GraphQLInputObjectType.newInputObject().name(name).fields(fields).fields(oneofs);
if (isRoot) {
if (ctx.isWhere()) {
builder.field(GraphQLInputObjectField.newInputObjectField().name(Logical.OR.symbol()).description("Logical operation for expressions").type(new GraphQLList(new GraphQLTypeReference(name))).build()).field(GraphQLInputObjectField.newInputObjectField().name(Logical.AND.symbol()).description("Logical operation for expressions").type(new GraphQLList(new GraphQLTypeReference(name))).build());
}
}
return builder.build();
}
use of io.kgraph.kgiraffe.util.proto.NamedProtobufSchema in project kgiraffe by rayokota.
the class GraphQLProtobufConverter method createInputEnum.
private GraphQLInputType createInputEnum(SchemaContext ctx, EnumDescriptor schema) {
String name = ctx.qualify(schema.getFullName());
ParsedSchema parsedSchema = new NamedProtobufSchema(schema);
GraphQLEnumType enumType = (GraphQLEnumType) ctx.getCached(parsedSchema);
if (enumType != null) {
return enumType;
}
enumType = GraphQLEnumType.newEnum().name(name).values(schema.getValues().stream().map(v -> GraphQLEnumValueDefinition.newEnumValueDefinition().name(v.getName()).value(v.getName()).description(v.getName()).build()).collect(Collectors.toList())).build();
ctx.cache(parsedSchema, enumType);
return enumType;
}
use of io.kgraph.kgiraffe.util.proto.NamedProtobufSchema in project kgiraffe by rayokota.
the class GraphQLProtobufConverter method createOutputRecord.
private GraphQLOutputType createOutputRecord(SchemaContext ctx, Descriptor schema) {
switch(schema.getFullName()) {
case PROTOBUF_ANY_TYPE:
case PROTOBUF_STRUCT_TYPE:
case PROTOBUF_VALUE_TYPE:
case PROTOBUF_EMPTY_TYPE:
return ExtendedScalars.Json;
case PROTOBUF_LIST_VALUE_TYPE:
return new GraphQLList(ExtendedScalars.Json);
case PROTOBUF_TIMESTAMP_TYPE:
case PROTOBUF_DURATION_TYPE:
case PROTOBUF_FIELD_MASK_TYPE:
return Scalars.GraphQLString;
}
FieldDescriptor unwrapped = unwrapType(schema);
if (unwrapped != null) {
return createOutputType(ctx, unwrapped);
}
String name = ctx.qualify(schema.getFullName());
GraphQLTypeReference type = ctx.cacheIfAbsent(new NamedProtobufSchema(schema), name);
if (type != null) {
return type;
}
List<GraphQLFieldDefinition> fields = schema.getFields().stream().map(f -> createOutputField(ctx, f)).collect(Collectors.toList());
List<GraphQLFieldDefinition> oneofs = schema.getRealOneofs().stream().flatMap(o -> o.getFields().stream()).map(f -> createOutputField(ctx, f)).collect(Collectors.toList());
GraphQLObjectType.Builder builder = GraphQLObjectType.newObject().name(name).fields(fields).fields(oneofs);
return builder.build();
}
use of io.kgraph.kgiraffe.util.proto.NamedProtobufSchema in project kgiraffe by rayokota.
the class GraphQLProtobufConverter method createOutputEnum.
private GraphQLEnumType createOutputEnum(SchemaContext ctx, EnumDescriptor schema) {
String name = ctx.qualify(schema.getFullName());
ParsedSchema parsedSchema = new NamedProtobufSchema(schema);
GraphQLEnumType enumType = (GraphQLEnumType) ctx.getCached(parsedSchema);
if (enumType != null) {
return enumType;
}
enumType = GraphQLEnumType.newEnum().name(name).values(schema.getValues().stream().map(v -> GraphQLEnumValueDefinition.newEnumValueDefinition().name(v.getName()).value(v.getName()).description(v.getName()).build()).collect(Collectors.toList())).build();
ctx.cache(parsedSchema, enumType);
return enumType;
}
Aggregations