···11+---
22+'@0no-co/graphqlsp': major
33+---
44+55+Look for `gql` and `graphql` by default as well as change the default for call-expressions to true.
66+77+If you are using TaggedTemplateExpressions you can migrate by adding the following to your tsconfig file
88+99+```json
1010+{
1111+ "plugins": [
1212+ {
1313+ "name": "@0no-co/graphqlsp",
1414+ "schema": "...",
1515+ "templateIsCallExpression": false
1616+ }
1717+ ]
1818+}
1919+```
+2-4
README.md
···60606161**Optional**
62626363-- `template` the shape of your template, by default `gql`
6363+- `template` the shape of your template, by default `gql` and `graphql` are respected
6464- `templateIsCallExpression` this tells our client that you are using `graphql('doc')`
6565- `shouldCheckForColocatedFragments` when turned on, this will scan your imports to find
6666 unused fragments and provide a message notifying you about them
···7979 "name": "@0no-co/graphqlsp",
8080 "schema": "./schema.graphql",
8181 "disableTypegen": true,
8282- "templateIsCallExpression": true,
8382 "shouldCheckForColocatedFragments": true,
8484- "trackFieldUsage": true,
8585- "template": "graphql"
8383+ "trackFieldUsage": true
8684 }
8785 ]
8886 }
···11-import ts from 'typescript/lib/tsserverlibrary';
11+import ts, { TaggedTemplateExpression } from 'typescript/lib/tsserverlibrary';
22import { Diagnostic, getDiagnostics } from 'graphql-language-service';
33import {
44 FragmentDefinitionNode,
···5757 schema: { current: GraphQLSchema | null; version: number },
5858 info: ts.server.PluginCreateInfo
5959): ts.Diagnostic[] | undefined {
6060- const tagTemplate = info.config.template || 'gql';
6161- const isCallExpression = info.config.templateIsCallExpression ?? false;
6060+ const isCallExpression = info.config.templateIsCallExpression ?? true;
62616362 let source = getSource(info, filename);
6463 if (!source) return undefined;
···6665 let fragments: Array<FragmentDefinitionNode> = [],
6766 nodes: (ts.TaggedTemplateExpression | ts.NoSubstitutionTemplateLiteral)[];
6867 if (isCallExpression) {
6969- const result = findAllCallExpressions(source, tagTemplate, info);
6868+ const result = findAllCallExpressions(source, info);
7069 fragments = result.fragments;
7170 nodes = result.nodes;
7271 } else {
7373- nodes = findAllTaggedTemplateNodes(source, tagTemplate);
7272+ nodes = findAllTaggedTemplateNodes(source);
7473 }
75747675 const texts = nodes.map(node => {
···123122 schema: { current: GraphQLSchema | null; version: number },
124123 info: ts.server.PluginCreateInfo
125124) => {
126126- const tagTemplate = info.config.template || 'gql';
127125 const filename = source.fileName;
128128- const isCallExpression = info.config.templateIsCallExpression ?? false;
126126+ const isCallExpression = info.config.templateIsCallExpression ?? true;
129127130128 const diagnostics = nodes
131129 .map(originalNode => {
···159157 }
160158 // When we are dealing with a plain gql statement we have to add two these can be recognised
161159 // by the fact that the parent is an expressionStatement
160160+162161 let startingPosition =
163162 node.pos +
164164- (isCallExpression ? 0 : tagTemplate.length + (isExpression ? 2 : 1));
163163+ (isCallExpression
164164+ ? 0
165165+ : (node as TaggedTemplateExpression).tag.getText().length +
166166+ (isExpression ? 2 : 1));
165167 const endPosition = startingPosition + node.getText().length;
166168167169 let docFragments = [...fragments];
···336338 start,
337339 length,
338340 } = moduleSpecifierToFragments[moduleSpecifier];
339339- const missingFragments = Array.from(new Set(fragmentNames.filter(
340340- x => !usedFragments.has(x)
341341- )));
341341+ const missingFragments = Array.from(
342342+ new Set(fragmentNames.filter(x => !usedFragments.has(x)))
343343+ );
342344 if (missingFragments.length) {
343345 fragmentDiagnostics.push({
344346 file: source,
+6-14
packages/graphqlsp/src/index.ts
···44import { getGraphQLCompletions } from './autoComplete';
55import { getGraphQLQuickInfo } from './quickInfo';
66import { getGraphQLDiagnostics } from './diagnostics';
77+import { templates } from './ast/templates';
7889function createBasicDecorator(info: ts.server.PluginCreateInfo) {
910 const proxy: ts.LanguageService = Object.create(null);
···22232324type Config = {
2425 schema: SchemaOrigin | string;
2525- // TODO: rename to tag or just remove entirely and always check for
2626- // gql and graphql.
2727- template?: string;
2828- // TODO: we need a bettername, gql.tada will also have
2929- // call expressions, we can differentiate by means of
3030- // tada having a second argument containing the fragments.
3126 templateIsCallExpression?: boolean;
3232- // Up in the air whether we want to keep supporting
3333- // this. Current limitation are barrel-file exports
3434- // could be counter-acted with an opinion on
3535- // fragment-naming. Could become more relevant
3636- // with gql.tada and could be useful for
3737- // client-preset as well however the component type-annotations
3838- // can better indicate a missing spread for the
3939- // client-preset.
4027 shouldCheckForColocatedFragments?: boolean;
2828+ template?: string;
2929+ trackFieldUsage?: boolean;
4130};
42314332function create(info: ts.server.PluginCreateInfo) {
···53425443 logger('Setting up the GraphQL Plugin');
55444545+ if (config.template) {
4646+ templates.add(config.template);
4747+ }
5648 const proxy = createBasicDecorator(info);
57495850 const schema = loadSchema(