Skip to content

fix(nested importing) #213

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

Merged
merged 1 commit into from
Sep 1, 2018
Merged

Conversation

SpaceK33z
Copy link
Collaborator

@SpaceK33z SpaceK33z commented Aug 10, 2018

Previously only the files that were processed were kept in memory in a Set, to prevent circular dependencies. However, it can happen that a file gets imported two or more times, with different imports. To fix this, instead of only keeping track of the processed files, it now also keeps track of which specific imports from the processed files are used.

The new test I added illustrates this use-case. This might seem like a far stretch, but if you use Prisma and have separated files, e.g. "user.graphql" and "restaurant.graphql", and use each file to import specific types from "generated/prisma.graphql", you'll walk into this.

It cost me three hours to finally end up with a solution that is less code than before, so I'm very happy with that if I may say so 😅.

An explanation with examples

This is the use-case I'm fixing:

schema.graphql

# import Query.*, Mutation.*, * from "./restaurant.graphql"
# import Query.*, Mutation.*, * from "./user.graphql"

restaurant.graphql

# import Query.restaurant, Mutation.createRestaurant from "./prisma.graphql"

user.graphql

# import Query.user, Mutation.createUser from "./prisma.graphql"

Actual result

Only Query.restaurant and Mutation.createRestaurant get imported, Query.user and Mutation.createUser are ignored.

Expected result

Query.restaurant, Mutation.createRestaurant, Query.user and Mutation.createUser are imported.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Previously only the files that were processed were kept in memory in a Set, to prevent circular dependencies. However, it can happen that a file gets imported two or more times, with different imports. To fix this, instead of only keeping track of the processed files, it now also keeps track of which specific imports from the processed files are used.

The new test I added illustrates this use-case. This might seem like a far stretch, but if you use Prisma and have separated files (e.g. "user.graphql" and "restaurant.graphql", and use each file to import specific types from "generated/prisma.graphql"), you'll walk into this.
@SpaceK33z
Copy link
Collaborator Author

Updated description to add a real-world use-case.

@SpaceK33z
Copy link
Collaborator Author

@divyenduz could you review this one? It is a bugfix so not a breaking change.

@divyenduz
Copy link
Contributor

@SpaceK33z : Sure! thanks for the PR. On my list.

@divyenduz divyenduz changed the title Fix nested importing fix(nested importing) Sep 1, 2018
@divyenduz divyenduz merged commit c336171 into ardatan:master Sep 1, 2018
@SpaceK33z SpaceK33z deleted the fix-nested-imports branch September 3, 2018 08:48
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.

None yet

2 participants