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.

Wrap auto-completed list input values with square brackets if required

See original GitHub issue

In Gatsby’s connections, you can add a sort input like the following:

allMarkdownRemark(sort: { fields: [frontmatter___title], order: DESC}) {
  edges {
    node {
      id
    }
  }
}

But in graphiql, it doesn’t enforce that fields must be an array so people regularly complain sorting is broken as they just add a field in the UI and then when they try to copy that into a project it won’t work.

Is there a reason graphiql is like this? It seems to be casting the single values to an array which is why it seems to work.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:7
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
OlegIlyenkocommented, Jun 29, 2018

If I understand what you are describing correctly, then this aspect is covered by the GraphQL spec:

If the value passed as an input to a list type is not a list and not the null value, it should be coerced as though the input was a list of size one, where the value passed is the only item in the list. This is to allow inputs that accept a “var args” to declare their input type as a list; if only one argument is passed (a common case), the client can just pass that value rather than constructing the list.

In other words, it is ok to skip list syntax (e.g. [...]) if list has only one element.

1reaction
coreywardcommented, Jun 29, 2018

+1 Currently Relay will cast a single value to a string; graphiql’s deviation from this causes incompatibilities.

Read more comments on GitHub >

github_iconTop Results From Across the Web

why are square brackets used in javascript function calls? jquery
It's a requirement from jQuery 's trigger function that the second parameter be an array (prior to 1.6.2), thus the wrapping to make...
Read more >
Outlook advanced editing options - Microsoft Support
Learn how to use the advanced editing options in Outlook.
Read more >
Frequently Asked Questions - Snakemake - Read the Docs
A named tuple that contains a list of values for each wildcard is returned. Here, this named tuple has only one item, that...
Read more >
Language Configuration Guide - Visual Studio Code
Autosurrounding. When you select a range in VS Code and enter an opening bracket, VS Code surrounds the selected content with a pair...
Read more >
Editable Combobox With List Autocomplete Example - W3C
This example illustrates the autocomplete behavior known as list ... but it does not prevent input of any other arbitrary value.
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