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

Query diff error when operation has variables #496

Closed
lvauvillier opened this issue Aug 2, 2016 · 3 comments
Closed

Query diff error when operation has variables #496

lvauvillier opened this issue Aug 2, 2016 · 3 comments
Assignees
Labels

Comments

@lvauvillier
Copy link

It seems query diff is not working in some cases when original query use variables.

I have an article container component which retrieve its data and its source from two distinct root queries.

The first time the component is mounted, everything works (the full query is sent to the server). But the second time with a different article and the same source the diff is not working.

Component connection :

export default connect({
  mapQueriesToProps: ({ ownProps }) => ({
    data: {
      query: gql`
        query articleWithSource($articleMid: MID!, $sourceMid: MID!) {
          article: article(mid: $articleMid) {
            rubric
            pubDate
            title
            subtitle
            byline
            abstract
            image {
              url
              width
              height
            }
          }
          source(mid: $sourceMid) {
            name
            image {
              url
              width
              height
            }
          }
        }
      `,
      variables: {
        articleMid: ownProps.params.articleMid,
        sourceMid: ownProps.sourceMid,
      },
    },
  }),
})(withTheme(ArticleContainer));

Generated diff query for the second article :


query articleWithSource($articleMid: MID!, $sourceMid: MID!) {
  article: article(mid: $articleMid) {
    rubric
    pubDate
    title
    subtitle
    byline
    abstract
    image {
      url
      width
      height
    }
  }
}

I get from the server :

{
  "errors": [
    {
      "message": "Variable \"$sourceMid\" is never used in operation \"articleWithSource\".",
      "locations": [
        {
          "line": 1,
          "column": 44
        }
      ]
    }
  ]
}
@stubailo
Copy link
Contributor

stubailo commented Aug 2, 2016

Sounds like we might need to avoid sending variables that are not actually included in the query!

@stubailo stubailo assigned Poincare and Slava and unassigned Poincare Aug 2, 2016
@stubailo
Copy link
Contributor

stubailo commented Aug 4, 2016

Hmm, this requires additional logic to manipulate the AST to remove variable definitions, scan for what variables are being used, etc.

Would it maybe be better to just get rid of this query diffing feature? Then the only difference is you just put it in as two separate queries if you want them to be cached independently. What do you think? Do you feel like you get a lot of value out of this feature?

@lvauvillier
Copy link
Author

I split it in two queries, this is a safe workaround, you're right.
But as it return an unexpected result, i think this is a good idea to disable query diffing for theses queries.

@Slava Slava closed this as completed Aug 9, 2016
@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

4 participants