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

"There can only be one fragment named Xyz" (UniqueFragmentNames) #170

Open
borekb opened this issue Oct 1, 2019 · 2 comments
Open

"There can only be one fragment named Xyz" (UniqueFragmentNames) #170

borekb opened this issue Oct 1, 2019 · 2 comments

Comments

@borekb
Copy link

borekb commented Oct 1, 2019

I have two tests like this:

import { gql } from 'apollo-server';
import { createTestClient } from 'apollo-server-testing';
import { apolloServer } from './apolloServer';

it('test 1', async () => {
  const QUERY = gql`
    {
      example {
        ...MyFragment
      }
    }

    fragment MyFragment on Character {
      name
      age
    }
  `;
  const { query } = createTestClient(apolloServer);
  const result = await query({
    query: QUERY,
  });
  expect(result).toMatchSnapshot();
});

it('test 2', async () => {
  const QUERY = gql`
    {
      example2 {
        ...MyFragment
      }
    }

    fragment MyFragment on Character {
      name
      age
    }
  `;
  const { query } = createTestClient(apolloServer);
  const result = await query({
    query: QUERY,
  });
  expect(result).toMatchSnapshot();
});

Both run fine at runtime but at development time (in VSCode via Kumar's extension), I get this error:

Screenshot 2019-10-01 at 10 34 47

There can be only one fragment named "MyFragment". (UniqueFragmentNames)

It looks like the validation isn't scoped to a single gql` ` string or something.

This is my config:

{
  "schema": {
    "files": "graphql-server/src/**/*.graphql"
  },
  "query": {
    "files": [
      {
        "match": ["graphql-server/src/**/*.test.ts"],
        "parser": ["EmbeddedQueryParser", { "startTag": "gql`", "endTag": "`" }],
      },
    ]
  }
}
@borekb
Copy link
Author

borekb commented Oct 1, 2019

By the way, using the same query names does this too (e.g., having query ExampleQuery twice).

@Mayank1791989
Copy link
Owner

@borekb Currently scope is file. In V3 branch I have made scope configurable. For now you can suppress errors in your test files by disabling the validation rule.

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

2 participants