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

fix: Fixes Unknown Fragment issues due to GraphQL Tag type mismatch in web #10357

Merged
merged 3 commits into from
Apr 19, 2024

Conversation

dthyresson
Copy link
Contributor

@dthyresson dthyresson commented Mar 28, 2024

Fixes: #10322

See ^^^


Tested that both the graphql toml config with fragments and trustedDocuments set to true works.

However, if trusted documents uses fragments seeing an intermittent Apollo issue. Investigating.

Update: Have confirm that if trusted documents uses fragments, works as expected. See note below.

Note: Had to make small fix to fragments setup to address an error when prettifying as final step.

@dthyresson dthyresson added the release:fix This PR is a fix label Mar 28, 2024
@dthyresson dthyresson added this to the next-release-patch milestone Mar 28, 2024
@dthyresson dthyresson self-assigned this Mar 28, 2024
@shivghai
Copy link

@dthyresson can I help with this?

@dthyresson dthyresson changed the title DRAFT: fix: Fixes Unknown Fragment issues due to GraphQL Tag type mismatch in web fix: Fixes Unknown Fragment issues due to GraphQL Tag type mismatch in web Apr 18, 2024
@dthyresson
Copy link
Contributor Author

@dthyresson can I help with this?

Sorry for the delay - "if trusted documents uses fragments seeing an intermittent Apollo issue. Investigating."

^^ I just need to confirm TD's with fragments was still working ok in a test project.

@dthyresson
Copy link
Contributor Author

dthyresson commented Apr 18, 2024

  1. Confirm Trusted Documents setup and using store working
  2. Confirmed fragments using useregisterFragment working.

image

  1. Confirmed that a TD query using fragments also works
    image
'69d9843ccef232ac2b27629fbb1cb913c25b1fdc':
    'fragment PostInfo on Post { __typename id title } query GetArticles { __typename articles: posts { __typename createdAt ...PostInfo } }',

@dthyresson dthyresson marked this pull request as ready for review April 18, 2024 16:05
@dthyresson
Copy link
Contributor Author

Steps to reproduce:

  1. Get this PR
  2. Build Test Project: yarn build:test-project ~/tmp/td-f-gql-test
  3. Setup TD: yarn rw setup graphql trusted-documents
  4. yarn rw g types and yarn rw dev and comfit in Network tab that requests use the TD id vs the query
  5. Stop dev
  6. Setup fragments: yarn rw setup graphql fragments
  7. new articles page: yarn rw g page articles

In ArticlesPage

import type { GetArticles } from 'types/graphql'

import { Metadata } from '@redwoodjs/web'
import { useQuery } from '@redwoodjs/web'
import { registerFragment } from '@redwoodjs/web/apollo'

registerFragment(gql`
  fragment PostInfo on Post {
    id
    title
  }
`)

const GET_ARTICLES = gql`
  query GetArticles {
    articles: posts {
      ...PostInfo
      createdAt
      # Include other fields specific to this query
    }
  }
`

const ArticlesPage = () => {
  const { data, loading } = useQuery<GetArticles>(GET_ARTICLES)

  return (
    <>
      <Metadata title="Articles" description="Articles page" />

      <h1>ArticlesPage</h1>
      {!loading &&
        data.articles.map((post) => (
          <div key={post.id}>
            {post.title} @ {post.createdAt}
          </div>
        ))}
    </>
  )
}
  1. yarn rw dev
  2. Navigate to /articles
  3. Should see list of articles with title and createdAt timestamp

@dthyresson
Copy link
Contributor Author

@Josh-Walker-GM Requested review as you had helped some of these setups. Also, will need a patch release. Thanks!

@dthyresson
Copy link
Contributor Author

dthyresson commented Apr 19, 2024

Original issue reproduction:

  1. yarn build:test-project ~/tmp/fragment-issue
  2. cd and yarn and yarn dev to test app up
  3. yarn rw g page Articles

for the ArticlesPage, use the following code:

import type { GetArticles } from 'types/graphql'

