Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/source/data/fragments.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@

Changes to the `NameParts` fragment automatically update the fields included in any operations that use it. This reduces the effort required to keep fields consistent across a set of operations.

## Unique fragment names {#unique-names}

Fragment names must be unique across your entire application. If you reuse a fragment name, the `graphql-tag` library warns about the conflict at runtime to help prevent bugs:

Check notice on line 46 in docs/source/data/fragments.mdx

View check run for this annotation

Apollo Librarian / AI Style Review

docs/source/data/fragments.mdx#L46

**Framing Apollo Products**: Focus on the benefit of the tool helping the user rather than the negative aspect of a conflict or bug. **Framing**: Frame content relative to the reader by using "you" and "your". **Products and Features**: Do not use articles like "the" before standalone product or library names like graphql-tag. **Voice**: The original phrasing is slightly passive. Using 'always' and 'to prevent' provides a more authoritative and helpful tone. **Word and Symbol Usage**: Avoid semicolons; a period and new sentence is clearer. ```suggestion Fragment names must be unique across your entire application. If you reuse a fragment name, the `graphql-tag` library provides a warning about the conflict at runtime to help you identify the issue: ```

```text
Warning: fragment with name SomeFragment already exists.
graphql-tag enforces all fragment names across your application to be unique; read more about
this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names
```

As a best practice, use descriptive, component-scoped fragment names (like `ItemFragment` or `UserProfileFragment`) to avoid name collisions.

## Example usage

Let's say we have a blog application that executes several GraphQL operations related to comments (submitting a comment, fetching a post's comments, etc.). Our application likely has a `Comment` component that is responsible for rendering comment data.
Expand Down