Add passthrough schema config support with GQL Codegen #650
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem (#649)
GQLCodeGen supports several formats for the schema files used to do codegen. This include formats like remote URLs or TS/JS files that generate the schema.
The way Graphql-Let works today, its config is more or less directly passed through to the underlying GQLCodeGen CLI. This means that if you set your config to something like a remote file or TS file, the schema will actually be correctly generated.
The problem arises when you change that schema and re-run codegen. Before the config is passed through to the underlying CLI, graphql-let does some hashing / processing on it to determine if it should be run. The issue is that specific processing only handles literal files. If you browse the code, you can see there's a TODO and it filters out URLs. For TS/JS files...it can be very misleading because it will work, but it will actually hash the file itself (not the result of running the file which actually makes the schema)
This both:
Solution
If we look inside Codegen, we can see it uses several loaders and tools (all readily available) to parse the schemas. These loaders handle everything from traversing globbed patterns, to fetching remote files, and more.
By leveraging the same underlying parsers, we can effectively grab the actual schema (from just the schema config) and hash that content. This should give us a more accurate representation of the hash and when the schema has changed for more complex formats and should provide consistent behavior with the underlying GraphQLCodegen library
NOTE: I removed the Prisma loader because it is not Node 12 compatible.
NOTE: This is not mergable right now since the schema printing is too heavy; it won't work well with the loader functionality. There likely needs to be some memoization sitting in front of the loader, but we have no way to tell when a file changes and we need to rescan it.