apollographql / persistgraphql

A build tool for GraphQL projects.
MIT License
425 stars 57 forks source link

Silently removing duplicate query names #30

Open ScallyGames opened 7 years ago

ScallyGames commented 7 years ago

Current behavior When defining two queries with the same operation name, only the last one is kept. All other versions are removed.

Expected behavior Two options:

Minimal reproduction Run persistgraphql on

// bar.graphql
query foo {
    foo
    {
        bar
        foobar
    }
}

// baz.graphql
query foo {
    faz
    {
        baz
        fazbaz
    }
}

// result {"query foo {\n  faz {\n    baz\n    fazbaz\n  }\n}\n":1}

Minimal demo

git clone -b duplicate-operation-names https://github.com/
Aides359/persistgraphql
cd persistgraphql
npm install
npm run compile
npm start
Poincare commented 7 years ago

Throwing error seems like the right approach here. I think the generally accepted idea is that you shouldn't have two queries with the same name and it seems reasonable to enforce that. I'm open to hearing alternative solutions to this of course.

kamsar commented 6 years ago

In a large application with many developers enforcing unique query names across a big whitelist may not be particularly tenable, so imo this should be a choice with the default throwing an error.