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

Does not return mock. #6

Closed
MarkLyck opened this issue Sep 27, 2020 · 3 comments
Closed

Does not return mock. #6

MarkLyck opened this issue Sep 27, 2020 · 3 comments
Labels
needs more info Not enough info to move forward with yet

Comments

@MarkLyck
Copy link

MarkLyck commented Sep 27, 2020

using this as per the docs does not seem to work for my simple component using @apollo-client.

When running the story, the useQuery hook returns:

{
  error: undefined,
  loading: true,
  data: undefined
}

then it returns:

{
  error: undefined,
  loading: false,
  data: undefined
}

It does not return the mock I provided in my story:

story.tsx

import React from 'react'
import { MockedProvider } from "@apollo/client/testing";
import LatestSells from '~/components/SalesPage/LatestSells'
import { LATEST_SELL_SIGNALS } from '~/common/queries'

export default {
  title: 'Sales page/latest sells',
}


const mocks = [
  {
    request: {
      query: LATEST_SELL_SIGNALS,
      variables: {},
    },
    result: {
      data: {
        dog: {
          name: "Douglas"
        }
      }
    }
  }
]

export const latest_sells = () => {
  return (
    <MockedProvider mocks={mocks} addTypename={false}>
      <LatestSells />
    </MockedProvider>
  )
}

I made my component as simple as possible to troubleshoot, but it doesn't work even when simplified down to the smallest possible react component.

component:

import React from 'react'
import { useQuery } from '@apollo/client'
import { LATEST_SELL_SIGNALS } from '~/common/queries'

const LatestSells = () => {
  const { loading, error, data } = useQuery(LATEST_SELL_SIGNALS)
  console.log(loading, error, data)
  return null
}

export default LatestSells

Even with the simplest possible setup, this does not work.

Lastly here is my query:

import { gql } from 'apollo-boost'

export const LATEST_SELL_SIGNALS = gql`
  query {
    latestSellSignalsList(orderBy: createdAt_DESC, first: 10) {
      items {
        name
        ticker
        boughtAt
        soldAt
      }
    }
  }
`

I've doubled checked that the query console logs correctly and the same in both the story and the actual component.

versions:
"@apollo/client": "^3.2.1",
"storybook-addon-apollo-client": "^3.0.0",

P.S.

My component works fine on localhost and production, so the query etc. is definitely valid and normally called without issues.

@lifeiscontent
Copy link
Owner

@MarkLyck what's your config for the Storybook Apollo Client Decorator look like in preview.js?

@lifeiscontent lifeiscontent added the needs more info Not enough info to move forward with yet label Oct 23, 2020
@lifeiscontent
Copy link
Owner

@MarkLyck closing since you haven't responded in almost 2 months.

@YoruNoHikage
Copy link

In case anyone is encountering this, more to be found here : apollographql/apollo-client#7081 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info Not enough info to move forward with yet
Projects
None yet
Development

No branches or pull requests

3 participants