Why is the extra query/mutation declaration necessary?

I’ve been using Apollo for a few years, and I still don’t understand why the extra declaration is needed like:

  query YourQuery($variableX: String!) {
    someQuery(variableX: $variableX) {
  • First, renaming a query can just lead to more confusion in your code.
  • Second, the syntax with the $ is totally foreign, I imagine, to most normal developers. Any mistake here can lead to other confusing errors.
  • Third, I’m not sure I ever had the need for any of this.

I recently found out that you can use Apollo Tooling to generate types so you can declare a query like:

useQuery<YourQuery, YourQueryVariables>(QUERY, { variables: { variableX } })

But I’m not sure how much this extra stuff is buying me. And again, why is a different name recommended/required.

I usually always have the two declarations with the same name, so I don’t confuse myself more that I need to.


1 Like