cylc / cylc-ui

Web app for monitoring and controlling Cylc workflows
https://cylc.github.io
GNU General Public License v3.0
35 stars 26 forks source link

Warning: fragment with name X already exists #1757

Open MetRonnie opened 2 months ago

MetRonnie commented 2 months ago

We get a lot of these warnings from graphql-tag in the console:

index.ts:46 Warning: fragment with name AddedDelta 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 link in the warning is dead)

From https://github.com/apollographql/graphql-tag/issues/269:

we have a global module cache... of the fragments we parse — that means that somewhere else in your application, there's another fragment defined with the same name. we protect against this because if you were to interpolate both of them into the same GraphQL document, it would fail validation. you can disable this warning by invoking disableFragmentWarnings ( https://github.com/apollographql/graphql-tag#warnings )

However we also get this warning for fragments defined only once in the whole app, because at https://github.com/cylc/cylc-ui/blob/88753e233a99c5d1643b210b2cd98c232ba2e6d8/src/services/workflow.service.js#L546-L550

it is re-evaluating the fragment definitions (which have already been cached the first time) each time the query changes because they are included in the query document.

oliver-sanders commented 2 months ago

At present fragments must be given the same name in order to merge, this isn't a problem because we merge them before issuing the request. Presumably these warnings are being raised during the merging process not at request time?

We could potentially avoid the whole merging process by generating the subscription on demand, this solution is outlined here: https://github.com/cylc/cylc-ui/issues/862#issuecomment-1753266211