-
Notifications
You must be signed in to change notification settings - Fork 84
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
$typeName returned in response payload when calling service method #1373
Comments
It must be related to the connect clients. When using CURL, we can't see any As a side note: We also experienced type issues when implementing a service. Is this known? router.service(PlatformService, {
getNamespaces: async (req, ctx) => {
return {} // Valid
},
}, handlerOptions); |
The
This is possible in v1 as well. This is mainly because protobuf messages have default values. The return type matches the second parameter passed to |
Hi @srikrsna-buf, I don't understand your conclusion. I know, it is there to identify a message but why is it part of my client response? I never defined this in my proto definition and it is not required to consume messages.
This will change the way how we do assertions in our code base. Would you be open to support a mode where those fields are omitted?
Shouldn't the expectation be here to validate the proto message definition? |
It is not part of the wire, it is only part of the objects returned from the clients. It is similar to retuning a class with a couple of additional methods and properties (that are not part of proto) which was the case in v1.
We won't be supporting such a mode as our suggestion is to keep the
It does match the definition, the required fields have to be set. Only if a message has no required fields will it allow |
@StarpTech If you need to work with JSON, you can use envoy gRPC-JSON transcoding or interceptor: import { fromJson, toJson } from "@bufbuild/protobuf";
/**
* @typedef {import("@bufbuild/protobuf").DescMessage} DescMessage
*/
/**
* Change every stream message
* @returns {AsyncGenerator<*, void, *>}
* @param {DescMessage} schema
* @param {AsyncIterable<MessageShape<Object>>} stream
* @yield {MessageShape<Object>} message
*/
async function* fromJsonStream(schema, stream) {
for await (const message of stream) {
yield fromJson(schema, message, { ignoreUnknownFields: true });
}
}
/**
* Change every stream message
* @param {DescMessage} schema
* @param {AsyncIterable<MessageShape<Object>>} stream
* @returns {AsyncGenerator<*, void, *>}
*/
async function* toJsonStream(schema, stream) {
for await (const message of stream) {
yield toJson(schema, message, { ignoreUnknownFields: true });
}
}
/**
* Connect RPC Interceptor for auto json serializer
* @returns {function(*): Promise<*>}
*/
export default function serializerInterceptor(next) {
return (req) => {
if (req.service.name !== "ServerReflection") {
if (req.stream) {
req.message = toJsonStream(req.method.input, req.message);
} else {
req.message = toJson(req.method.input, req.message, { alwaysEmitImplicit: true });
}
}
return next(req).then((res) => {
if (res.service.name !== "ServerReflection") {
if (res.stream) {
res.message = fromJsonStream(res.method.output, res.message);
} else {
res.message = fromJson(res.method.output, res.message, { ignoreUnknownFields: true }); // FOR ENUM
}
}
return res;
});
};
} import serializerInterceptor from "./interceptors/serializerInterceptor.js";
// ...
connectNodeAdapter({
routes,
interceptors: [serializerInterceptor],
jsonOptions: {
emitDefaultValues: true, // this deserialization default value
}
}), |
@srikrsna-buf I find this behaviour highly debatable because I consider this as internal details from a consumer perspective. Wrapping the client is a good solution. In what cases, does the user benefit from the @intech thanks for the examples. It was not necessary to do this in Node / Fastify or CURL because it seems to be only related when using the clients directly. |
Describe the bug
Hello, we're currently investigating the migration from v1 to v2. Thanks to your migration guide, the migration is straightforward, although it requires a lot of effort.
Unfortunately, we ran into the following issue in our tests when we used the connect client to make requests against our server.
Is this the intended behaviour? We don't see
$typeName
as part of the response e.g. in the Next.js frontend. We're curious why this only appears server side. Thanks!The text was updated successfully, but these errors were encountered: