interpolate reflection url and metadata (#5663)

This commit is contained in:
Jack Kavanagh
2023-01-13 12:15:37 +01:00
committed by GitHub
parent 7a80ec095a
commit 5cecdf0a0b
2 changed files with 11 additions and 7 deletions

View File

@@ -106,10 +106,9 @@ const getMethodsFromReflection = async (host: string, metadata: GrpcRequestHeade
throw error;
}
};
const loadMethodsFromReflection = async (requestId: string): Promise<GrpcMethodInfo[]> => {
const request = await models.grpcRequest.getById(requestId);
invariant(request, `Grpc request ${requestId} not found`);
const methods = await getMethodsFromReflection(request.url, request.metadata);
const loadMethodsFromReflection = async (options: { url: string; metadata: GrpcRequestHeader[] }): Promise<GrpcMethodInfo[]> => {
invariant(options.url, 'gRPC request url not provided');
const methods = await getMethodsFromReflection(options.url, options.metadata);
return methods.map(method => ({
type: getMethodType(method),
fullPath: method.path,

View File

@@ -6,7 +6,7 @@ import styled from 'styled-components';
import { getCommonHeaderNames, getCommonHeaderValues } from '../../../common/common-headers';
import { documentationLinks } from '../../../common/documentation';
import { generateId } from '../../../common/misc';
import { getRenderedGrpcRequest, getRenderedGrpcRequestMessage, RENDER_PURPOSE_SEND } from '../../../common/render';
import { getRenderContext, getRenderedGrpcRequest, getRenderedGrpcRequestMessage, render, RENDER_PURPOSE_SEND } from '../../../common/render';
import { GrpcMethodType } from '../../../main/ipc/grpc';
import * as models from '../../../models';
import type { GrpcRequest, GrpcRequestHeader } from '../../../models/grpc-request';
@@ -170,8 +170,13 @@ export const GrpcRequestPane: FunctionComponent<Props> = ({
}}
handleChangeProtoFile={() => setIsProtoModalOpen(true)}
handleServerReflection={async () => {
models.grpcRequest.update(activeRequest, { protoMethodName: '', protoFileId: '' });
const methods = await window.main.grpc.loadMethodsFromReflection(activeRequest._id);
const request = await models.grpcRequest.update(activeRequest, { protoMethodName: '', protoFileId: '' });
const renderContext = await getRenderContext({ request, environmentId, purpose: RENDER_PURPOSE_SEND });
const rendered = await render({
url: request.url,
metadata: request.metadata,
}, renderContext);
const methods = await window.main.grpc.loadMethodsFromReflection(rendered);
setGrpcState({ ...grpcState, methods, reloadMethods: false });
}}
/>