Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make sure that custom parser is used if passed to process #1438

Merged
merged 2 commits into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/graphql-language-service-server/src/GraphQLCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ const {

export async function getGraphQLCache(
configDir: Uri,
parser: typeof parseDocument,
extensions?: Array<(config: GraphQLConfig) => GraphQLConfig>,
config?: GraphQLConfig,
parser?: typeof parseDocument,
): Promise<GraphQLCacheInterface> {
let graphQLConfig =
config ?? ((await loadConfig({ rootDir: configDir })) as GraphQLConfig);
Expand All @@ -81,7 +81,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
constructor(
configDir: Uri,
graphQLConfig: GraphQLConfig,
parser?: typeof parseDocument,
parser: typeof parseDocument,
) {
this._configDir = configDir;
this._graphQLConfig = graphQLConfig;
Expand All @@ -90,7 +90,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
this._fragmentDefinitionsCache = new Map();
this._typeDefinitionsCache = new Map();
this._typeExtensionMap = new Map();
this._parser = parser || parseDocument;
this._parser = parser;
acao marked this conversation as resolved.
Show resolved Hide resolved
}

getGraphQLConfig = (): GraphQLConfig => this._graphQLConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class MessageProcessor {
this._extensions = extensions;
this._fileExtensions = fileExtensions;
this._graphQLConfig = config;
this._parser = parser || parseDocument;
this._parser = parser ?? parseDocument;
}

async handleInitializeRequest(
Expand Down Expand Up @@ -118,9 +118,9 @@ export class MessageProcessor {

this._graphQLCache = await getGraphQLCache(
rootPath,
this._parser,
this._extensions,
this._graphQLConfig,
this._parser,
);
this._languageService = new GraphQLLanguageService(this._graphQLCache);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ function wihtoutASTNode(definition: any) {
describe('GraphQLCache', () => {
const configDir = __dirname;
let graphQLRC;
let cache = new GraphQLCache(configDir, graphQLRC);
let cache = new GraphQLCache(configDir, graphQLRC, parseDocument);

beforeEach(async () => {
graphQLRC = await loadConfig({ rootDir: configDir });
cache = new GraphQLCache(configDir, graphQLRC);
cache = new GraphQLCache(configDir, graphQLRC, parseDocument);
});

afterEach(() => {
Expand All @@ -52,7 +52,11 @@ describe('GraphQLCache', () => {
};
};
const extensions = [extension];
const cacheWithExtensions = await getGraphQLCache(configDir, extensions);
const cacheWithExtensions = await getGraphQLCache(
configDir,
parseDocument,
extensions,
);
const config = cacheWithExtensions.getGraphQLConfig();
expect('extension' in config).toBe(true);
expect((config as any).extension).toBe('extension-used');
Expand Down