redwood: [Bug]: Seeing Unknown Fragment after migration to use `registerFragment`
What’s not working?
I was previously, pre rw 7, using fragments (successfully) using string interpolation. Post upgrade, there are no changes to the actual query itself, except that the fragment is no longer interpolated, and is being registered instead.
I have a GQL Fragment, F_Fragment, which is being used in a query, Q_QUERY.
UPDATE - file info Here’s the code for the fragment, in fragment.ts:
import { registerFragment } from '@redwoodjs/web/apollo'
const F_Fragment = gql`
fragment F_Fragment on F {
field1
field2
}`
registerFragment(F_Fragment)
UPDATE - file info The code for the query, in query.ts:
const Q_QUERY = gql`
query QQuery {
f {
...F_Fragment
}
}
We can no longer fetch the required data using the query, and get the Unknown fragment A_Fragment error.
The query is called in this way:
import { useQuery } from '@redwoodjs/web'
export default () => {
return useQuery(Q_QUERY)
}
Interestingly, the graphql types are generated correctly. The query also still works with string interpolation (minus types). Any ideas here?
How do we reproduce the bug?
UPDATED Declare and register fragment in a different file than the query
What’s your environment? (If it applies)
System: OS: macOS 13.6 Shell: 5.9 - /bin/zsh Binaries: Node: 20.11.1 - /private/var/folders/8y/99byt5ms31d1z8jgjfmyvcg80000gn/T/xfs-d437a37e/node Yarn: 3.2.1 - /private/var/folders/8y/99byt5ms31d1z8jgjfmyvcg80000gn/T/xfs-d437a37e/yarn Databases: SQLite: 3.39.5 - /usr/bin/sqlite3 Browsers: Chrome: 123.0.6312.59 Safari: 16.6 npmPackages: @redwoodjs/auth-auth0-setup: 7.1.3 => 7.1.3 @redwoodjs/cli-data-migrate: 7.1.3 => 7.1.3 @redwoodjs/core: 7.1.3 => 7.1.3
Are you interested in working on this?
- I’m interested in working on this
About this issue
- Original URL
- State: closed
- Created 3 months ago
- Comments: 20 (9 by maintainers)
Commits related to this issue
- fix: Fixes Unknown Fragment issues due to GraphQL Tag type mismatch in web (#10357) Fixes: https://github.com/redwoodjs/redwood/issues/10322 See ^^^ --- Tested that both the graphql toml con... — committed to redwoodjs/redwood by dthyresson 2 months ago
- fix: Fixes Unknown Fragment issues due to GraphQL Tag type mismatch in web (#10357) Fixes: https://github.com/redwoodjs/redwood/issues/10322 See ^^^ --- Tested that both the graphql toml con... — committed to redwoodjs/redwood by dthyresson 2 months ago
- fix: Fixes Unknown Fragment issues due to GraphQL Tag type mismatch in web (#10357) Fixes: https://github.com/redwoodjs/redwood/issues/10322 See ^^^ --- Tested that both the graphql toml con... — committed to redwoodjs/redwood by dthyresson 2 months ago
@shivghai and @pvenable I think I may have found the culprit and even why I may not have seen it when working on fragments as the change to help support Trusted Documents aka Persisted Operations changed the type of the global gql.
The generic type we had made for TD support seems to be incompatible with the graphql-tag:
With this change, TS and GraphQL seem to be happy:
I need to do some tests that TD still works, but I think you have two workarounds:
global.web-auto-imports.d.tsin web node modules dist (web/node_modules/@redwoodjs/web/dist/global.web-auto-imports.d.ts) toIt’s that
...argsthat we didn’t have that seems to be the root of the expecrtect 1 but got 2 etc.I also been to test that this is ok with the fragments setting turns on – but I think I am on the right track.
Since TD was implemented after, and our e2e/CI/test suite used the collocated fragments pattern this got missed unfortunately.