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.

poll schema every minute (#112)

* poll schema every minute

* fix

authored by

Jovi De Croock and committed by
GitHub
49568110 5d3ef644

+54 -44
+5
.changeset/odd-bugs-think.md
··· 1 + --- 2 + '@0no-co/graphqlsp': patch 3 + --- 4 + 5 + Poll schema every minute
+49 -44
packages/graphqlsp/src/graphql/getSchema.ts
··· 31 31 version: 0, 32 32 }; 33 33 let url: URL | undefined; 34 - 35 - let isJSON = false; 36 - let config: undefined | SchemaOrigin; 34 + let config: { headers: Record<string, unknown> } | undefined; 37 35 38 36 try { 39 37 if (typeof schema === 'object') { 40 38 url = new URL(schema.url); 39 + config = { headers: schema.headers }; 41 40 } else { 42 41 url = new URL(schema); 43 42 } 44 43 } catch (e) {} 45 44 46 45 if (url) { 47 - logger(`Fetching introspection from ${url.toString()}`); 48 - fetch(url.toString(), { 49 - method: 'POST', 50 - headers: 51 - isJSON && config 46 + const pollSchema = () => { 47 + logger(`Fetching introspection from ${url!.toString()}`); 48 + fetch(url!.toString(), { 49 + method: 'POST', 50 + headers: config 52 51 ? { 53 52 ...(config.headers || {}), 54 53 'Content-Type': 'application/json', ··· 56 55 : { 57 56 'Content-Type': 'application/json', 58 57 }, 59 - body: JSON.stringify({ 60 - query: getIntrospectionQuery({ 61 - descriptions: true, 62 - schemaDescription: false, 63 - inputValueDeprecation: false, 64 - directiveIsRepeatable: false, 65 - specifiedByUrl: false, 58 + body: JSON.stringify({ 59 + query: getIntrospectionQuery({ 60 + descriptions: true, 61 + schemaDescription: false, 62 + inputValueDeprecation: false, 63 + directiveIsRepeatable: false, 64 + specifiedByUrl: false, 65 + }), 66 66 }), 67 - }), 68 - }) 69 - .then(response => { 70 - logger(`Got response ${response.statusText} ${response.status}`); 71 - if (response.ok) return response.json(); 72 - else return response.text(); 73 67 }) 74 - .then(result => { 75 - logger(`Got result ${JSON.stringify(result)}`); 76 - if (typeof result === 'string') { 77 - logger(`Got error while fetching introspection ${result}`); 78 - } else if (result.data) { 79 - try { 80 - ref.current = buildClientSchema( 81 - (result as { data: IntrospectionQuery }).data 82 - ); 83 - ref.version = ref.version + 1; 84 - logger(`Got schema for ${url!.toString()}`); 85 - if (shouldTypegen) 86 - generateBaseTypes( 87 - ref.current, 88 - baseTypesPath, 89 - scalars, 90 - extraTypes 68 + .then(response => { 69 + logger(`Got response ${response.statusText} ${response.status}`); 70 + if (response.ok) return response.json(); 71 + else return response.text(); 72 + }) 73 + .then(result => { 74 + logger(`Got result ${JSON.stringify(result)}`); 75 + if (typeof result === 'string') { 76 + logger(`Got error while fetching introspection ${result}`); 77 + } else if (result.data) { 78 + try { 79 + ref.current = buildClientSchema( 80 + (result as { data: IntrospectionQuery }).data 91 81 ); 92 - } catch (e: any) { 93 - logger(`Got schema error for ${e.message}`); 82 + ref.version = ref.version + 1; 83 + logger(`Got schema for ${url!.toString()}`); 84 + if (shouldTypegen) 85 + generateBaseTypes( 86 + ref.current, 87 + baseTypesPath, 88 + scalars, 89 + extraTypes 90 + ); 91 + } catch (e: any) { 92 + logger(`Got schema error for ${e.message}`); 93 + } 94 + } else { 95 + logger(`Got invalid response ${JSON.stringify(result)}`); 94 96 } 95 - } else { 96 - logger(`Got invalid response ${JSON.stringify(result)}`); 97 - } 98 - }); 97 + }); 98 + }; 99 + 100 + pollSchema(); 101 + setInterval(() => { 102 + pollSchema(); 103 + }, 1000 * 60); 99 104 } else if (typeof schema === 'string') { 100 105 const isJson = schema.endsWith('json'); 101 106 const resolvedPath = path.resolve(path.dirname(root), schema);