Mirror: TypeScript LSP plugin that finds GraphQL documents in your code and provides diagnostics, auto-complete and hover-information.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

avoid erroring on known client side directives (#144)

authored by

Jovi De Croock and committed by
GitHub
29938e91 b4fd0d88

+31 -2
+5
.changeset/khaki-clouds-marry.md
··· 1 + --- 2 + '@0no-co/graphqlsp': patch 3 + --- 4 + 5 + Don't error on known client-side directives
+1 -1
packages/example-external-generator/src/index.tsx
··· 3 3 4 4 const x = graphql(` 5 5 query Pok($limit: Int!) { 6 - pokemons(limit: $limit) { 6 + pokemons(limit: $limit) @populate { 7 7 id 8 8 name 9 9 fleeRate
+1 -1
packages/example/src/index.ts
··· 3 3 4 4 const x = gql` 5 5 query Pok($limit: Int!) { 6 - pokemons(limit: $limit) { 6 + pokemons(limit: $limit) @populate { 7 7 id 8 8 name 9 9 fleeRate
+24
packages/graphqlsp/src/diagnostics.ts
··· 21 21 import { resolveTemplate } from './ast/resolve'; 22 22 import { generateTypedDocumentNodes } from './graphql/generateTypes'; 23 23 24 + const clientDirectives = new Set([ 25 + 'populate', 26 + 'client', 27 + '_optional', 28 + '_required', 29 + 'arguments', 30 + 'argumentDefinitions', 31 + 'connection', 32 + 'refetchable', 33 + 'relay', 34 + 'required', 35 + 'inline', 36 + ]); 37 + const directiveRegex = /Unknown directive "@([^)]+)"/g; 38 + 24 39 export const SEMANTIC_DIAGNOSTIC_CODE = 52001; 25 40 export const MISSING_OPERATION_NAME_CODE = 52002; 26 41 export const MISSING_FRAGMENT_CODE = 52003; ··· 181 196 undefined, 182 197 docFragments 183 198 ) 199 + .filter(diag => { 200 + if (!diag.message.includes('Unknown directive')) return true; 201 + 202 + const [message] = diag.message.split('('); 203 + const matches = directiveRegex.exec(message); 204 + if (!matches) return true; 205 + const directiveNmae = matches[1]; 206 + return !clientDirectives.has(directiveNmae); 207 + }) 184 208 .map(x => { 185 209 const { start, end } = x.range; 186 210