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

Empty responses using MockedProvider and custom resolvers #4520

Closed
hwillson opened this issue Mar 2, 2019 · 17 comments
Closed

Empty responses using MockedProvider and custom resolvers #4520

hwillson opened this issue Mar 2, 2019 · 17 comments

Comments

@hwillson
Copy link
Member

hwillson commented Mar 2, 2019

Migrated from apollographql/react-apollo#2825 (comment):

Hey @hwillson, after updating from 2.5.0 to 2.5.1 I am now getting empty responses after I've mocked apollo provider and passed my own resolvers. I am not using apollo-link-state anymore.

2.5.0 version returns proper result but it warns in console that:

Found @client directives in query but no client resolvers were specified. You can now pass apollo-link-state resolvers to the ApolloClient constructor.

Also if I pass null to resolvers in v2.5.1 it also works but still gives the warning.

@ameistad
Copy link

ameistad commented Mar 2, 2019

Found @client directives in query but no client resolvers were specified. You can now pass apollo-link-state resolvers to the ApolloClient constructor.

I'm also getting this warning in a Nuxt project using apollo-client 2.5.1

@filipkroca
Copy link

filipkroca commented Mar 4, 2019

Here the same. I have done migration from apollo-boost to apollo-client because I need to apply middleware.

I think this warning is necessary for apollo-boost, but I do not understand why I'm getting it in apollo-link.

If I rollback to version:

{
"dependencies": {
"apollo-client": "2.4.13"
}
}

I'm not getting this warning, it happens only from 2.5.0 version.

@vickywane
Copy link

Has anyone been able to solve this ?
Am having same issue

@hwillson
Copy link
Member Author

hwillson commented Mar 7, 2019

A fix for this is in place, and will be coming in the next patch release of react-apollo. I'll re-cap the changelog notes here:

MockedProvider has been updated to stop setting a default resolvers
value of {}, which means by default Apollo Client 2.5 local resolver
functionality is not enabled when mocking with MockedProvider. This allows
@client fields to be passed through the mocked link chain, like people
were used to before AC 2.5. When using this default mode you will see a
dev only warning message about this like:

Found @client directives in query but no client resolvers were specified. You can now pass apollo-link-state resolvers to the ApolloClient constructor.

This message can be safely ignored. If you want to use MockedProvider
with AC 2.5's new local resolver functionality, you can pass your local
resolver map into the MockedProvider resolvers prop.

And just to add - the warning message above is going to change to the following, in the next patch release of Apollo Client (see #4550 for details):

Found @client directives in a query but no ApolloClient resolvers were specified. This means ApolloClient local resolver handling has been disabled, and @client directives will be passed through to your link chain.

@youfoundron
Copy link

Also experiencing this issue.

@epileftro85
Copy link

Nothing on this?

@taylor-lindores-reeves
Copy link

taylor-lindores-reeves commented May 17, 2019

I'm getting this warning "Found @client directives in query but no client resolvers were specified. You can now pass apollo-link-state resolvers to the ApolloClient constructor." for apparently no reason?

**** EDIT ****

Updated apollo-boost to ^0.3.1 which removed the warning.

@alondahari
Copy link

If anyone gets here because of the console warning, without using MockedProvider, update your local state management: https://www.apollographql.com/docs/react/essentials/local-state/#migrating-from-apollo-link-state

@Anahkiasen
Copy link

Having the same issue, everything is properly configured and my tests pass, but I get dozens of warnings about the @client directive in Jest

@elaich
Copy link

elaich commented Aug 4, 2019

My tests don't pass and I get this error message, the query on MockedProvider doesn't resolve the results.

Found @client directives in a query but no ApolloClient resolvers were specified. This means ApolloClient local resolver handling has been disabled, and @client directives will be passed through to your link chain

@hwillson hwillson removed their assignment Aug 7, 2019
@pdemarino
Copy link

Hi all, FWIW I am getting the same issue. Basically I am posting the following query:

query getTasks($item: ID!) {
    record (id: $item) {
      tasks @client {
        id
        name
        state
        deadline
      }
    }
  }

Going through the source, I put a breakpoint on MockLink's requestToKey - and the query that it received was:

query getTasks($item: ID!) {
    record (id: $item) {
     __typename
    }
  }

Something in the pipeline is stripping the @client fields away, making it impossible to mock them.

This is a problem, as I am using Storybook to simulate my components.

@pdemarino
Copy link

This appears to happen when the MockLink is created, not when it's queried - at that point, the queries seem to go through intact.

@ken-nah
Copy link

ken-nah commented Aug 22, 2019

Anything about this am also getting the following warning
Found @client directives in a query but no ApolloClient resolvers were specified. This means ApolloClient local resolver handling has been disabled, and @client directives will be passed through to your link chain

@elaich
Copy link

elaich commented Aug 22, 2019

If you have local resolvers try adding them to your MockedProvider as follow

<MockedProvider resovlers={resolvers}>
  <Component>
</MockedProvider>

@pdemarino
Copy link

pdemarino commented Aug 22, 2019 via email

@nathanredblur
Copy link

nathanredblur commented Nov 9, 2020

Same similar problem here.

I have this query:

export const GET_AVAILABLE_PLANS = gql`
  query getAvailablePlans($areaId: Int!) {
    availablePlans(areaId: $areaId) @client
  }
`;

and on use this mock:

export const getAvailablePlansMock = {
  request: {
    query: GET_AVAILABLE_PLANS,
    variables: { areaId },
  },
  result: {
    data: {
      availablePlans: [{
        id: areaId,
        name: 'Salem',
        __typename: 'AvailablePlans',
      }],
    },
  },
};

I didn't get any result.

Only using a resolver:

const resolvers = {
  Query: {
    availablePlans: () => getAvailablePlansMock.result.data.availablePlans,
  },
};

I was able to get data.

This looks like an issue to me. resolver shouldn't be required if you specify the query result.

I was using:

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

@hwillson
Copy link
Member Author

See #4520 (comment) for a solution. Thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests