js-graphql-intellij-plugin icon indicating copy to clipboard operation
js-graphql-intellij-plugin copied to clipboard

Apollo gql tagged template literals: Setting default parameter using variable substitution leads to error

Open ecomcoders opened this issue 4 years ago • 4 comments

I would like to set default values to some parameters in my GraphQL schema using Apollo server tagged template literals. But as soon as I try to use variable substitution for my default values, I got the following error in my query test suite using the apollo-server-testing package:

Unknown field "...": The parent selection or operation does not resolve to a valid schema type

Cutout of my schema:

export default gql`
  type Query {
   cardList(pageSize: Int = ${myPageSizeVariable}): CardList
   ...
 }`;

As soon as I put ${myPageSizeVariable} in, I get lost of Schema-aware completion and error highlighting in my tests with the mentioned error message. With a number literal as default value, everything works fine.

ecomcoders avatar Dec 02 '20 08:12 ecomcoders

I believe this is related: In a React project using Apollo GraphQL client I'm trying to structure my queries in files that export both the query itself and the query's name. Like this:

import gql from 'graphql-tag';

export const queryName = 'myQueryName';

const query = gql`
  query ${queryName} {
    theThingWeNeed {
      someField {
        subField1
        subField2
      }
    }
  }
`;

export default query;

However, the template literal string substitution of the queryName causes the GraphQL schema validation from this plugin to fail:

image

tinynumbers avatar Nov 17 '21 22:11 tinynumbers

@tinynumbers hi! Unfortunately, current support for template literals is very limited, you are allowed to use placeholders only in predefined places, they are hardcoded in the parser, and it's not the way it's usually done in IDEA. This subsystem should be reworked and it should be done in the near future, but I can't provide any exact estimates 😞.

vepanimas avatar Nov 19 '21 19:11 vepanimas

Still waiting...

IBlasterus avatar Aug 18 '22 09:08 IBlasterus

Any update or milestone for this feature?

wiput1999 avatar Dec 14 '22 10:12 wiput1999