Giter Club home page Giter Club logo

Comments (10)

dthyresson avatar dthyresson commented on July 24, 2024 2

I would have never thought of that

We didn't either -- until we found that issue and then it actually makes perfect sense.

Under the covers RedwoodJS replies on https://www.apollographql.com/docs/react/data/fragments/#usefragment and we think that needs to know the type to properly match up data with the fragment in the query.

from redwood.

irg1008 avatar irg1008 commented on July 24, 2024 2

Okay it's working!, closing this know. Great work the RedwoodJS team is amazing

from redwood.

dthyresson avatar dthyresson commented on July 24, 2024 1

Hi @irg1008 thanks to @arimendelow we think we figured it out. Ignore the updates I made to your reproduction repo as having the two cells with the two queries can confuse the issue. but try using:


// Define your own mock data here:
export const standard = (/* vars, { ctx, req } */) => ({
  chatMessages: Array.from({ length: 20 }, (_, index) => ({
    __typename: 'ChatMessage',
    body: `Message${index + 1}`,
    createdAt: '2021-07-01T00:00:00.000Z',
    id: index + 1,
    user: {
      __typename: 'ChatUser',
      displayName: `User ${(index % 5) + 1}`, // Cycle through 5 different users
      id: (index % 5) + 1,
    },
    chatRoomId: '42',
  })) satisfies ChatMessage[],
})

in ChatCell.mock.ts.

Notice the __typename in the data to note what the GraphQL types are. This appears to be needed so that Apollo can understand have to use the fragments and map the data coming back.

Some more info in: mswjs/msw#630

Can you see if that works for you?

We'll update the Fragment docs (or if you feel like making a docs PR, that'd be amazing) and then think about how this might be done more transparently. But it is good practice I guess to include the typenames since that in fact does come back in real-world cases from Yoga.

from redwood.

irg1008 avatar irg1008 commented on July 24, 2024 1

Oh my god I would have never thought of that, will try it tomorrow and let you know. And will happily make the PR to the fragment docs. Thanks!

from redwood.

dthyresson avatar dthyresson commented on July 24, 2024

Hi @irg1008 and thanks for writing up this issue — I’ll have to recreate it with. Small reproduction.

One question: for the log output of your mock is that from running a test or using storybook?

from redwood.

irg1008 avatar irg1008 commented on July 24, 2024

Sorry should have said. It's Storybook. If need me to create a small repo please say so

from redwood.

dthyresson avatar dthyresson commented on July 24, 2024

If need me to create a small repo please say so

If you could, that would be really helpful for me to reproduce and know we are seeing the same thing.

Thanks!

from redwood.

irg1008 avatar irg1008 commented on July 24, 2024

Okay there you go: https://github.com/irg1008/issue-redwood-fragments-storybook.git

  1. Install (yarn install, etc)
  2. yarn rw dev
  3. yarn rw storybook
  4. Open storybook > Components > Chat: See that IS WORKING
  5. Go to ChatCell.tsx
  6. Uncomment and comment to swap to using fragment
  7. Open storybook > Components > Chat: NOT WORKING

from redwood.

dthyresson avatar dthyresson commented on July 24, 2024

Hi @irg1008 I forked and made PR on your demo repo here: irg1008/issue-redwood-fragments-storybook#1

The cells themselves appear to mock ok, but when the cell is then used in a component (or maybe even a page) and that story then doesn't appear to "pass along" the mocked data so to speak. Am investigating still.

from redwood.

irg1008 avatar irg1008 commented on July 24, 2024

I just merged it. If you need any help I am starting to learn the redwood repo I can help

from redwood.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.