@@ -862,6 +862,127 @@ func TestEntityKeys(t *testing.T) {
862862 },
863863 },
864864 },
865+ {
866+ name : "Should create an execution plan for an entity lookup with a key field and nested field" ,
867+ query : `query EntityLookup($representations: [_Any!]!) { _entities(representations: $representations) { ... on User { __typename id name address { street } } } }` ,
868+ schema : testFederationSchemaString (`
869+ type Query {
870+ _entities(representations: [_Any!]!): [_Entity]!
871+ }
872+ type User @key(fields: "id") {
873+ id: ID!
874+ name: String!
875+ address: Address!
876+ }
877+
878+ type Address {
879+ id: ID!
880+ street: String!
881+ }
882+ ` , []string {"User" }),
883+ mapping : & GRPCMapping {
884+ Service : "Products" ,
885+ EntityRPCs : map [string ][]EntityRPCConfig {
886+ "User" : {
887+ {
888+ Key : "id" ,
889+ RPCConfig : RPCConfig {
890+ RPC : "LookupUserById" ,
891+ Request : "LookupUserByIdRequest" ,
892+ Response : "LookupUserByIdResponse" ,
893+ },
894+ },
895+ },
896+ },
897+ },
898+ federationConfigs : plan.FederationFieldConfigurations {
899+ {
900+ TypeName : "User" ,
901+ SelectionSet : "id" ,
902+ },
903+ },
904+
905+ expectedPlan : & RPCExecutionPlan {
906+ Calls : []RPCCall {
907+ {
908+ ServiceName : "Products" ,
909+ MethodName : "LookupUserById" ,
910+ Kind : CallKindEntity ,
911+ // Define the structure of the request message
912+ Request : RPCMessage {
913+ Name : "LookupUserByIdRequest" ,
914+ Fields : []RPCField {
915+ {
916+ Name : "keys" ,
917+ ProtoTypeName : DataTypeMessage ,
918+ Repeated : true ,
919+ JSONPath : "representations" ,
920+ Message : & RPCMessage {
921+ Name : "LookupUserByIdKey" ,
922+ MemberTypes : []string {"User" },
923+ Fields : []RPCField {
924+ {
925+ Name : "id" ,
926+ ProtoTypeName : DataTypeString ,
927+ JSONPath : "id" ,
928+ },
929+ },
930+ },
931+ },
932+ },
933+ },
934+ // Define the structure of the response message
935+ Response : RPCMessage {
936+ Name : "LookupUserByIdResponse" ,
937+ Fields : []RPCField {
938+ {
939+ Name : "result" ,
940+ ProtoTypeName : DataTypeMessage ,
941+ Repeated : true ,
942+ JSONPath : "_entities" ,
943+ Message : & RPCMessage {
944+ Name : "User" ,
945+ Fields : []RPCField {
946+ {
947+ Name : "__typename" ,
948+ ProtoTypeName : DataTypeString ,
949+ JSONPath : "__typename" ,
950+ StaticValue : "User" ,
951+ },
952+ {
953+ Name : "id" ,
954+ ProtoTypeName : DataTypeString ,
955+ JSONPath : "id" ,
956+ },
957+ {
958+ Name : "name" ,
959+ ProtoTypeName : DataTypeString ,
960+ JSONPath : "name" ,
961+ },
962+ {
963+ Name : "address" ,
964+ ProtoTypeName : DataTypeMessage ,
965+ JSONPath : "address" ,
966+ Message : & RPCMessage {
967+ Name : "Address" ,
968+ Fields : []RPCField {
969+ {
970+ Name : "street" ,
971+ ProtoTypeName : DataTypeString ,
972+ JSONPath : "street" ,
973+ },
974+ },
975+ },
976+ },
977+ },
978+ },
979+ },
980+ },
981+ },
982+ },
983+ },
984+ },
985+ },
865986 }
866987
867988 for _ , tt := range tests {
0 commit comments