question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GraphiQL Query Variables are reset whenever query is updated

See original GitHub issue

Description

I’ve noticed that the Query Variable field is reset every time I update a GraphQL query in the GraphiQL IDE.

Steps to reproduce

This can be reproduced on gatsby-starter-blog:

gatsby new graphiql-test https://github.com/gatsbyjs/gatsby-starter-blog
cd graphiql-test
gatsby develop

Open up GraphiQL: http://localhost:8000/___graphql and enter the following query:

query NewBeginningsPost($title: String!) {
  markdownRemark(frontmatter: {title: {eq: $title}}) {
    frontmatter {
      title
    }
  }
}

In the Query Variable section, add the following:

{
  "title": "New Beginnings"
}

Now update the query either directly in the query field, or using the Explorer menu on the left-hand side.

Expected result

The query variable field should not change unless we update it ourselves.

Actual result

Animated GIF showing query variables field being reset when the main query is updated

Environment

  System:
    OS: macOS 10.15.4
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Shell: 3.1.0 - /usr/local/bin/fish
  Binaries:
    Node: 12.16.3 - ~/.config/nvm/12.16.3/bin/node
    Yarn: 1.22.4 - ~/.config/nvm/12.16.3/bin/yarn
    npm: 6.14.4 - ~/.config/nvm/12.16.3/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 81.0.4044.138
    Edge: 81.0.416.77
    Safari: 13.1
  npmPackages:
    gatsby: ^2.21.37 => 2.21.37 
    gatsby-image: ^2.4.4 => 2.4.4 
    gatsby-plugin-feed: ^2.5.1 => 2.5.1 
    gatsby-plugin-google-analytics: ^2.3.1 => 2.3.1 
    gatsby-plugin-manifest: ^2.4.5 => 2.4.5 
    gatsby-plugin-offline: ^3.2.3 => 3.2.3 
    gatsby-plugin-react-helmet: ^3.3.1 => 3.3.1 
    gatsby-plugin-sharp: ^2.6.4 => 2.6.4 
    gatsby-plugin-typography: ^2.5.1 => 2.5.1 
    gatsby-remark-copy-linked-files: ^2.3.2 => 2.3.2 
    gatsby-remark-images: ^3.3.4 => 3.3.4 
    gatsby-remark-prismjs: ^3.5.1 => 3.5.1 
    gatsby-remark-responsive-iframe: ^2.4.2 => 2.4.2 
    gatsby-remark-smartypants: ^2.3.1 => 2.3.1 
    gatsby-source-filesystem: ^2.3.4 => 2.3.4 
    gatsby-transformer-remark: ^2.8.9 => 2.8.9 
    gatsby-transformer-sharp: ^2.5.2 => 2.5.2 

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
acaocommented, May 26, 2020

found the bugfix!

it seems to have been introduced in #21158

i will create a PR, but the solution is as simple as changing

const DEFAULT_VARIABLES =
  parameters.variables ||
  (window.localStorage && window.localStorage.getItem(`graphiql:variables`)) ||
  null

to

const DEFAULT_VARIABLES =
  parameters.variables ||
  (window.localStorage && window.localStorage.getItem(`graphiql:variables`)) ||
  undefined
1reaction
LekoArtscommented, May 20, 2020

Can confirm this with your repro. I also see this behavior when I open/close the “Explorer” pane. @acao who works on GraphiQL will look into this. Thanks for the issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Queries - Apollo GraphQL Docs
This article assumes you're familiar with building basic GraphQL queries. ... You can optionally provide a new variables object to the refetch function....
Read more >
Queries and Mutations - GraphQL
On this page, you'll learn in detail about how to query a GraphQL server. Fields#. At its simplest, GraphQL is about asking for...
Read more >
Updating GraphQL Query With New Variables - Stack Overflow
I have a GraphQL query from Apollo + React that I am using on a map component where the parameters are "latitude" and...
Read more >
Five Common Problems in GraphQL Apps (And How to Fix ...
There is a solution though, which is to cache the entire GraphQL query response. Unlike Dataloader, whose scope is limited to the current...
Read more >
Refreshing Queries - Relay
When referring to "refreshing a query", we mean fetching the exact same data that was originally rendered by the query, in order to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found