Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 61 additions & 2 deletions v2/pkg/engine/datasource/grpc_datasource/execution_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,34 @@ const (
federationKeyDirectiveName = "key"
)

// OneOfType represents the type of a oneof field in a protobuf message.
// It can be either an interface or a union type.
type OneOfType int

// FieldName returns the corresponding field name for the OneOfType.
// For interfaces, it returns "instance", for unions it returns "value".
// Returns an empty string for invalid or unknown types.
func (o OneOfType) FieldName() string {
switch o {
case OneOfTypeInterface:
return "instance"
case OneOfTypeUnion:
return "value"
}

return ""
}

// OneOfType constants define the different types of oneof fields.
const (
// OneOfTypeNone represents no oneof type (default/zero value)
OneOfTypeNone OneOfType = iota
// OneOfTypeInterface represents an interface type oneof field
OneOfTypeInterface
// OneOfTypeUnion represents a union type oneof field
OneOfTypeUnion
)

// RPCExecutionPlan represents a plan for executing one or more RPC calls
// to gRPC services. It defines the sequence of calls and their dependencies.
type RPCExecutionPlan struct {
Expand Down Expand Up @@ -46,8 +74,39 @@ type RPCMessage struct {
Name string
// Fields is a list of fields in the message
Fields RPCFields
// OneOf indicates if the message is an interface
OneOf bool
// FieldSelectionSet are field selections based on inline fragments
FieldSelectionSet RPCFieldSelectionSet
// OneOfType indicates the type of the oneof field
OneOfType OneOfType
// MemberTypes provides the names of the types that are implemented by the Interface or Union
MemberTypes []string
}

// IsOneOf checks if the message is a oneof field.
func (r *RPCMessage) IsOneOf() bool {
return r.OneOfType > OneOfTypeNone && r.OneOfType <= OneOfTypeUnion
Comment thread
Noroth marked this conversation as resolved.
Outdated
}

// RPCFieldSelectionSet is a map of field selections based on inline fragments
type RPCFieldSelectionSet map[string]RPCFields
Comment thread
devsergiy marked this conversation as resolved.

// Add adds a field selection set to the map
func (r RPCFieldSelectionSet) Add(fragmentName string, field RPCField) {
if r[fragmentName] == nil {
r[fragmentName] = make(RPCFields, 0)
}

r[fragmentName] = append(r[fragmentName], field)
}

// FieldsForSelection returns the fields for a given fragment name.
func (r RPCFieldSelectionSet) FieldsForSelection(fragmentName string) RPCFields {
fields, ok := r[fragmentName]
if !ok {
return nil
}

return fields
}

// RPCField represents a single field in a gRPC message.
Expand Down
Loading
Loading