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

SSR: ssr: false and variables in queries #1163

Closed
curio77 opened this issue Jan 12, 2017 · 6 comments
Closed

SSR: ssr: false and variables in queries #1163

curio77 opened this issue Jan 12, 2017 · 6 comments
Labels

Comments

@curio77
Copy link

curio77 commented Jan 12, 2017

I have a setup using ApolloClient (v0.6.0; v0.7.1 behaves identically) in conjunction with React, Redux, and SSR. With this I noticed that if I have a query decorating a component like this:

graphql(ItemsQuery, {
  options: ({ root }) => ({
    variables: {
      root: root || null,
      limit: 50,
      offset: null,
    },
  }),
})(Items);

with the query being

query Items($root: Int, $limit: Int, $offset: Int) {
  items(root:$root limit:$limit offset:$offset) {
    id
    name
  }
}

then things work as intended with SSR enabled.

However, adding ssr: false to the options gives the following — obviously unfounded — error:

Error: The inline argument "root" is expected as a variable but was not provided.

I.e., this only happens client-site if SSR is disabled for the query, but not server-side (with SSR enabled).

I'm clueless as to why this might be and suspect a bug in ApolloClient.

@helfer
Copy link
Contributor

helfer commented Jan 12, 2017

@curio77 can you reproduce this issue with only Apollo Client (i.e. without using react-apollo
s graphql HOC)? If not, it would be better to file the issue on react-apollo so we can first figure out if it's a bug in react-apollo. Thanks!

@curio77
Copy link
Author

curio77 commented Jan 12, 2017

Drat, completely forgot about react-apollo being separate. Will check and update/repost this accordingly.

@curio77
Copy link
Author

curio77 commented Jan 12, 2017

OK, so I've refactored this to do away with react-apollo, replacing the HOC call with this code in my component's componentDidMount():

return this.context.apollo.query({
  query: ItemsQuery,
  variables: {
    root: this.props.root || null,
    limit: 50,
    offset: null,
  },
}).then(data => this.setState({ data }));

This yields the same, so I think this is an apollo-client issue after all?

Uncaught (in promise) Error: Network error: The inline argument "root" is expected as a variable but was not provided.

@curio77
Copy link
Author

curio77 commented Jan 12, 2017

BTW, I load my queries via graphql-tag/loader but also tried the gql template literal route just now: makes no difference.

@curio77
Copy link
Author

curio77 commented Jan 19, 2017

This seems related to #1183: just as happens there, I've now looked at the chatter between client and GraphQL backend via Wireshark and confirmed that the request goes out including variables and the expected response gets returned, but regardless of this, the error gets thrown and my component gets no data.

@curio77
Copy link
Author

curio77 commented Jan 28, 2017

This issue is resolved for me with v0.8.1.

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

No branches or pull requests

3 participants