import { Metadata } from '@redwoodjs/web'
import { useQuery } from '@redwoodjs/web'
import { registerFragment } from '@redwoodjs/web/apollo'

const POST_FRAGMNET = gql`
  fragment PostInfo on Post {
    id
    title
  }
`

registerFragment(POST_FRAGMNET)

const GET_ARTICLES = gql`
  query GetArticles {
    articles: posts {
      ...PostInfo
      createdAt
      # Include other fields specific to this query
    }
  }
`

const ArticlesPage = () => {
  const { data, loading } = useQuery<GetArticles>(GET_ARTICLES)

  return (
    <>
      <Metadata title="Articles" description="Articles page" />

      <h1>ArticlesPage</h1>
      {!loading &&
        data.articles.map((post) => (
          <div key={post.id}>
            {post.title} @ {post.createdAt}
          </div>
        ))}
    </>
  )
}

export default ArticlesPage
  1. yarn rw g types
  2. You will still see the error
    image
Unknown fragment "PostInfo".GraphQL: Validation
  1. run yarn rwfw project:sync with this PR
  2. Type error goes away

image

  1. yarn rw dev
  2. navigate to /articles

image

Copy link
Collaborator

@Josh-Walker-GM Josh-Walker-GM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paired with @dthyresson on this and confirmed it fixes the type issue.

@Josh-Walker-GM Josh-Walker-GM merged commit ae7ed1a into main Apr 19, 2024
52 checks passed
@Josh-Walker-GM Josh-Walker-GM deleted the dt-gql-tag-fragments-web-global branch April 19, 2024 12:53
Josh-Walker-GM pushed a commit that referenced this pull request Apr 19, 2024
…n web (#10357)

Fixes: #10322

See ^^^

---

Tested that both the graphql toml config with fragments and
trustedDocuments set to true works.

However, if trusted documents uses fragments seeing an intermittent
Apollo issue. Investigating.

Update: Have confirm that if trusted documents uses fragments, works as
expected. See note below.

Note: Had to make small fix to fragments setup to address an error when
prettifying as final step.
Josh-Walker-GM pushed a commit that referenced this pull request Apr 19, 2024
…n web (#10357)

Fixes: #10322

See ^^^

---

Tested that both the graphql toml config with fragments and
trustedDocuments set to true works.

However, if trusted documents uses fragments seeing an intermittent
Apollo issue. Investigating.

Update: Have confirm that if trusted documents uses fragments, works as
expected. See note below.

Note: Had to make small fix to fragments setup to address an error when
prettifying as final step.
dac09 added a commit that referenced this pull request Apr 22, 2024
…g-gen-mw-p2

* 'main' of github.com:redwoodjs/redwood:
  fix(deps): update React to latest canary 19.x (#10496)
  fix(upgrade): Download yarn patches (#10497)
  Revert React 19 upgrade (#10482 and #10491) (#10495)
  Modified type for describeScenario (#10468)
  fix(upgrade): Download yarn patches (#10491)
  fix(deps): update React to latest canary 19.x (#10482)
  chore(dataMigrate): Fix package.json directory value (#10490)
  RSC: css preinit: Add required option precedence (#10481)
  chore(renovate): Remove config for unused package (#10489)
  RSC: Update test projects to use new @apollo/client-react-streaming (#10488)
  RSC: Remove unused vite patch from test-project-rsa (#10487)
  chore(ssr): Switch to use `@apollo/client-react-streaming` package (#10484)
  chore(docs): Move .mdx import into separate file (#10486)
  fix(cli): avoid `npx` during upgrade command (#10479)
  fix: Fixes Unknown Fragment issues due to GraphQL Tag type mismatch in web (#10357)
  RSC: Clean up some comments and logs (#10480)
  feat: redwoodjs/auth-dbauth-middleware - Part 2/3 - Auth Middleware for dbAuth to authenticate users via cookie (#10447)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Seeing Unknown Fragment after migration to use registerFragment
3 participants