Search in sources :

Example 1 with NamedProtobufSchema

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();
}
Also used : GraphQLList(graphql.schema.GraphQLList) DescriptorProtos(com.google.protobuf.DescriptorProtos) ProtobufSchema(io.confluent.kafka.schemaregistry.protobuf.ProtobufSchema) Descriptor(com.google.protobuf.Descriptors.Descriptor) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) LoggerFactory(org.slf4j.LoggerFactory) GraphQLSchemaBuilder.orderByEnum(io.kgraph.kgiraffe.schema.GraphQLSchemaBuilder.orderByEnum) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) GraphQLEnumValueDefinition(graphql.schema.GraphQLEnumValueDefinition) Type(org.ojai.Value.Type) AttributeFetcher(io.kgraph.kgiraffe.schema.AttributeFetcher) Scalars(graphql.Scalars) JavaScalars(io.kgraph.kgiraffe.schema.JavaScalars) GraphQLSchemaBuilder.createInputFieldOp(io.kgraph.kgiraffe.schema.GraphQLSchemaBuilder.createInputFieldOp) SchemaContext(io.kgraph.kgiraffe.schema.SchemaContext) GraphQLObjectType(graphql.schema.GraphQLObjectType) Logical(io.kgraph.kgiraffe.schema.Logical) Logger(org.slf4j.Logger) ExtendedScalars(graphql.scalars.ExtendedScalars) GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLOutputType(graphql.schema.GraphQLOutputType) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) Collectors(java.util.stream.Collectors) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) NamedProtobufSchema(io.kgraph.kgiraffe.util.proto.NamedProtobufSchema) List(java.util.List) GraphQLList(graphql.schema.GraphQLList) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) EnumDescriptor(com.google.protobuf.Descriptors.EnumDescriptor) Either(io.vavr.control.Either) TypeElement(com.squareup.wire.schema.internal.parser.TypeElement) GraphQLEnumType(graphql.schema.GraphQLEnumType) MessageElement(com.squareup.wire.schema.internal.parser.MessageElement) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) NamedProtobufSchema(io.kgraph.kgiraffe.util.proto.NamedProtobufSchema) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 2 with NamedProtobufSchema

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;
}
Also used : GraphQLEnumType(graphql.schema.GraphQLEnumType) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) NamedProtobufSchema(io.kgraph.kgiraffe.util.proto.NamedProtobufSchema)

Example 3 with NamedProtobufSchema

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();
}
Also used : GraphQLList(graphql.schema.GraphQLList) DescriptorProtos(com.google.protobuf.DescriptorProtos) ProtobufSchema(io.confluent.kafka.schemaregistry.protobuf.ProtobufSchema) Descriptor(com.google.protobuf.Descriptors.Descriptor) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) LoggerFactory(org.slf4j.LoggerFactory) GraphQLSchemaBuilder.orderByEnum(io.kgraph.kgiraffe.schema.GraphQLSchemaBuilder.orderByEnum) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) GraphQLEnumValueDefinition(graphql.schema.GraphQLEnumValueDefinition) Type(org.ojai.Value.Type) AttributeFetcher(io.kgraph.kgiraffe.schema.AttributeFetcher) Scalars(graphql.Scalars) JavaScalars(io.kgraph.kgiraffe.schema.JavaScalars) GraphQLSchemaBuilder.createInputFieldOp(io.kgraph.kgiraffe.schema.GraphQLSchemaBuilder.createInputFieldOp) SchemaContext(io.kgraph.kgiraffe.schema.SchemaContext) GraphQLObjectType(graphql.schema.GraphQLObjectType) Logical(io.kgraph.kgiraffe.schema.Logical) Logger(org.slf4j.Logger) ExtendedScalars(graphql.scalars.ExtendedScalars) GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLOutputType(graphql.schema.GraphQLOutputType) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) Collectors(java.util.stream.Collectors) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) NamedProtobufSchema(io.kgraph.kgiraffe.util.proto.NamedProtobufSchema) List(java.util.List) GraphQLList(graphql.schema.GraphQLList) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) EnumDescriptor(com.google.protobuf.Descriptors.EnumDescriptor) Either(io.vavr.control.Either) TypeElement(com.squareup.wire.schema.internal.parser.TypeElement) GraphQLEnumType(graphql.schema.GraphQLEnumType) MessageElement(com.squareup.wire.schema.internal.parser.MessageElement) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) GraphQLObjectType(graphql.schema.GraphQLObjectType) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) NamedProtobufSchema(io.kgraph.kgiraffe.util.proto.NamedProtobufSchema) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 4 with NamedProtobufSchema

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;
}
Also used : GraphQLEnumType(graphql.schema.GraphQLEnumType) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) NamedProtobufSchema(io.kgraph.kgiraffe.util.proto.NamedProtobufSchema)

Aggregations

GraphQLEnumType (graphql.schema.GraphQLEnumType)4 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)4 NamedProtobufSchema (io.kgraph.kgiraffe.util.proto.NamedProtobufSchema)4 DescriptorProtos (com.google.protobuf.DescriptorProtos)2 Descriptor (com.google.protobuf.Descriptors.Descriptor)2 EnumDescriptor (com.google.protobuf.Descriptors.EnumDescriptor)2 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)2 MessageElement (com.squareup.wire.schema.internal.parser.MessageElement)2 TypeElement (com.squareup.wire.schema.internal.parser.TypeElement)2 Scalars (graphql.Scalars)2 ExtendedScalars (graphql.scalars.ExtendedScalars)2 GraphQLEnumValueDefinition (graphql.schema.GraphQLEnumValueDefinition)2 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)2 GraphQLInputObjectField (graphql.schema.GraphQLInputObjectField)2 GraphQLInputObjectType (graphql.schema.GraphQLInputObjectType)2 GraphQLInputType (graphql.schema.GraphQLInputType)2 GraphQLList (graphql.schema.GraphQLList)2 GraphQLObjectType (graphql.schema.GraphQLObjectType)2 GraphQLOutputType (graphql.schema.GraphQLOutputType)2 GraphQLTypeReference (graphql.schema.GraphQLTypeReference)2