-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All GQL fields are nullable when source is a Protobuf schema. #5590
Comments
PRs are welcome! |
Hi, I'm not sure it is possible to rely on the From what I understand of the dedicated documentation section, the default The difference between Don't hesitate to give more information if I've misunderstood something here, I'm not expert in Protobuf 😅 |
Hi @Francismb #6137 check my PR please. |
I'm not sure non nullable fields are the same with
|
@ardatan Thanks for replying 👍
The well-formed message can have optional, non optional, repeated and map field. |
I misunderstood about non-optional field In this docs,
// no explicit field label
syntax = "proto3";
package example;
message Msg {
int32 foo = 1;
} // Optional
syntax = "proto3";
package example;
message Msg {
optional int32 foo = 1;
} With m := GetProto()
if m.Foo != 0 {
// "Clear" the field:
m.Foo = 0
} else {
// Default value: field may not have been present.
m.Foo = 1
} With Optional field, there is a methd checking presence in its message. In that case, the default is the language-specific null value. m := GetProto()
// check the field nil
if m.Foo != nil {
// Clear the field:
m.Foo = nil
} else {
// Field is not present, so set it.
m.Foo = proto.Int32(1)
} after proto of 3.15 version, the optional field is default enabled. So I think we have to check its presence when we use optional field. I understand you because the non explicit field label indicates that the default value can be not presence. also I think it is very hard to decide the policy about proto. How do you think about this? @ardatan |
For me, the real problem here is that "optional" doesn't really means the same thing in protobuf and graphql. Proto allows to define a binary data format, so it needs to know which value is present or not. Optional here means that a field can be present or not in the message. But it doesn't say anything about the value itself. The field can be present with a nil value. In GraphQL, there is not really such thing as "present" field. A field is always here, but can contain a value or not. Optional here means that the value can be null. So it you have a strict value policy here. And one of the problem here is that it's not easy to map the concept of "null" to protobuf, which is mainly based on Go, where |
@EmrysMyrddin I agree with you about some point. I made a brief overview of proto3 before v3.15.
But In proto v3.15 Let's see the "round trip" case between explicit and implicit presence.
In the docs, it describes this situation that
So protobuf propose the way to resolve the issue. explicit optional In this case, there is a need to distinguish proto3 optional with implicit field. In summary, the introduction of explicit optional in proto3 starting from version 3.15 addresses some of the challenges in field presence semantics, especially when integrating with technologies like GraphQL. Providing options for controlling how proto3 messages are generated or how GraphQL schemas are defined can be a valuable feature to ensure smooth integration and consistency in graphql-mesh. |
Issue workflow progress
Progress of the issue based on the
Contributor Workflow
Github,
Stackblitz
or
CodeSandbox
Describe the bug
All GraphQL fields are marked as nullable when using a Protobuf schema as a source. Protobuf has 'optional' and 'one of' types to indicate fields as nullable/required. The GraphQL schema generation should use these to indicate if a GraphQL field is nullable.
To Reproduce Steps to reproduce the behavior:
An example repository can be found here: https://github.com/Francismb/graphql-mesh-issue
The protobuf schema with a non-nullable field: https://github.com/Francismb/graphql-mesh-issue/blob/main/api.proto#L6
The generated GraphQL schema with a not required field: https://github.com/Francismb/graphql-mesh-issue/blob/main/.mesh/schema.graphql#L41
Expected behavior
Required fields in Protobuf schemas should ensure that its also required in GraphQL.
Environment:
@graphql-mesh/...
: latestThe text was updated successfully, but these errors were encountered: