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.

0.7 source-graphql isn't accepting type [Int] query arguments

See original GitHub issue

Description

I’m using Craft CMS’s new internal GraphQL in context of adding a very nice ability for Gridsome. This was working fine in Gridsome 0.6 with the prior method of accessing external GraphqL servers.

Now, when I define a (necessary) page query of form:

   query someQuery (id: [Int], url: [String]) { 
    craftgql {
     entries (id: $id, url: $url) {
       ...
      }
    }
  }
  • the [String] argument is accepted and works fine, if it’s there alone
  • the [Int] argument, however, fails hard when used in entries(), a valid entity in the Schema to query
  • with gridsome build, I get an error like:
Error: Variable "$id" expected value of type "[Int]" which cannot be used as an input type.
GraphQL request:84:24
83 |
84 | query CardzrNoID ($id: Int, $uri: [String]) {
  • There’s a note in the graphql js source that this should be caught in schema validation, but perhaps you only do that on gridsome develop, where I see:
Module build failed (from ./node_modules/gridsome/lib/plugins/vue-components/lib/loaders/page-query.js):
Error: Unknown type "[Int]". Did you mean "Int"?
  • And no, I don’t mean “Int”. id in this case is defined in the Craft Schema as [Int], not Int. If you wonder, List types also accept single values, so that covers “Int” but anyway that’s not at issue here.

Summary: some how Gridsome’s plugin seems not to pick up that [Int] is a List type, so that it’s not allowed per the js graphql definition.mjs code as an Input Type. That’s the root of the error reported in this issue.

I realize this sounds at first like something to do with Craft’s internal GraphQL server’s Schema defs, but the same schema and (real) query works fine (with the [Int]) when I access directly through the service inside Craft, or through Gatsby as a page query, or indeed when I exercise it point-blank using Insomnia.

I’ve also looked at the GraphQL schema-defining source in Craft, which uses webonyx underneath, and ìd` does seem to be defined as List of Int type.

Steps to reproduce

  • make your own query on some server and table of the form above, with an [Int] array query argument defined for a field that accepts array of ints. No need to actually set the query variable, or you can set it to null as either is acceptable since it’s not defined non-null.
  • hmm. You can run your query against your own server, and see if you get the error. I’m just realizing that if you don’t, I’m going to need to set up a publicly accessible Craft with GraphQL server to test against so you can see it.
  • or, if there’s a way I could conveniently dump out the resolved schema from a page source in Gridsome, let me know, and happy to do that, should you need it…

Expected result

Such a query should work fine, as it does against the (very different) CraftQL plugin. And no, this is not an alternative for many going forward.

Actual result

Error as above.

Environment


Libs:
- gridsome version: v0.7.4
- @gridsome/cli version: v0.2.4


Browser:
- [ X] Chrome (desktop) version latest

 
For Tooling issues:
- Node version: v12.6.0
- Platform:  =Win10 extreme up-to-date

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
narration-sdcommented, Sep 23, 2019

Ok! Just got 0.7.5, thanks, and your fix is working, for Gridsome itself. Queries with [Ints] for id are accepted, and indeed limit the result properly, within my built app. Which by the way, is demonstrating Live Previews for Gridsome via a plugin in Craft. Not released yet, as the Gridsome part is reaching its final architecture.

I’ll put a screenshot below, showing that for Gridsome’s very nice explore/Playground, things don’t appear to be quite connected yet. There, id is accepted as [Int], in the query, but isn’t obeyed when setting a query variable for it. You can see the message I get when hovering, flagged by the red bar, and some data also with ids that don’t match it – the one that does is off-screen.

Playground is not a priority here, as I can also use Insomnia, so as you can fold it in would be fine.

Quite appreciated to have gotten so rapidly what does let me proceed, Hans-Jørgen. and I always feel comfortable to return to working with Gridsome.

playground-id

0reactions
hjvedvikcommented, Sep 27, 2019

Bare hyggelig! We try not to break too much in the minor releases and show a deprecation warning before removing if possible 😃

Glad the variables work for you now. But I’m not sure what’s going on in the GraphQL Playground. It might be a bug with the package Gridsome use for it.

Looking forward to checking out that Craft plugin with Live Previews!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolvers - Apollo GraphQL Docs
We want to define resolvers for the numberSix and numberSeven fields of the root Query type so that they always return 6 and...
Read more >
Why doesn't GraphQL accept this scalar argument type ...
I have tried making the argument type an Input Type, but it didn't help. Why is the code generating the error, and how...
Read more >
Resolvers – GraphQL Tools
Since the schema already describes all of the fields, arguments, ... To respond to queries, a schema needs to have resolvers for all...
Read more >
Queries and Mutations - GraphQL
The field name returns a String type, in this case the name of the main hero of Star ... Declare $variableName as one...
Read more >
Five Common Problems in GraphQL Apps (And How to Fix ...
But of course, a GraphQL schema can also have custom types: User ... await graphql(executableSchema, query, {}, context, variables);.
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