js-graphql-intellij-plugin
js-graphql-intellij-plugin copied to clipboard
Apollo gql tagged template literals: Setting default parameter using variable substitution leads to error
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.
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:
@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 😞.
Still waiting...
Any update or milestone for this feature?