Skip to content

Conversation

@ahmdmhd
Copy link
Collaborator

@ahmdmhd ahmdmhd commented Oct 24, 2025

This PR implements support for exporting .proto files.

s2dm export protobuf --schema /path/to/schema --output output.proto --selection-query /path/to/selection/query [--package-name package.name] [--flatten-naming]

Based on #146.

@ahmdmhd ahmdmhd changed the title feat: export protobuf [WIP] feat: export protobuf Oct 24, 2025
@jdacoello jdacoello deleted the branch COVESA:main October 27, 2025 09:36
@jdacoello jdacoello closed this Oct 27, 2025
@jdacoello jdacoello reopened this Oct 27, 2025
@jdacoello
Copy link
Collaborator

There is a mismatch in the develop commit history. The develop branch will be deleted.
@ahmdmhd , please rebase your branch and direct the PR against the main branch directly.

@ahmdmhd ahmdmhd force-pushed the feat/export-protobuf branch from 2a99ade to f4b2f1a Compare October 27, 2025 15:00
@ahmdmhd ahmdmhd changed the base branch from develop to main October 27, 2025 15:01
@ahmdmhd ahmdmhd force-pushed the feat/export-protobuf branch from 36edab9 to c8f265f Compare October 30, 2025 13:55
@ahmdmhd ahmdmhd changed the title [WIP] feat: export protobuf feat: export protobuf Oct 30, 2025
@ahmdmhd ahmdmhd marked this pull request as ready for review October 30, 2025 13:55
Signed-off-by: Ahmed Mohamed <[email protected]>
@ahmdmhd ahmdmhd force-pushed the feat/export-protobuf branch from 1efd74b to f8da8b8 Compare November 5, 2025 15:09
@ahmdmhd
Copy link
Collaborator Author

ahmdmhd commented Nov 5, 2025

@jdacoello the PR is now ready to be reviewed.

The following has been changed:

  • The --selection-query​ flag is now mandatory.
  • Name flattening now works for types present in the selection query.
  • Nullable fields are mapped to optional and non-null fields include validation.
  • A bug that prevented referenced types from being included in the proto file is now fixed.
  • The documentation includes a comment on field numbering in proto files.

PASSENGERSIDE
}
```

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
As the selection query is mandatory. The example must have a `type Query` to enable entry point(s) for the selection mechanism.
```gql
type Query {
cabin: Cabin
}

```

The Protobuf exporter produces:

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give here the exact command that produces that output because now selection query is mandatory.

Comment on lines +213 to +224
#### Selection Query (Required)

The protobuf exporter requires a selection query to determine which types and fields to export:

```bash
s2dm export protobuf --schema schema.graphql --selection-query query.graphql --output cabin.proto
```

Given a query file `query.graphql` that matches the schema above:

```graphql
query Selection {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming you define a selection query like:

query MyCustomSelection {
  ...
}

The resulting proto root message of that query has the name Query:

message Query {
  ...
}

Intead, the query name should be the proto message name like:

message MyCustomSelection {
  ...
}

Please, modify the logic that is assigning that name to the proto message.

Comment on lines +240 to +248
#### Root Type Filtering

Use the `--root-type` flag in combination with the selection query to further filter the export:

```bash
s2dm export protobuf --schema schema.graphql --selection-query query.graphql --output cabin.proto --root-type Cabin
```

This will include only the `Cabin` type and all types transitively referenced by it from the selection query.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an example of this? I am not understanding the point of introducing this --root-type when we have already the selection query. Isn't the selection query enough?

Comment on lines +268 to +296
```graphql
type Vehicle {
adas: ADAS
}

type ADAS {
abs: ABS
}

type ABS {
isEngaged: Boolean
}
```

Flatten mode produces:

```protobuf
syntax = "proto3";

import "google/protobuf/descriptor.proto";
import "buf/validate/validate.proto";

extend google.protobuf.MessageOptions {
string source = 50001;
}

message Message {
bool Vehicle_adas_abs_isEngaged = 1;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example is incomplete and not replicable because selection query is mandatory and not in the example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants