Skip to content

Commit

Permalink
chore: failing test for #8221 (#8226)
Browse files Browse the repository at this point in the history
* Issue reproduction

* Changeset

* ..

* ..

* Update snapshots

* Stabilize snapshots

* More stabilize snapshots

* Enable leak testing for grpc example

* More

---------

Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>
  • Loading branch information
iamchanii and ardatan authored Jan 8, 2025
1 parent ba63a9a commit 4011203
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 164 deletions.
6 changes: 6 additions & 0 deletions .changeset/tidy-masks-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@graphql-mesh/transport-grpc': patch
'@graphql-mesh/utils': patch
---

Handle transformed gRPC sources correctly
41 changes: 29 additions & 12 deletions e2e/grpc-multiple/__snapshots__/grpc-multiple.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ schema
@link(
url: "https://the-guild.dev/graphql/mesh/spec/v1.0"
import: ["@grpcMethod", "@grpcConnectivityState", "@transport", "@extraSchemaDefinitionDirective"]
import: ["@grpcMethod", "@grpcConnectivityState", "@transport", "@source", "@extraSchemaDefinitionDirective"]
)
{
query: Query
Expand Down Expand Up @@ -97,6 +97,8 @@ directive @grpcConnectivityState(subgraph: String, rootJsonName: String, objPath
directive @transport(subgraph: String, kind: String, location: String, options: TransportOptions) repeatable on SCHEMA
directive @source(name: String!, type: String, subgraph: String!) repeatable on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @extraSchemaDefinitionDirective(directives: _DirectiveExtensions) repeatable on OBJECT
"""
Expand All @@ -122,32 +124,47 @@ type Query @extraSchemaDefinitionDirective(
) @extraSchemaDefinitionDirective(
directives: {transport: [{subgraph: "Stores", kind: "grpc", location: "localhost:<Stores_port>", options: {requestTimeout: 200000, roots: [{name: "Root0", rootJson: "{\\"options\\":{\\"syntax\\":\\"proto3\\"},\\"nested\\":{\\"petstore\\":{\\"nested\\":{\\"PetStore\\":{\\"fields\\":{\\"id\\":{\\"type\\":\\"int32\\",\\"id\\":1,\\"comment\\":null},\\"name\\":{\\"type\\":\\"string\\",\\"id\\":2,\\"comment\\":null},\\"location\\":{\\"type\\":\\"int32\\",\\"id\\":3,\\"comment\\":null},\\"petsForSale\\":{\\"rule\\":\\"repeated\\",\\"type\\":\\"int32\\",\\"id\\":4,\\"comment\\":null}},\\"comment\\":\\"Message for pet store information\\"},\\"Empty\\":{\\"fields\\":{},\\"comment\\":\\"Request to get all pet stores\\"},\\"PetStoreList\\":{\\"fields\\":{\\"petStores\\":{\\"rule\\":\\"repeated\\",\\"type\\":\\"PetStore\\",\\"id\\":1,\\"comment\\":null}},\\"comment\\":\\"Response with a list of pet stores\\"},\\"PetStoreService\\":{\\"methods\\":{\\"GetAllPetStores\\":{\\"requestType\\":\\"Empty\\",\\"responseType\\":\\"PetStoreList\\",\\"comment\\":null},\\"GetPetStorePets\\":{\\"requestType\\":\\"PetStore\\",\\"responseType\\":\\"PetStore\\",\\"comment\\":null}},\\"comment\\":\\"Service definition for pet store\\"}}}}}"}]}}]}
) @join__type(graph: PETS) @join__type(graph: STORES) {
pets_PetService_GetAllPets(input: pets__Empty_Input) : pets__Pets @grpcMethod(
GetAllPets(input: pets__Empty_Input) : pets__Pets @grpcMethod(
subgraph: "Pets"
rootJsonName: "Root0"
objPath: "pets.PetService"
methodName: "GetAllPets"
responseStream: false
) @join__field(graph: PETS)
pets_PetService_connectivityState(tryToConnect: Boolean) : ConnectivityState @grpcConnectivityState(subgraph: "Pets", rootJsonName: "Root0", objPath: "pets.PetService") @join__field(graph: PETS)
petstore_PetStoreService_GetAllPetStores(input: petstore__Empty_Input) : petstore__PetStoreList @grpcMethod(
) @source(name: "pets_PetService_GetAllPets", type: "pets__Pets", subgraph: "Pets") @join__field(graph: PETS)
connectivityState(tryToConnect: Boolean) : ConnectivityState @grpcConnectivityState(subgraph: "Pets", rootJsonName: "Root0", objPath: "pets.PetService") @source(
name: "pets_PetService_connectivityState"
type: "ConnectivityState"
subgraph: "Pets"
) @grpcConnectivityState(
subgraph: "Stores"
rootJsonName: "Root0"
objPath: "petstore.PetStoreService"
) @source(
name: "petstore_PetStoreService_connectivityState"
type: "ConnectivityState"
subgraph: "Stores"
)
GetAllPetStores(input: petstore__Empty_Input) : petstore__PetStoreList @grpcMethod(
subgraph: "Stores"
rootJsonName: "Root0"
objPath: "petstore.PetStoreService"
methodName: "GetAllPetStores"
responseStream: false
) @source(
name: "petstore_PetStoreService_GetAllPetStores"
type: "petstore__PetStoreList"
subgraph: "Stores"
) @join__field(graph: STORES)
petstore_PetStoreService_GetPetStorePets(input: petstore__PetStore_Input) : petstore__PetStore @grpcMethod(
GetPetStorePets(input: petstore__PetStore_Input) : petstore__PetStore @grpcMethod(
subgraph: "Stores"
rootJsonName: "Root0"
objPath: "petstore.PetStoreService"
methodName: "GetPetStorePets"
responseStream: false
) @join__field(graph: STORES)
petstore_PetStoreService_connectivityState(tryToConnect: Boolean) : ConnectivityState @grpcConnectivityState(
) @source(
name: "petstore_PetStoreService_GetPetStorePets"
type: "petstore__PetStore"
subgraph: "Stores"
rootJsonName: "Root0"
objPath: "petstore.PetStoreService"
) @join__field(graph: STORES)
}
Expand Down Expand Up @@ -207,7 +224,7 @@ input petstore__PetStore_Input @join__type(graph: STORES) {
exports[`gRPC Multiple works: GetAllPetStores 1`] = `
{
"data": {
"petstore_PetStoreService_GetAllPetStores": {
"GetAllPetStores": {
"petStores": [
{
"id": 1,
Expand Down Expand Up @@ -238,7 +255,7 @@ exports[`gRPC Multiple works: GetAllPetStores 1`] = `
exports[`gRPC Multiple works: GetAllPets 1`] = `
{
"data": {
"pets_PetService_GetAllPets": {
"GetAllPets": {
"pets": [
{
"id": 1,
Expand Down
4 changes: 2 additions & 2 deletions e2e/grpc-multiple/grpc-multiple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('gRPC Multiple', () => {
const queries = {
GetAllPets: /* GraphQL */ `
query GetAllPets {
pets_PetService_GetAllPets {
GetAllPets {
pets {
id
name
Expand All @@ -15,7 +15,7 @@ describe('gRPC Multiple', () => {
`,
GetAllPetStores: /* GraphQL */ `
query GetAllPetStores {
petstore_PetStoreService_GetAllPetStores {
GetAllPetStores {
petStores {
id
name
Expand Down
10 changes: 9 additions & 1 deletion e2e/grpc-multiple/mesh.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Opts } from '@e2e/opts';
import { defineConfig } from '@graphql-mesh/compose-cli';
import { createRenameFieldTransform, defineConfig } from '@graphql-mesh/compose-cli';
import { loadGrpcSubgraph } from '@omnigraph/grpc';

const opts = Opts(process.argv);
Expand All @@ -11,12 +11,20 @@ export const composeConfig = defineConfig({
endpoint: 'localhost:' + opts.getServicePort('Pets'),
source: './services/Pets/pets.proto', // only needed when not running reflection
}),
transforms: [
createRenameFieldTransform(({ fieldName }) => fieldName.replace('pets_PetService_', '')),
],
},
{
sourceHandler: loadGrpcSubgraph('Stores', {
endpoint: 'localhost:' + opts.getServicePort('Stores'),
source: './services/Stores/pet-store.proto', // only needed when not running reflection
}),
transforms: [
createRenameFieldTransform(({ fieldName }) =>
fieldName.replace('petstore_PetStoreService_', ''),
),
],
},
],
});
24 changes: 12 additions & 12 deletions examples/grpc-example/tests/__snapshots__/grpc.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ exports[`gRPC Example should fetch movies by cast as a subscription correctly: m
`;

exports[`gRPC Example should generate correct schema: grpc-schema 1`] = `
"schema @transport(subgraph: "grpc", kind: "grpc", location: "localhost:50051", options: {requestTimeout: 200000, metaData: {someKey: "someValue", connection_type: "{context.headers.connection}"}, roots: [{name: "Root0", rootJson: "{\\"options\\":{\\"syntax\\":\\"proto3\\"},\\"nested\\":{\\"EmptyRequest\\":{\\"fields\\":{},\\"comment\\":null},\\"MovieRequest\\":{\\"fields\\":{\\"movie\\":{\\"type\\":\\"Movie\\",\\"id\\":1,\\"comment\\":null}},\\"comment\\":null},\\"SearchByCastRequest\\":{\\"fields\\":{\\"castName\\":{\\"type\\":\\"string\\",\\"id\\":1,\\"comment\\":null}},\\"comment\\":null},\\"MoviesResult\\":{\\"fields\\":{\\"result\\":{\\"rule\\":\\"repeated\\",\\"type\\":\\"Movie\\",\\"id\\":1,\\"comment\\":\\"list of movies\\"}},\\"comment\\":\\"movie result message, contains list of movies\\"},\\"Example\\":{\\"methods\\":{\\"GetMovies\\":{\\"requestType\\":\\"MovieRequest\\",\\"responseType\\":\\"MoviesResult\\",\\"comment\\":\\"get all movies\\"},\\"SearchMoviesByCast\\":{\\"requestType\\":\\"SearchByCastRequest\\",\\"responseType\\":\\"Movie\\",\\"responseStream\\":true,\\"comment\\":\\"search movies by the name of the cast\\"}},\\"comment\\":null},\\"AnotherExample\\":{\\"methods\\":{\\"GetMovies\\":{\\"requestType\\":\\"MovieRequest\\",\\"responseType\\":\\"MoviesResult\\",\\"comment\\":\\"get all movies\\"},\\"SearchMoviesByCast\\":{\\"requestType\\":\\"SearchByCastRequest\\",\\"responseType\\":\\"Movie\\",\\"responseStream\\":true,\\"comment\\":\\"search movies by the name of the cast\\"}},\\"comment\\":null},\\"Genre\\":{\\"values\\":{\\"UNSPECIFIED\\":0,\\"ACTION\\":1,\\"DRAMA\\":2},\\"comment\\":null,\\"comments\\":{\\"UNSPECIFIED\\":null,\\"ACTION\\":null,\\"DRAMA\\":null}},\\"Movie\\":{\\"fields\\":{\\"name\\":{\\"type\\":\\"string\\",\\"id\\":1,\\"comment\\":null},\\"year\\":{\\"type\\":\\"int64\\",\\"id\\":2,\\"comment\\":null},\\"rating\\":{\\"type\\":\\"float\\",\\"id\\":3,\\"comment\\":null},\\"cast\\":{\\"rule\\":\\"repeated\\",\\"type\\":\\"string\\",\\"id\\":4,\\"comment\\":\\"list of cast\\"},\\"time\\":{\\"type\\":\\"google.protobuf.Timestamp\\",\\"id\\":5,\\"comment\\":null},\\"genre\\":{\\"type\\":\\"Genre\\",\\"id\\":6,\\"comment\\":null}},\\"comment\\":\\"movie message payload\\"},\\"google\\":{\\"nested\\":{\\"protobuf\\":{\\"nested\\":{\\"Timestamp\\":{\\"fields\\":{\\"seconds\\":{\\"type\\":\\"int64\\",\\"id\\":1},\\"nanos\\":{\\"type\\":\\"int32\\",\\"id\\":2}},\\"comment\\":null}}}}}}}"}]}) {
"schema @transport(subgraph: "Example", kind: "grpc", location: "localhost:50051", options: {requestTimeout: 200000, metaData: {someKey: "someValue", connection_type: "{context.headers.connection}"}, roots: [{name: "Root0", rootJson: "{\\"options\\":{\\"syntax\\":\\"proto3\\"},\\"nested\\":{\\"EmptyRequest\\":{\\"fields\\":{},\\"comment\\":null},\\"MovieRequest\\":{\\"fields\\":{\\"movie\\":{\\"type\\":\\"Movie\\",\\"id\\":1,\\"comment\\":null}},\\"comment\\":null},\\"SearchByCastRequest\\":{\\"fields\\":{\\"castName\\":{\\"type\\":\\"string\\",\\"id\\":1,\\"comment\\":null}},\\"comment\\":null},\\"MoviesResult\\":{\\"fields\\":{\\"result\\":{\\"rule\\":\\"repeated\\",\\"type\\":\\"Movie\\",\\"id\\":1,\\"comment\\":\\"list of movies\\"}},\\"comment\\":\\"movie result message, contains list of movies\\"},\\"Example\\":{\\"methods\\":{\\"GetMovies\\":{\\"requestType\\":\\"MovieRequest\\",\\"responseType\\":\\"MoviesResult\\",\\"comment\\":\\"get all movies\\"},\\"SearchMoviesByCast\\":{\\"requestType\\":\\"SearchByCastRequest\\",\\"responseType\\":\\"Movie\\",\\"responseStream\\":true,\\"comment\\":\\"search movies by the name of the cast\\"}},\\"comment\\":null},\\"AnotherExample\\":{\\"methods\\":{\\"GetMovies\\":{\\"requestType\\":\\"MovieRequest\\",\\"responseType\\":\\"MoviesResult\\",\\"comment\\":\\"get all movies\\"},\\"SearchMoviesByCast\\":{\\"requestType\\":\\"SearchByCastRequest\\",\\"responseType\\":\\"Movie\\",\\"responseStream\\":true,\\"comment\\":\\"search movies by the name of the cast\\"}},\\"comment\\":null},\\"Genre\\":{\\"values\\":{\\"UNSPECIFIED\\":0,\\"ACTION\\":1,\\"DRAMA\\":2},\\"comment\\":null,\\"comments\\":{\\"UNSPECIFIED\\":null,\\"ACTION\\":null,\\"DRAMA\\":null}},\\"Movie\\":{\\"fields\\":{\\"name\\":{\\"type\\":\\"string\\",\\"id\\":1,\\"comment\\":null},\\"year\\":{\\"type\\":\\"int64\\",\\"id\\":2,\\"comment\\":null},\\"rating\\":{\\"type\\":\\"float\\",\\"id\\":3,\\"comment\\":null},\\"cast\\":{\\"rule\\":\\"repeated\\",\\"type\\":\\"string\\",\\"id\\":4,\\"comment\\":\\"list of cast\\"},\\"time\\":{\\"type\\":\\"google.protobuf.Timestamp\\",\\"id\\":5,\\"comment\\":null},\\"genre\\":{\\"type\\":\\"Genre\\",\\"id\\":6,\\"comment\\":null}},\\"comment\\":\\"movie message payload\\"},\\"google\\":{\\"nested\\":{\\"protobuf\\":{\\"nested\\":{\\"Timestamp\\":{\\"fields\\":{\\"seconds\\":{\\"type\\":\\"int64\\",\\"id\\":1},\\"nanos\\":{\\"type\\":\\"int32\\",\\"id\\":2}},\\"comment\\":null}}}}}}}"}]}) {
query: Query
subscription: Subscription
}
Expand All @@ -146,15 +146,15 @@ directive @transport(subgraph: String, kind: String, location: String, options:
type Query {
"""get all movies"""
exampleGetMovies(input: MovieRequest_Input): MoviesResult @grpcMethod(subgraph: "grpc", rootJsonName: "Root0", objPath: "Example", methodName: "GetMovies", responseStream: false)
exampleGetMovies(input: MovieRequest_Input): MoviesResult @grpcMethod(subgraph: "Example", rootJsonName: "Root0", objPath: "Example", methodName: "GetMovies", responseStream: false)
"""search movies by the name of the cast"""
exampleSearchMoviesByCast(input: SearchByCastRequest_Input): [Movie] @grpcMethod(subgraph: "grpc", rootJsonName: "Root0", objPath: "Example", methodName: "SearchMoviesByCast", responseStream: true)
exampleConnectivityState(tryToConnect: Boolean): ConnectivityState @grpcConnectivityState(subgraph: "grpc", rootJsonName: "Root0", objPath: "Example")
exampleSearchMoviesByCast(input: SearchByCastRequest_Input): [Movie] @grpcMethod(subgraph: "Example", rootJsonName: "Root0", objPath: "Example", methodName: "SearchMoviesByCast", responseStream: true)
exampleConnectivityState(tryToConnect: Boolean): ConnectivityState @grpcConnectivityState(subgraph: "Example", rootJsonName: "Root0", objPath: "Example")
"""get all movies"""
anotherExampleGetMovies(input: MovieRequest_Input): MoviesResult @grpcMethod(subgraph: "grpc", rootJsonName: "Root0", objPath: "AnotherExample", methodName: "GetMovies", responseStream: false)
anotherExampleGetMovies(input: MovieRequest_Input): MoviesResult @grpcMethod(subgraph: "Example", rootJsonName: "Root0", objPath: "AnotherExample", methodName: "GetMovies", responseStream: false)
"""search movies by the name of the cast"""
anotherExampleSearchMoviesByCast(input: SearchByCastRequest_Input): [Movie] @grpcMethod(subgraph: "grpc", rootJsonName: "Root0", objPath: "AnotherExample", methodName: "SearchMoviesByCast", responseStream: true)
anotherExampleConnectivityState(tryToConnect: Boolean): ConnectivityState @grpcConnectivityState(subgraph: "grpc", rootJsonName: "Root0", objPath: "AnotherExample")
anotherExampleSearchMoviesByCast(input: SearchByCastRequest_Input): [Movie] @grpcMethod(subgraph: "Example", rootJsonName: "Root0", objPath: "AnotherExample", methodName: "SearchMoviesByCast", responseStream: true)
anotherExampleConnectivityState(tryToConnect: Boolean): ConnectivityState @grpcConnectivityState(subgraph: "Example", rootJsonName: "Root0", objPath: "AnotherExample")
}
"""movie result message, contains list of movies"""
Expand Down Expand Up @@ -185,9 +185,9 @@ type google__protobuf__Timestamp {
}
enum Genre {
UNSPECIFIED @enum(subgraph: "grpc", value: "0")
ACTION @enum(subgraph: "grpc", value: "1")
DRAMA @enum(subgraph: "grpc", value: "2")
UNSPECIFIED @enum(subgraph: "Example", value: "0")
ACTION @enum(subgraph: "Example", value: "1")
DRAMA @enum(subgraph: "Example", value: "2")
}
input MovieRequest_Input {
Expand Down Expand Up @@ -224,9 +224,9 @@ enum ConnectivityState {
type Subscription {
"""search movies by the name of the cast"""
exampleSearchMoviesByCast(input: SearchByCastRequest_Input): Movie @grpcMethod(subgraph: "grpc", rootJsonName: "Root0", objPath: "Example", methodName: "SearchMoviesByCast", responseStream: true)
exampleSearchMoviesByCast(input: SearchByCastRequest_Input): Movie @grpcMethod(subgraph: "Example", rootJsonName: "Root0", objPath: "Example", methodName: "SearchMoviesByCast", responseStream: true)
"""search movies by the name of the cast"""
anotherExampleSearchMoviesByCast(input: SearchByCastRequest_Input): Movie @grpcMethod(subgraph: "grpc", rootJsonName: "Root0", objPath: "AnotherExample", methodName: "SearchMoviesByCast", responseStream: true)
anotherExampleSearchMoviesByCast(input: SearchByCastRequest_Input): Movie @grpcMethod(subgraph: "Example", rootJsonName: "Root0", objPath: "AnotherExample", methodName: "SearchMoviesByCast", responseStream: true)
}
scalar TransportOptions"
Expand Down
Loading

0 comments on commit 4011203

Please sign in to comment.