urql-graphql / urql-exchange-graphcache

A normalized and configurable cache exchange for urql
88 stars 13 forks source link

Fix: Duplicate fragments in populated documents #151

Closed imranolas closed 4 years ago

imranolas commented 4 years ago

Where the mutation body uses and declares a fragment named the same as one found in an active selection it was incorrectly added as duplicate. This change checks the document for existing named fragments before adding them.

Given a query

query {
  todos {
    ...TodoFragment
    creator {
      ...CreatorFragment
    }
  }
}

fragment TodoFragment on Todo {
  id
  text
}

fragment CreatorFragment on User {
  id
  name
}

and mutation using both @populate and a named fragment

mutation MyMutation {
  addTodo @populate
    ...TodoFragment
  }
}

fragment TodoFragment on Todo {
  id
  text
}

The TodoFragment should appear only once in the populated mutation.

Additional changes