What is the "Merge" Button in GraphiQL?
Asked Answered
S

1

5

What is the purpose of the Merge button in GraphiQL UI. It seems to be doing the same thing as the Prettify button.

Please provide an example

Stethoscope answered 25/3, 2021 at 12:48 Comment(0)
T
6

The Merge button is used for flattening a query with defined fragments. It is different from Prettify which retains the original query but just indents it.

Using the GraphiQL netify demo schema, the following query is "Prettified"

query {
  test {
    person {
      name
      age
      ...friendNames
    }
  }
}

fragment friendNames on Person {
  friends {
    name
  }
}

When clicking the Merge button the result is as follows:

{
  test {
    person {
      name
      age
      friends {
        name
      }
    }
  }
}

To see a live demo of the above, you can follow this link

Tragic answered 18/5, 2021 at 21:52 Comment(1)
Thank you very much! Very clear and understandable answer.Stethoscope

© 2022 - 2024 — McMap. All rights reserved.