Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code formatting causing fragment to be perceived as not unique. #751

Open
RamonBalthazar opened this issue Apr 17, 2023 · 0 comments
Open

Comments

@RamonBalthazar
Copy link

RamonBalthazar commented Apr 17, 2023

The problem

Given a fragment that looks like this:

const PersonFragment = gql`
  fragment PersonFragment on Person {
    id
    name
    notes(where: { deleted_at: { _is_null: true } }) {
      id
      text
    }
  }
`

When I use this fragment in two places in my app I get this warning on the console:

Warning: fragment with name PersonFragment 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

The cause

After some investigation I found out that the issue is being caused by code formatting.

If I change this line

    notes(where: { deleted_at: { _is_null: true } }) {

to this, without some of the spaces

    notes(where: {deleted_at: {_is_null: true}}) {

the warning goes away!

I worked it out after printing PersonFragment and noticing that the print function gets rid of those spaces.

This is a bug because the fragment equality algorithm is formatting the code itself when parsing the fragment for the first time, but not formatting the code again when comparing with what it's got stored.


This doesn't work also, which is extra annoying:

    # prettier-ignore
    notes(where: {deleted_at: {_is_null: true}}) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant