Closed yurtaev closed 3 years ago
Describe the bug
buildOperationNodeForField returns wrong result if return a field of type Query from mutation
To Reproduce
I created #3381 with tests to reproduce that.
# Schema type Pizza { dough: String! toppings: [String!] query: Query } type Salad { ingredients: [String!]! query: Query } union Food = Pizza | Salad type Query { pizza: Pizza getPizzaById(id: String!): Pizza } type Mutation { addRandomFood(name: String!): Food }
const document = buildOperationNodeForField({ schema, kind: 'mutation', field: 'addRandomFood', models, ignore: [], })!;
buildOperationNodeForField returns:
buildOperationNodeForField
- mutation addRandomFood_mutation($name: String!) { + mutation addRandomFood_mutation($name: String!, $addRandomFood_query_query_getPizzaById_id: String!) { addRandomFood(name: $name) { ... on Pizza { dough toppings } ... on Salad { ingredients + query { + pizza { + dough + toppings + } + getPizzaById(id: $addRandomFood_query_query_getPizzaById_id) { + dough + toppings + } + } } } }
Expected behavior
should return:
mutation addRandomFood_mutation($name: String!) { addRandomFood(name: $name) { ... on Pizza { dough toppings } ... on Salad { ingredients } } }
Environment:
@graphql-tools/utils
Additional context
Ok, I found how to fix it #3383
P.S I found the bug when trying to use this rule https://graphql-rules.com/rules/mutation-payload-query
Thanks for the PR :) Available in the latest version!
Describe the bug
buildOperationNodeForField returns wrong result if return a field of type Query from mutation
To Reproduce
I created #3381 with tests to reproduce that.
buildOperationNodeForField
returns:Expected behavior
should return:
Environment:
@graphql-tools/utils
: 6.2.3Additional context