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

feat(git-loader): add glob support #3012

Merged
merged 5 commits into from
Jun 8, 2021

Conversation

PixnBits
Copy link
Contributor

Description

While Providing Schema GraphQL file doesn't mention globs, Providing Documents GraphQL file does. It could also be useful for the git repository notation to likewise support globs. An example for graphql-inspector:

$ graphql-inspector diff "git:origin/main:./schema/*.graphql" "./schema/*.graphql"

This PR is the start of a possible implementation. It's my first TypeScript project so my intentions may not be expressed in the canonical way, I'm moving glob resolution out of the source collector to the individual loaders, and other bull-in-the-china-shop moves. 😅 I can start on tests, but figured it might be better to see if the approach needed redirection first.

Related #2786

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Possibly a breaking change to the interface of GraphQLFileLoader, uncertain so retaining the option for now but can delete that if seen as not a breaking change.

How Has This Been Tested?

I've been using these changes on a project, using just the file and git loaders. I $ yarn packd in the relevant package directories and installed the resulting tgz's in the other project and used the git glob syntax successfully.

Checklist:

  • I have followed the CONTRIBUTING doc and the style guidelines of this project [at least, I think so]
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation [TODO]
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works [TODO, see above]
  • New and existing unit tests and linter rules pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@changeset-bot
Copy link

changeset-bot bot commented May 27, 2021

⚠️ No Changeset found

Latest commit: 15263d4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

packages/load/src/load-typedefs/collect-sources.ts Outdated Show resolved Hide resolved
packages/load/src/load-typedefs/collect-sources.ts Outdated Show resolved Hide resolved
packages/load/src/load-typedefs/collect-sources.ts Outdated Show resolved Hide resolved
@@ -58,6 +67,11 @@ export class CodeFileLoader implements UniversalLoader<CodeFileLoaderOptions> {
pointer: SchemaPointerSingle | DocumentPointerSingle,
options: CodeFileLoaderOptions
): Promise<boolean> {
if (isGlob(pointer)) {
// FIXME: parse to find and check the file extensions?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how though. Maybe picomatch.parse? 🤔

Copy link
Contributor Author

@PixnBits PixnBits May 27, 2021

Choose a reason for hiding this comment

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

Oh, maybe this is a non-issue: the graphql-file and code-file loaders can both resolve globs for the other because they're both on the file system? So as long as there isn't a protocol prefix like git: in front (or is a file: protocol though that might be a separate feature PR) blindly returning true for all (local file system) globs is fine?

Copy link
Owner

@ardatan ardatan Jun 3, 2021

Choose a reason for hiding this comment

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

@PixnBits It is kind of tricky but let's try that and see if the tests would pass or fail

packages/loaders/git/src/index.ts Outdated Show resolved Hide resolved
packages/loaders/git/src/load-git.ts Outdated Show resolved Hide resolved
@@ -31,6 +36,10 @@ function isGraphQLImportFile(rawSDL: string) {
return trimmedRawSDL.startsWith('# import') || trimmedRawSDL.startsWith('#import');
}

function createGlobbyOptions(options: GraphQLFileLoaderOptions): GlobbyOptions {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

used by both code file and graphql file loaders, might be a candidate for moving to the utils package? or the filesystem glob calls rather than something specific to globby
not sure and not advocating for the move 😅

Copy link
Owner

Choose a reason for hiding this comment

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

Sure 👍

packages/load/src/load-typedefs/collect-sources.ts Outdated Show resolved Hide resolved
@ardatan
Copy link
Owner

ardatan commented Jun 8, 2021

@PixnBits Thank you very much! This PR looks awesome! Do you this is ready to merge? Is there anything we can help you?

@ardatan ardatan merged commit c664c82 into ardatan:master Jun 8, 2021
@PixnBits
Copy link
Contributor Author

PixnBits commented Jun 9, 2021

Very very sorry to respond late, I was curious if this was the right/an acceptable direction and was going to start on tests too, but got a bit busy 😓
Excited to see this in, I'll still work on those tests 😅 👍

@ardatan
Copy link
Owner

ardatan commented Jun 9, 2021

@PixnBits Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants