-
I'm trying to use this VSCode plugin to get autocomplete with GraphQL. However, it requires the following syntax: const query = graphql`
query Test {
test
}
` Notice that Could the // before
export function graphql(source: string | [string]) {
return (documents as any)[source] ?? {}
}
// after
export function graphql(source: string | [string]) {
if (Array.isArray(source)) {
return (documents as any)[source[0]] ?? {}
}
return (documents as any)[source] ?? {}
} And for the codegen'd function overloads, instead of doing this: function graphql(source: '\n query Test2($key: String!) {\n sentryTesting(key: $key)\n }\n'): ... ...it could do this: // separated for legibility
type Source = '\n query Test2($key: String!) {\n sentryTesting(key: $key)\n }\n'
function graphql(...source: [Source] | [[Source]]): ... |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Have you tried the GraphQL magic comment const query = graphql(/* GraphQL */`
query Test {
test
}
`) |
Beta Was this translation helpful? Give feedback.
-
@nandorojo have you tried modifying the generated code as you suggest? tl;dr it won't return a TypedDocumentNode because typescript's type system can't (currently) support overloads based on TemplateStringArray contents (or if it can, someone with type-fu greater than mine will need to chime in). I agree with your stance that the tagged template literal syntax is preferable, and I'd go a step further and say it's the idiomatic way inline gql is written. Finding a workaround for this should be explicitly added to the roadmap IMO, and if it's deemed impossible, this caveat should be clearly documented in the official docs. |
Beta Was this translation helpful? Give feedback.
Have you tried the GraphQL magic comment