-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add gql editor support: autocomplete / quick infos / go to definitions (
#40) * add gql quick infos * add quick-infos test * add gql auto-complete with test * add gql go to definitions * improve get definition and bound span add tests * improve definition coverage * update README * upgrade to 1.5.0
- Loading branch information
Showing
56 changed files
with
1,997 additions
and
518 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-7.88 KB
...ache/@endemolshinegroup-cosmiconfig-typescript-loader-npm-3.0.2-97436e68fc-7fe0198622.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+5.63 KB
.yarn/cache/cosmiconfig-typescript-loader-npm-4.0.0-cf43f43006-9151ffe62d.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+239 KB
.yarn/cache/graphql-language-service-npm-5.0.6-ef9bc63fd4-a7155ba934.zip
Binary file not shown.
Binary file added
BIN
+16.1 KB
.yarn/cache/graphql-language-service-types-npm-1.8.7-28bebe1bed-17d73316d5.zip
Binary file not shown.
Binary file added
BIN
+59.7 KB
.yarn/cache/graphql-language-service-utils-npm-2.7.1-deb8c81d4d-36f2d5db18.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-28.3 KB
.yarn/cache/source-map-support-npm-0.5.21-09ca99e250-43e98d700d.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+72.2 KB
.yarn/cache/vscode-languageserver-types-npm-3.17.2-b1136aa522-ef2d862d22.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "ts-gql-plugin", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"packageManager": "[email protected]", | ||
"license": "MIT", | ||
"main": "./dist/index.js", | ||
|
@@ -43,7 +43,9 @@ | |
"@graphql-codegen/typescript-operations": "2.3.7", | ||
"@graphql-tools/graphql-tag-pluck": "7.3.3", | ||
"deasync": "0.1.26", | ||
"graphql-config": "4.3.1" | ||
"graphql-config": "4.3.5", | ||
"graphql-language-service": "5.0.6", | ||
"graphql-language-service-utils": "2.7.1" | ||
}, | ||
"peerDependencies": { | ||
"graphql": ">= 16", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { DocumentNode } from 'graphql'; | ||
import path from 'node:path'; | ||
import { ErrorCatcher } from '../create-error-catcher'; | ||
import { ExtensionConfig } from '../extension-config'; | ||
import { generateTypeFromSchema } from '../generators/generate-type-from-schema'; | ||
import { getProjectExtension } from '../source-update/extension'; | ||
import { | ||
CacheItem, | ||
checkFileLastUpdate, | ||
createCacheSystem, | ||
} from '../utils/cache-system'; | ||
import { CachedGraphQLConfigLoader } from './cached-graphql-config-loader'; | ||
|
||
export type CreateCachedSchemaLoaderOptions = { | ||
cachedGraphQLConfigLoader: CachedGraphQLConfigLoader; | ||
errorCatcher: ErrorCatcher; | ||
}; | ||
|
||
export type SchemaProjectInfos<D> = { | ||
schemaFilePath?: string; | ||
schemaDocument: D; | ||
}; | ||
|
||
type ProjectInfos = SchemaProjectInfos<DocumentNode> & { | ||
staticGlobals: string[]; | ||
extension: ExtensionConfig; | ||
}; | ||
|
||
type CachedDocumentSchemaLoaderValue = ProjectInfos | null; | ||
|
||
export type CachedSchemaLoaderInput = { | ||
projectName: string; | ||
}; | ||
|
||
export type CachedDocumentSchemaLoader = ReturnType< | ||
typeof createCachedDocumentSchemaLoader | ||
>; | ||
|
||
export const defaultProjectName = 'default'; | ||
|
||
export const getProjectNameIfNotDefault = (projectName: string) => | ||
projectName === defaultProjectName ? undefined : projectName; | ||
|
||
export const getCreateProjectInfos = async ( | ||
cachedGraphQLConfigLoader: CachedGraphQLConfigLoader, | ||
{ projectName }: CachedSchemaLoaderInput | ||
) => { | ||
const { graphqlProjects } = await cachedGraphQLConfigLoader.getItemOrCreate( | ||
null | ||
); | ||
|
||
const project = graphqlProjects.find(({ name }) => name === projectName); | ||
if (!project) { | ||
throw new Error(`Project not defined for name "${projectName}"`); | ||
} | ||
|
||
const schemaFilePath = | ||
typeof project.schema === 'string' | ||
? path.join(project.dirpath, project.schema) | ||
: undefined; | ||
|
||
return { | ||
project, | ||
schemaFilePath, | ||
}; | ||
}; | ||
|
||
export const getCachedSchemaCheckValidity = | ||
(cachedGraphQLConfigLoader: CachedGraphQLConfigLoader) => | ||
async ( | ||
currentItem: CacheItem<SchemaProjectInfos<unknown> | null, unknown> | ||
) => { | ||
const isGraphQLConfigValid = | ||
await cachedGraphQLConfigLoader.checkItemValidity(null); | ||
if (!isGraphQLConfigValid) { | ||
return false; | ||
} | ||
|
||
const project = await currentItem.value; | ||
if (!project) { | ||
return true; | ||
} | ||
|
||
if (!project.schemaFilePath) { | ||
return false; | ||
} | ||
|
||
return checkFileLastUpdate(project.schemaFilePath, currentItem.dateTime); | ||
}; | ||
|
||
export const createCachedDocumentSchemaLoader = ({ | ||
cachedGraphQLConfigLoader, | ||
errorCatcher, | ||
}: CreateCachedSchemaLoaderOptions) => | ||
createCacheSystem<CachedDocumentSchemaLoaderValue, CachedSchemaLoaderInput>({ | ||
// TODO debounce | ||
// debounceValue: 1000, | ||
getKeyFromInput: (input) => input.projectName, | ||
create: async (input) => { | ||
const { project, schemaFilePath } = await getCreateProjectInfos( | ||
cachedGraphQLConfigLoader, | ||
input | ||
); | ||
|
||
const extension = getProjectExtension(project); | ||
|
||
return project | ||
.getSchema('DocumentNode') | ||
.then( | ||
async (schemaDocument): Promise<ProjectInfos> => ({ | ||
schemaFilePath, | ||
schemaDocument, | ||
staticGlobals: await generateTypeFromSchema( | ||
schemaDocument, | ||
getProjectNameIfNotDefault(input.projectName), | ||
extension.codegenConfig | ||
), | ||
extension, | ||
}) | ||
) | ||
.catch(errorCatcher); | ||
}, | ||
checkValidity: getCachedSchemaCheckValidity(cachedGraphQLConfigLoader), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { GraphQLSchema } from 'graphql'; | ||
import { createCacheSystem } from '../utils/cache-system'; | ||
import { | ||
CachedSchemaLoaderInput, | ||
CreateCachedSchemaLoaderOptions, | ||
getCachedSchemaCheckValidity, | ||
getCreateProjectInfos, | ||
SchemaProjectInfos, | ||
} from './cached-document-schema-loader'; | ||
|
||
type CachedSchemaLoaderValue = SchemaProjectInfos<GraphQLSchema> | null; | ||
|
||
export type CachedGraphQLSchemaLoader = ReturnType< | ||
typeof createCachedGraphQLSchemaLoader | ||
>; | ||
|
||
export const createCachedGraphQLSchemaLoader = ({ | ||
cachedGraphQLConfigLoader, | ||
errorCatcher, | ||
}: CreateCachedSchemaLoaderOptions) => | ||
createCacheSystem<CachedSchemaLoaderValue, CachedSchemaLoaderInput>({ | ||
getKeyFromInput: (input) => input.projectName, | ||
create: async (input) => { | ||
const { project, schemaFilePath } = await getCreateProjectInfos( | ||
cachedGraphQLConfigLoader, | ||
input | ||
); | ||
|
||
return project | ||
.getSchema('GraphQLSchema') | ||
.then(async (schemaDocument) => ({ | ||
schemaFilePath, | ||
schemaDocument, | ||
})) | ||
.catch(errorCatcher); | ||
}, | ||
checkValidity: getCachedSchemaCheckValidity(cachedGraphQLConfigLoader), | ||
sizeLimit: 40, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
efa6c5c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"with ts-gql-plugin" vs "without ts-gql-plugin" Benchmark
performance impact %: "with ts-gql-plugin" vs "without ts-gql-plugin"
27.57
% (±5.89%
)23.02
% (±1.23%
)0.83
This comment was automatically generated by workflow using github-action-benchmark.