Skip to content
This repository has been archived by the owner on Sep 2, 2020. It is now read-only.

Switch to graphql-config #130

Merged
merged 5 commits into from
Jul 31, 2017
Merged

Switch to graphql-config #130

merged 5 commits into from
Jul 31, 2017

Conversation

RomanHotsiy
Copy link
Contributor

@RomanHotsiy RomanHotsiy commented Jul 20, 2017

hey @asiandrummer ,
here is the PR to switch from graphql-language-services-config to graphql-config.
I split it into 2 commits. First one removes graphql-language-services-config folder and the second one adds support for graphqlconfig

All the tests are passing and flow doesn't show any errors. Although it definitely requires looking from someone who knows the codebase

@schickling schickling requested a review from asiandrummer July 20, 2017 14:34
@asiandrummer
Copy link
Contributor

Checking this out. Thanks!

@asiandrummer
Copy link
Contributor

@RomanGotsiy This looks amazing! I think I'll be able to merge this, but just in case am doing a super granular read for safety. One high level feedback - would it be possible to PR out the removal of graphql-language-service-config separately?

@RomanHotsiy
Copy link
Contributor Author

RomanHotsiy commented Jul 21, 2017

@asiandrummer

I think I'll be able to merge this, but just in case am doing a super granular read for safety

Definitely! Would be great if you also can test it with Nuclide if possible as there may be some issues in graphql-config.

would it be possible to PR out the removal of graphql-language-service-config separately?

I think that no. Other packages depend on graphql-language-service-config so tests won't pass and flow will complain.

One more thing: there is probably a need to add some function for detecting and converting old config format to new just to support old configs. Do you think this is required? Do you want me to add this?

@asiandrummer
Copy link
Contributor

One more thing: there is probably a need to add some function for detecting and converting old config format to new just to support old configs. Do you think this is required? Do you want me to add this?

I just realized that you've changed includeDirs and excludeDirs to include and exclude. I probably missed this while checking out the PR from graphql-config repo - is it too late to revert back to includeDirs and excludeDirs? I think include and exclude might be too generic to specify what it wants to accomplish.

Since I'm late to suggest this change, if you've already made a lot of PRs to apply this to other repos, I'm fine with writing a function to enable backward-compatibility.

this._graphQLConfig.getSchemaPath(appName),
appName,
);
if (projectConfig.schemaPath) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this getter stuff ;)

Copy link
Contributor

@asiandrummer asiandrummer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for getAutocompleteSuggestions and the performance optimization, or we can discuss about the perf stuff.

@@ -103,10 +98,7 @@ export class GraphQLLanguageService {
const appName = this._graphQLConfig.getAppConfigNameByFilePath(filePath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed here I think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be:

const projectConfig = this._graphQLConfig.getConfigForFile(filePath);

and so on, similar to getDiagnostics

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Fixed.
Probably there is need to add some test-case that covers this piece of code

import {GraphQLLanguageService} from '../GraphQLLanguageService';

const MOCK_CONFIG = {
inputDirs: ['./queries'],
include: ['./queries/**'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love it

): Promise<Map<string, FragmentInfo>> => {
// This function may be called from other classes.
// If then, check the cache first.
const rootDir = graphQLConfig.getRootDir();
const rootDir = projectConfig.configDir;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you forgot to do a getter for configDir in https://github.com/graphcool/graphql-config/blob/master/src/GraphQLProjectConfig.ts, which makes me feel a little uncomfortable. If possible could we be consistent and use the proper getter? Not really a blocker though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, added getter for configDir.

excludeDirs.every(
exclude => !fileInfo.filePath.startsWith(path.join(rootDir, exclude)),
));
.filter(fileInfo => projectConfig.includesFile(fileInfo.filePath));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a bug fix I think - thanks for that


const schemaFileExt = path.extname(schemaPath);
let schema;
let schemaSDL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried of the performance of this approach to generate GraphQL schema. From what I understand, this approach will read the file, build GraphQLSchema object, print the schema in SDL format, and build it again. Last time I checked, buildSchema() takes around several seconds with 4~5k types available, and with extendSchema() being slow as well, this is definitely a hit with the performance.

I guess this is one of the ways to supprot .json format, which previously had bugs with my implementation to append the custom directives in SDL format to content string. One easy performance optimization we can make is to optionally perform custom directive extension when customDirective extension entry is available, with extendSchema, not buildSchema.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! I refactored code to use extendSchema when customDirective extension entry is available

Just one thing. It appeared that extendSchema loses directive description. I've already opened a PR (#961) on graphql-js to fix that but had to change "" to undefined in one test case for the time being (until my PR is merged)

@asiandrummer
Copy link
Contributor

Really amazing work @RomanGotsiy!

@RomanHotsiy
Copy link
Contributor Author

Thanks, @asiandrummer!
So far I have fixed all the issues you've spotted!

Let me know if there is anything else

@asiandrummer
Copy link
Contributor

lgtm, cc @wincent for visibility
@RomanGotsiy what are you thoughts on the comment I made above about include and exclude?

I just realized that you've changed includeDirs and excludeDirs to include and exclude. I probably missed this while checking out the PR from graphql-config repo - is it too late to revert back to includeDirs and excludeDirs? I think include and exclude might be too generic to specify what it wants to accomplish.

Since I'm late to suggest this change, if you've already made a lot of PRs to apply this to other repos, I'm fine with writing a function to enable backward-compatibility.

@RomanHotsiy
Copy link
Contributor Author

what are you thoughts on the comment I made above about include and exclude?

oops, missed that.

I think include and exclude might be too generic to specify what it wants to accomplish.

I partly agree. But at the same time globs are much more powerful. Let's say I want to exclude all the __test__ directories down to the directories tree. Using glob I can set:

"exclude": "**/__test__/**"

while using excludeDirs I will have to specify each folder + each time I create a new one I have to add it to the config.

On the other hand globs are harder to work with. + there is no simple and reliable way to convert glob to list of dirs. Does fb-watchman support globs?

@asiandrummer
Copy link
Contributor

@RomanGotsiy sorry - I meant only the name, not the functionality :D I love the glob support!
includeDirs -> include and excludeDirs -> exclude might have been too aggressive of a change, at least for graphql-language-service. Again I do love the glob support, but could we just change the names back to includeDirs and excludeDirs?

@RomanHotsiy
Copy link
Contributor Author

RomanHotsiy commented Jul 21, 2017

But if a user specifies glob "test/**/*.graphql" which is basically a file glob then includeDirs name doesn't work.
But I see now why include may be a too generic name. How about includePattern/excludePattern or includeGlob/excludeGlob ?

@asiandrummer
Copy link
Contributor

Or maybe we could name them includes/exclude - sounds more functional.

@RomanHotsiy
Copy link
Contributor Author

Yes! I love this idea 👍 I will update specification/implementation and this PR to use includes and excludes.

btw, You probably missed one s (includes/exclude <- here) in the previous comment :)

@RomanHotsiy
Copy link
Contributor Author

Hey @asiandrummer,

I've updated graphql-config and this PR to use includes/excludes

@schickling
Copy link
Contributor

Any update on this @asiandrummer? :)

@asiandrummer
Copy link
Contributor

Sorry I've been away - thanks for the contribution!

@asiandrummer asiandrummer merged commit 99c23d4 into graphql:master Jul 31, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants